Class: Fastlane::Actions::EmergeComment

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

Class Method Summary collapse

Class Method Details

.authorsObject



42
43
44
# File 'lib/fastlane/plugin/emerge/actions/emerge_comment_action.rb', line 42

def self.authors
  ["Emerge Tools"]
end

.available_optionsObject



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/fastlane/plugin/emerge/actions/emerge_comment_action.rb', line 46

def self.available_options
  [
    FastlaneCore::ConfigItem.new(key: :api_token,
                                 env_name: "EMERGE_API_TOKEN",
                                 description: "An API token for Emerge",
                                 optional: false,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :gitlab_acces_token,
                                 env_name: "GITLAB_ACCESS_TOKEN",
                                 description: "An access token for Gitlab",
                                 optional: false,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :pr_number,
                                 description: "The PR number that triggered this upload",
                                 optional: false,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :build_id,
                                 description: "A string to identify this build",
                                 optional: false,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :base_build_id,
                                 description: "Id of the build to compare with this upload",
                                 optional: false,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :gitlab_url,
                                 description: "URL of the self hosted gitlab instance",
                                 optional: true,
                                 type: String),
    FastlaneCore::ConfigItem.new(key: :gitlab_project_id,
                                 description: "Id of the gitlab project this upload was triggered from",
                                 optional: false,
                                 type: Integer)
  ]
end

.descriptionObject



38
39
40
# File 'lib/fastlane/plugin/emerge/actions/emerge_comment_action.rb', line 38

def self.description
  "Post an Emerge PR comment, currently supports Gitlab only."
end

.is_supported?(platform) ⇒ Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/fastlane/plugin/emerge/actions/emerge_comment_action.rb', line 81

def self.is_supported?(platform)
  platform == :ios
end

.run(params) ⇒ Object



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
33
34
35
36
# File 'lib/fastlane/plugin/emerge/actions/emerge_comment_action.rb', line 8

def self.run(params)
  url = 'https://api.emergetools.com/getComment'
  api_token = params[:api_token]
  gitlab_url = params[:gitlab_url]
  project_id = params[:gitlab_project_id]
  pr_number = params[:pr_number]
  gitlab_access_token = params[:gitlab_access_token]

  request_params = {
    buildId: params[:build_id],
    baseBuildId: params[:base_build_id]
  }
  resp = Faraday.get(url, request_params, 'x-api-token' => api_token)
  case resp.status
  when 200
    UI.message("Received comment from Emerge")
    baseURL = gitlab_url ? gitlab_url : "https://gitlab.com"
    url = "#{baseURL}/api/v4/projects/#{project_id}/merge_requests/#{pr_number}/notes"
    gitlab_response = Faraday.post(url, { "body" => resp.body }, 'Authorization' => "Bearer #{gitlab_access_token}")
    case gitlab_response.status
    when 200...299
      UI.message("Successfully posted comment")
    else
      UI.error("Received error #{gitlab_response.status} from Gitlab")
    end
  else
    UI.error("Received error #{resp.status} from Emerge")
  end
end