fastlane-plugin-emerge 0.1.0 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 38e505be053a5c439e55a3c8ed9d69af31dd2da2f09607225153dd993170fa26
4
- data.tar.gz: 18c009df84980d664ef8dc02e6bd80511ff0b23e5671c5ea63be2f16c7cc6f20
3
+ metadata.gz: 9a1d1b9e1ea3e38708c95820afb2f51fadfffb6818e50486824cb746a7a17d5f
4
+ data.tar.gz: 2e1460681ef3295e3fa891d3f4cf81210a858f6eaffe2e33cbc5dde96e6a0dd4
5
5
  SHA512:
6
- metadata.gz: da48395fc4262b8a7055c4cf72ca54cac99c2b1f4b8061602949922f328db5daf26d75b80d949983a0387b88ad36c429380e4626b15f58e7dc4fbbdc8f1d79fe
7
- data.tar.gz: b35f798827f5927c55b9d61fbf132ee28e47fb354e35112399d400478b8d215aa3d2fdc47db378d22b7d9f138d17bb868de3dfdf1949f8880f623c99c9c22ea6
6
+ metadata.gz: 5afd725d1f5da3bae74dd12e8411eab77c8121d50052dd4a883bd9b850ce35380e08106c3c4fc437061ecb1b1ea13da81392d8a06728a9d5d1ee995ff653c69b
7
+ data.tar.gz: 25730e82e8b5756d5bd929dc8a2bb026dd27250bb8c5f7147e2daae5bcd5c0b49051b557bd2560e865600aae4de5396833b6c12b8bb2dd5632db408f56c472bb
@@ -1,28 +1,102 @@
1
1
  require 'fastlane/action'
2
+ require 'fastlane_core/print_table'
2
3
  require_relative '../helper/emerge_helper'
4
+ require 'pathname'
5
+ require 'tmpdir'
6
+ require 'fileutils'
3
7
 
4
8
  module Fastlane
5
9
  module Actions
6
10
  class EmergeAction < Action
7
11
  def self.run(params)
8
12
  api_token = params[:api_token]
9
- file_path = params[:file_path]
10
- if !File.exist?(file_path) || !File.extname(file_path) == '.zip'
13
+ file_path = params[:file_path] || lane_context[SharedValues::XCODEBUILD_ARCHIVE]
14
+
15
+ if file_path == nil
16
+ file_path = Dir.glob("#{lane_context[SharedValues::SCAN_DERIVED_DATA_PATH]}/Build/Products/Debug-iphonesimulator/*.app").first
17
+ end
18
+ pr_number = params[:pr_number]
19
+ build_id = params[:build_id]
20
+ base_build_id = params[:base_build_id]
21
+ repo_name = params[:repo_name]
22
+ gitlab_project_id = params[:gitlab_project_id]
23
+ build_type = params[:build_type]
24
+
25
+ if !File.exist?(file_path)
26
+ UI.error("Invalid input file")
27
+ return
28
+ end
29
+
30
+ # If the user provided a .app we will look for dsyms and package it into a zipped xcarchive
31
+ if File.extname(file_path) == '.app'
32
+ absolute_path = Pathname.new(File.expand_path(file_path))
33
+ UI.message("A .app was provided, dSYMs will be looked for in #{absolute_path.dirname}")
34
+ Dir.mktmpdir do |d|
35
+ application_folder = "#{d}/archive.xcarchive/Products/Applications/"
36
+ dsym_folder = "#{d}/archive.xcarchive/dSYMs/"
37
+ FileUtils.mkdir_p application_folder
38
+ FileUtils.mkdir_p dsym_folder
39
+ FileUtils.cp_r(file_path, application_folder)
40
+ Dir.glob("#{absolute_path.dirname}/*/*.dsym") do |filename|
41
+ UI.message("Found dSYM: #{Pathname.new(filename).basename}")
42
+ FileUtils.cp_r(filename, dsym_folder)
43
+ end
44
+ Xcodeproj::Plist.write_to_path({"NAME" => "Emerge Upload"}, "#{d}/archive.xcarchive/Info.plist")
45
+ file_path = "#{absolute_path.dirname}/archive.xcarchive.zip"
46
+ ZipAction.run(
47
+ path: "#{d}/archive.xcarchive",
48
+ output_path: file_path)
49
+ UI.message("Archive generated at #{file_path}")
50
+ end
51
+ elsif File.extname(file_path) == '.xcarchive'
52
+ zip_path = file_path + ".zip"
53
+ Actions::ZipAction.run(
54
+ path: file_path,
55
+ output_path: zip_path)
56
+ file_path = zip_path
57
+ elsif !File.extname(file_path) == '.zip'
11
58
  UI.error("Invalid input file")
12
59
  return
13
60
  end
14
61
 
15
62
  fileName = File.basename(file_path)
16
- url = 'https://2b32vitohk.execute-api.us-west-1.amazonaws.com/getUpload'
17
- resp = Faraday.get(url, {fileName: fileName}, {'X-API-Token' => api_token})
63
+ url = 'https://api.emergetools.com/getUpload'
64
+ params = {
65
+ fileName: fileName,
66
+ }
67
+ if pr_number
68
+ params[:prNumber] = pr_number
69
+ end
70
+ if build_id
71
+ params[:buildId] = build_id
72
+ end
73
+ if base_build_id
74
+ params[:baseBuildId] = base_build_id
75
+ end
76
+ if repo_name
77
+ params[:repoName] = repo_name
78
+ end
79
+ if gitlab_project_id
80
+ params[:gitlabProjectId] = gitlab_project_id
81
+ end
82
+ params[:buildType] = build_type || "development"
83
+ FastlaneCore::PrintTable.print_values(
84
+ config: params,
85
+ hide_keys: [],
86
+ title: "Summary for Emerge #{Fastlane::Emerge::VERSION}")
87
+ resp = Faraday.get(url, params, {'X-API-Token' => api_token})
18
88
  case resp.status
19
89
  when 200
20
90
  json = JSON.parse(resp.body)
21
91
  upload_id = json["upload_id"]
22
92
  upload_url = json["uploadURL"]
23
93
  Helper::EmergeHelper.perform_upload(upload_url, upload_id, file_path)
24
- when 400...500
94
+ when 403
25
95
  UI.error("Invalid API token")
96
+ when 400
97
+ UI.error("Invalid parameters")
98
+ json = JSON.parse(resp.body)
99
+ UI.error("Error: #{json["errorMessage"]}")
26
100
  else
27
101
  UI.error("Upload failed")
28
102
  end
@@ -55,7 +129,31 @@ module Fastlane
55
129
  FastlaneCore::ConfigItem.new(key: :file_path,
56
130
  env_name: "EMERGE_FILE_PATH",
57
131
  description: "Path to the zipped xcarchive or app to upload",
58
- optional: false,
132
+ optional: true,
133
+ type: String),
134
+ FastlaneCore::ConfigItem.new(key: :pr_number,
135
+ description: "The PR number that triggered this upload",
136
+ optional: true,
137
+ type: String),
138
+ FastlaneCore::ConfigItem.new(key: :build_id,
139
+ description: "A string to identify this build",
140
+ optional: true,
141
+ type: String),
142
+ FastlaneCore::ConfigItem.new(key: :base_build_id,
143
+ description: "Id of the build to compare with this upload",
144
+ optional: true,
145
+ type: String),
146
+ FastlaneCore::ConfigItem.new(key: :repo_name,
147
+ description: "Full name of the respository this upload was triggered from. For example: EmergeTools/Emerge",
148
+ optional: true,
149
+ type: String),
150
+ FastlaneCore::ConfigItem.new(key: :gitlab_project_id,
151
+ description: "Id of the gitlab project this upload was triggered from",
152
+ optional: true,
153
+ type: Integer),
154
+ FastlaneCore::ConfigItem.new(key: :build_type,
155
+ description: "Type of build, either release or development. Defaults to development",
156
+ optional: true,
59
157
  type: String)
60
158
  ]
61
159
  end
@@ -0,0 +1,86 @@
1
+ require 'fastlane/action'
2
+ require 'fastlane_core/print_table'
3
+ require_relative '../helper/emerge_helper'
4
+
5
+ module Fastlane
6
+ module Actions
7
+ class EmergeComment < Action
8
+ def self.run(params)
9
+ url = 'https://api.emergetools.com/getComment'
10
+ api_token = params[:api_token]
11
+ gitlab_url = params[:gitlab_url]
12
+ project_id = params[:gitlab_project_id]
13
+ pr_number = params[:pr_number]
14
+ gitlab_access_token = params[:gitlab_access_token]
15
+
16
+ requestParams = {
17
+ buildId: params[:build_id],
18
+ baseBuildId: params[:base_build_id]
19
+ }
20
+ resp = Faraday.get(url, requestParams, {'x-api-token' => api_token})
21
+ case resp.status
22
+ when 200
23
+ UI.message("Received comment from Emerge")
24
+ baseURL = gitlab_url ? gitlab_url : "https://gitlab.com"
25
+ url = "#{baseURL}/api/v4/projects/#{project_id}/merge_requests/#{pr_number}/notes"
26
+ gitlabResponse = Faraday.post(url, {"body" => resp.body}, {'Authorization' => "Bearer #{gitlab_access_token}"})
27
+ case gitlabResponse.status
28
+ when 200...299
29
+ UI.message("Successfully posted comment")
30
+ else
31
+ UI.error("Received error #{gitlabResponse.status} from Gitlab")
32
+ end
33
+ else
34
+ UI.error("Received error #{resp.status} from Emerge")
35
+ end
36
+ end
37
+
38
+ def self.description
39
+ "Post an Emerge PR comment, currently supports Gitlab only."
40
+ end
41
+
42
+ def self.authors
43
+ ["Emerge Tools"]
44
+ end
45
+
46
+ def self.available_options
47
+ [
48
+ FastlaneCore::ConfigItem.new(key: :api_token,
49
+ env_name: "EMERGE_API_TOKEN",
50
+ description: "An API token for Emerge",
51
+ optional: false,
52
+ type: String),
53
+ FastlaneCore::ConfigItem.new(key: :gitlab_acces_token,
54
+ env_name: "GITLAB_ACCESS_TOKEN",
55
+ description: "An access token for Gitlab",
56
+ optional: false,
57
+ type: String),
58
+ FastlaneCore::ConfigItem.new(key: :pr_number,
59
+ description: "The PR number that triggered this upload",
60
+ optional: false,
61
+ type: String),
62
+ FastlaneCore::ConfigItem.new(key: :build_id,
63
+ description: "A string to identify this build",
64
+ optional: false,
65
+ type: String),
66
+ FastlaneCore::ConfigItem.new(key: :base_build_id,
67
+ description: "Id of the build to compare with this upload",
68
+ optional: false,
69
+ type: String),
70
+ FastlaneCore::ConfigItem.new(key: :gitlab_url,
71
+ description: "URL of the self hosted gitlab instance",
72
+ optional: true,
73
+ type: String),
74
+ FastlaneCore::ConfigItem.new(key: :gitlab_project_id,
75
+ description: "Id of the gitlab project this upload was triggered from",
76
+ optional: false,
77
+ type: Integer)
78
+ ]
79
+ end
80
+
81
+ def self.is_supported?(platform)
82
+ platform == :ios
83
+ end
84
+ end
85
+ end
86
+ end
@@ -1,5 +1,5 @@
1
1
  module Fastlane
2
2
  module Emerge
3
- VERSION = "0.1.0"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlane-plugin-emerge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emerge Tools, Inc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-12-09 00:00:00.000000000 Z
11
+ date: 2021-04-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -160,6 +160,7 @@ files:
160
160
  - README.md
161
161
  - lib/fastlane/plugin/emerge.rb
162
162
  - lib/fastlane/plugin/emerge/actions/emerge_action.rb
163
+ - lib/fastlane/plugin/emerge/actions/emerge_comment_action.rb
163
164
  - lib/fastlane/plugin/emerge/helper/emerge_helper.rb
164
165
  - lib/fastlane/plugin/emerge/version.rb
165
166
  homepage: https://github.com/EmergeTools/fastlane-plugin-emerge