Class: Fastlane::Actions::FlockAction

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

Constant Summary collapse

BASE_URL =
'https://api.flock.co/hooks/sendMessage'.freeze

Class Method Summary collapse

Methods inherited from Fastlane::Action

action_name, authors, details, method_missing, other_action, output, return_value, sh, step_text

Class Method Details

.authorObject



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

def self.author
  "Manav"
end

.available_optionsObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/fastlane/actions/flock.rb', line 35

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :message,
                                 env_name: 'FL_FLOCK_MESSAGE',
                                 description: 'Message text'),
    FastlaneCore::ConfigItem.new(key: :token,
                                 env_name: 'FL_FLOCK_TOKEN',
                                 description: 'Token for the Flock incoming webhook'),
    FastlaneCore::ConfigItem.new(key: :base_url,
                                 env_name: 'FL_FLOCK_BASE_URL',
                                 description: 'Base URL of the Flock incoming message webhook',
                                 optional: true,
                                 default_value: BASE_URL,
                                 verify_block: proc do |value|
                                   UI.user_error! 'Invalid https URL' unless value.start_with? 'https://'
                                 end)
  ]
end

.descriptionObject



31
32
33
# File 'lib/fastlane/actions/flock.rb', line 31

def self.description
  "Send a message to a Flock group"
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/fastlane/actions/flock.rb', line 58

def self.is_supported?(platform)
  true
end

.notify_incoming_message_webhook(base_url, message, token) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/fastlane/actions/flock.rb', line 14

def self.notify_incoming_message_webhook(base_url, message, token)
  uri = URI.join(base_url + '/', token)
  response = Net::HTTP.start(
    uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
    request = Net::HTTP::Post.new uri.path
    request.content_type = 'application/json'
    request.body = JSON.generate("text" => message)
    http.request request
  end
  if response.kind_of? Net::HTTPSuccess
    UI.success 'Message sent to Flock.'
  else
    UI.error "HTTP request to '#{uri}' with message '#{message}' failed with a #{response.code} response."
    UI.user_error! 'Error sending message to Flock. Please verify the Flock webhook token.'
  end
end

.run(options) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/fastlane/actions/flock.rb', line 6

def self.run(options)
  require 'net/http'
  require 'uri'
  require 'json'

  notify_incoming_message_webhook(options[:base_url], options[:message], options[:token])
end