Class: Fastlane::Actions::SendBuildToBugsnagAction

Inherits:
Action
  • Object
show all
Defined in:
lib/fastlane/plugin/bugsnag/actions/send_build_to_bugsnag.rb

Constant Summary collapse

BUILD_TOOL =
"bugsnag-fastlane-plugin"

Class Method Summary collapse

Class Method Details

.authorsObject



93
94
95
# File 'lib/fastlane/plugin/bugsnag/actions/send_build_to_bugsnag.rb', line 93

def self.authors
  ["cawllec"]
end

.available_optionsObject



117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# File 'lib/fastlane/plugin/bugsnag/actions/send_build_to_bugsnag.rb', line 117

def self.available_options
  options = load_default_values
  [
    FastlaneCore::ConfigItem.new(key: :config_file,
                                 description: "AndroidManifest.xml/Info.plist location",
                                 optional: true,
                                 default_value: options[:config_file]),
    FastlaneCore::ConfigItem.new(key: :api_key,
                                 description: "Bugsnag API Key",
                                 optional: true,
                                 default_value: options[:apiKey]),
    FastlaneCore::ConfigItem.new(key: :app_version,
                                 description: "App version being built",
                                 optional: true,
                                 default_value: options[:appVersion]),
    FastlaneCore::ConfigItem.new(key: :android_version_code,
                                 description: "Android app version code",
                                 optional: true,
                                 default_value: options[:appVersionCode]),
    FastlaneCore::ConfigItem.new(key: :ios_bundle_version,
                                 description: "iOS/macOS/tvOS bundle version",
                                 optional: true,
                                 default_value: options[:appBundleVersion]),
    FastlaneCore::ConfigItem.new(key: :release_stage,
                                 description: "Release stage being built, i.e. staging, production",
                                 optional: true,
                                 default_value: options[:releaseStage] || "production"),
    FastlaneCore::ConfigItem.new(key: :builder,
                                 description: "The name of the entity triggering the build",
                                 optional: true,
                                 default_value: `whoami`.chomp),
    FastlaneCore::ConfigItem.new(key: :repository,
                                 description: "The source control repository URL for this application",
                                 optional: true,
                                 default_value: options[:repository]),
    FastlaneCore::ConfigItem.new(key: :revision,
                                 description: "The source control revision id",
                                 optional: true,
                                 default_value: options[:revision]),
    FastlaneCore::ConfigItem.new(key: :provider,
                                 description: "The source control provider, one of 'github-enterprise', 'gitlab-onpremise', or 'bitbucket-server', if any",
                                 optional: true,
                                 default_value: nil,
                                 verify_block: proc do |value|
                                   valid = ['github-enterprise', 'gitlab-onpremise', 'bitbucket-server'].include? value
                                   unless valid
                                     UI.user_error!("Provider must be one of 'github-enterprise', 'gitlab-onpremise', 'bitbucket-server', or unspecified")
                                   end
                                 end),
    FastlaneCore::ConfigItem.new(key: :endpoint,
                                 description: "Bugsnag deployment endpoint",
                                 optional: true,
                                 default_value: "https://build.bugsnag.com")
  ]
end

.categoryObject



101
102
103
# File 'lib/fastlane/plugin/bugsnag/actions/send_build_to_bugsnag.rb', line 101

def self.category
  :building
end

.descriptionObject



89
90
91
# File 'lib/fastlane/plugin/bugsnag/actions/send_build_to_bugsnag.rb', line 89

def self.description
  "Notifies Bugsnag of a build"
end

.detailsObject



109
110
111
# File 'lib/fastlane/plugin/bugsnag/actions/send_build_to_bugsnag.rb', line 109

def self.details
  "Notifies Bugsnag of a new build being released including app version and source control details"
end

.example_codeObject



97
98
99
# File 'lib/fastlane/plugin/bugsnag/actions/send_build_to_bugsnag.rb', line 97

def self.example_code
  ['send_build_to_bugsnag']
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


113
114
115
# File 'lib/fastlane/plugin/bugsnag/actions/send_build_to_bugsnag.rb', line 113

def self.is_supported?(platform)
  [:ios, :mac, :android].include?(platform)
end

.missing_api_key_message(params) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/fastlane/plugin/bugsnag/actions/send_build_to_bugsnag.rb', line 53

def self.missing_api_key_message(params)
  message = "A Bugsnag API key is required to release a build. "
  if lane_context[:PLATFORM_NAME] == :android
    if params[:config_file]
      message << "Set com.bugsnag.android.API_KEY in your AndroidManifest.xml to detect API key automatically."
    else
      message << "Set the config_file option with the path to your AndroidManifest.xml and set com.bugsnag.android.API_KEY in it to detect API key automatically."
    end
  else
    if params[:config_file]
      message << "Set BugsnagAPIKey in your Info.plist file to detect API key automatically."
    else
      message << "Set the config_file option with the path to your Info.plist and set BugsnagAPIKey in it to detect API key automatically."
    end
  end
  message
end

.missing_app_version_message(params) ⇒ Object



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/fastlane/plugin/bugsnag/actions/send_build_to_bugsnag.rb', line 71

def self.missing_app_version_message(params)
  message = "An app version must be specified release a build."
  if lane_context[:PLATFORM_NAME] == :android
    if params[:config_file]
      message << "Set com.bugsnag.android.APP_VERSION in your AndroidManifest.xml to detect this value automatically."
    else
      message << "Set the config_file option with the path to your AndroidManifest.xml and set com.bugsnag.android.APP_VERSION in it to detect this value automatically."
    end
  else
    if params[:config_file]
      message << "Set the app_version option with your app version or set config_file to update the path to your Info.plist"
    else
      message << "Set the config_file option with the path to your Info.plist"
    end
  end
  message
end

.return_valueObject



105
106
107
# File 'lib/fastlane/plugin/bugsnag/actions/send_build_to_bugsnag.rb', line 105

def self.return_value
  nil
end

.run(params) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/fastlane/plugin/bugsnag/actions/send_build_to_bugsnag.rb', line 10

def self.run(params)
  payload = {buildTool: BUILD_TOOL, sourceControl: {}}
  if lane_context[:PLATFORM_NAME] == :android
    payload.merge!(options_from_android_manifest(params[:config_file])) if params[:config_file]
  else
    payload.merge!(options_from_info_plist(params[:config_file])) if params[:config_file]
  end

  default_plist = default_info_plist_path
  default_manifest = default_android_manifest_path
  if (lane_context[:PLATFORM_NAME] == :android and params[:config_file] == default_manifest) or
     (lane_context[:PLATFORM_NAME] != :android and params[:config_file] == default_plist)
    # Load custom API key and version properties only if config file has not been overridden
    payload[:apiKey] = params[:api_key] unless params[:api_key].nil?
    payload[:appVersion] = params[:app_version] unless params[:app_version].nil?
    payload[:appVersionCode] = params[:android_version_code] unless params[:android_version_code].nil?
    payload[:appBundleVersion] = params[:ios_bundle_version] unless params[:ios_bundle_version].nil?
  else
    # Print which file is populating version and API key information since the value has been
    # overridden
    UI.message("Loading API key and app version info from #{params[:config_file]}")
  end
  payload.delete(:config_file)

  # Overwrite automated options with configured if set
  payload[:releaseStage] = params[:release_stage] unless params[:release_stage].nil?
  payload[:builderName] = params[:builder]

  payload[:sourceControl][:revision] = params[:revision] if params[:revision]
  payload[:sourceControl][:repository] = params[:repository] if params[:repository]
  payload[:sourceControl][:provider] = params[:provider] if params[:provider]

  payload.reject! {|k,v| v == nil || (v.is_a?(Hash) && v.empty?)}

  if payload[:apiKey].nil? || !payload[:apiKey].is_a?(String)
    UI.user_error! missing_api_key_message(params)
  end
  if payload[:appVersion].nil?
    UI.user_error! missing_app_version_message(params)
  end
  send_notification(params[:endpoint], ::JSON.dump(payload))
end