Class: Fastlane::Actions::TypetalkAction

Inherits:
Fastlane::Action show all
Defined in:
fastlane/lib/fastlane/actions/typetalk.rb

Constant Summary

Constants inherited from Fastlane::Action

Fastlane::Action::AVAILABLE_CATEGORIES, Fastlane::Action::RETURN_TYPES

Class Method Summary collapse

Methods inherited from Fastlane::Action

action_name, authors, deprecated_notes, details, lane_context, method_missing, other_action, output, return_type, return_value, sample_return_value, shell_out_should_use_bundle_exec?, step_text

Class Method Details

.authorObject



68
69
70
# File 'fastlane/lib/fastlane/actions/typetalk.rb', line 68

def self.author
  "Nulab Inc."
end

.available_optionsObject



58
59
60
61
62
63
64
65
66
# File 'fastlane/lib/fastlane/actions/typetalk.rb', line 58

def self.available_options
  [
    ['message', 'The message to post'],
    ['note_path', 'Path to an additional note'],
    ['topic_id', 'Typetalk topic id'],
    ['success', 'Successful build?'],
    ['typetalk_token', 'typetalk token']
  ]
end

.categoryObject



88
89
90
# File 'fastlane/lib/fastlane/actions/typetalk.rb', line 88

def self.category
  :notifications
end

.check_response(response) ⇒ Object



45
46
47
48
49
50
51
52
# File 'fastlane/lib/fastlane/actions/typetalk.rb', line 45

def self.check_response(response)
  case response.code.to_i
  when 200, 204
    true
  else
    UI.user_error!("Could not sent Typetalk notification")
  end
end

.descriptionObject



54
55
56
# File 'fastlane/lib/fastlane/actions/typetalk.rb', line 54

def self.description
  "Post a message to [Typetalk](https://www.typetalk.com/)"
end

.example_codeObject



76
77
78
79
80
81
82
83
84
85
86
# File 'fastlane/lib/fastlane/actions/typetalk.rb', line 76

def self.example_code
  [
    'typetalk(
      message: "App successfully released!",
      note_path: "ChangeLog.md",
      topicId: 1,
      success: true,
      typetalk_token: "Your Typetalk Token"
    )'
  ]
end

.is_supported?(platform) ⇒ Boolean

Returns:



72
73
74
# File 'fastlane/lib/fastlane/actions/typetalk.rb', line 72

def self.is_supported?(platform)
  true
end

.post_to_typetalk(message, topic_id, typetalk_token) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'fastlane/lib/fastlane/actions/typetalk.rb', line 34

def self.post_to_typetalk(message, topic_id, typetalk_token)
  require 'net/http'
  require 'uri'

  uri = URI.parse("https://typetalk.in/api/v1/topics/#{topic_id}")
  response = Net::HTTP.post_form(uri, { 'message' => message,
                                       'typetalkToken' => typetalk_token })

  self.check_response(response)
end

.run(params) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'fastlane/lib/fastlane/actions/typetalk.rb', line 4

def self.run(params)
  options = {
      message: nil,
      note_path: nil,
      success: true,
      topic_id: nil,
      typetalk_token: nil
  }.merge(params || {})

  [:message, :topic_id, :typetalk_token].each do |key|
    UI.user_error!("No #{key} given.") unless options[key]
  end

  emoticon = (options[:success] ? ':smile:' : ':rage:')
  message = "#{emoticon} #{options[:message]}"

  note_path = File.expand_path(options[:note_path]) if options[:note_path]
  if note_path && File.exist?(note_path)
    contents = File.read(note_path)
    message += "\n\n```\n#{contents}\n```"
  end

  topic_id = options[:topic_id]
  typetalk_token = options[:typetalk_token]

  self.post_to_typetalk(message, topic_id, typetalk_token)

  UI.success('Successfully sent Typetalk notification')
end