fastlane-plugin-appcenter 1.5.0 → 1.8.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,13 +6,11 @@ module Fastlane
6
6
  # accounting for file types that can and should be zip-compressed
7
7
  # before they are uploaded
8
8
  def self.file_extname_full(path)
9
- is_zip = File.extname(path) == ".zip"
10
-
11
- # if file is not .zip'ed, these do not change basename and extname
12
- unzip_basename = File.basename(path, ".zip")
13
- unzip_extname = File.extname(unzip_basename)
9
+ %w(.app.zip .dSYM.zip).each do |suffix|
10
+ return suffix if path.to_s.downcase.end_with? suffix.downcase
11
+ end
14
12
 
15
- is_zip ? unzip_extname + ".zip" : unzip_extname
13
+ File.extname path
16
14
  end
17
15
 
18
16
  # create request
@@ -20,10 +18,17 @@ module Fastlane
20
18
  require 'faraday'
21
19
  require 'faraday_middleware'
22
20
 
21
+ default_api_url = "https://api.appcenter.ms"
22
+ if ENV['APPCENTER_ENV']&.upcase == 'INT'
23
+ default_api_url = "https://api-gateway-core-integration.dev.avalanch.es"
24
+ end
25
+
23
26
  options = {
24
- url: upload_url || ENV.fetch('APPCENTER_UPLOAD_URL', "https://api.appcenter.ms")
27
+ url: upload_url || default_api_url
25
28
  }
26
29
 
30
+ UI.message("DEBUG: BASE URL #{options[:url]}") if ENV['DEBUG']
31
+
27
32
  Faraday.new(options) do |builder|
28
33
  if upload_url
29
34
  builder.request :multipart unless dsym
@@ -44,15 +49,22 @@ module Fastlane
44
49
  def self.create_release_upload(api_token, owner_name, app_name, body)
45
50
  connection = self.connection
46
51
 
47
- response = connection.post("v0.1/apps/#{owner_name}/#{app_name}/release_uploads") do |req|
52
+ url = "v0.1/apps/#{owner_name}/#{app_name}/release_uploads"
53
+ body ||= {}
54
+
55
+ UI.message("DEBUG: POST #{url}") if ENV['DEBUG']
56
+ UI.message("DEBUG: POST body: #{JSON.pretty_generate(body)}\n") if ENV['DEBUG']
57
+
58
+ response = connection.post(url) do |req|
48
59
  req.headers['X-API-Token'] = api_token
49
60
  req.headers['internal-request-source'] = "fastlane"
50
- req.body = body.nil? && {} || body
61
+ req.body = body
51
62
  end
52
63
 
64
+ UI.message("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
65
+
53
66
  case response.status
54
67
  when 200...300
55
- UI.message("DEBUG: #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
56
68
  response.body
57
69
  when 401
58
70
  UI.user_error!("Auth Error, provided invalid token")
@@ -61,7 +73,7 @@ module Fastlane
61
73
  UI.error("Not found, invalid owner or application name")
62
74
  false
63
75
  when 500...600
64
- UI.crash!("Internal Service Error, please try again later")
76
+ UI.abort_with_message!("Internal Service Error, please try again later")
65
77
  else
66
78
  UI.error("Error #{response.status}: #{response.body}")
67
79
  false
@@ -76,20 +88,27 @@ module Fastlane
76
88
  def self.create_mapping_upload(api_token, owner_name, app_name, file_name, build_number, version)
77
89
  connection = self.connection
78
90
 
79
- response = connection.post("v0.1/apps/#{owner_name}/#{app_name}/symbol_uploads") do |req|
91
+ url = "v0.1/apps/#{owner_name}/#{app_name}/symbol_uploads"
92
+ body = {
93
+ symbol_type: "AndroidProguard",
94
+ file_name: file_name,
95
+ build: build_number,
96
+ version: version,
97
+ }
98
+
99
+ UI.message("DEBUG: POST #{url}") if ENV['DEBUG']
100
+ UI.message("DEBUG: POST body #{JSON.pretty_generate(body)}\n") if ENV['DEBUG']
101
+
102
+ response = connection.post(url) do |req|
80
103
  req.headers['X-API-Token'] = api_token
81
104
  req.headers['internal-request-source'] = "fastlane"
82
- req.body = {
83
- symbol_type: "AndroidProguard",
84
- file_name: file_name,
85
- build: build_number,
86
- version: version,
87
- }
105
+ req.body = body
88
106
  end
89
107
 
108
+ UI.message("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
109
+
90
110
  case response.status
91
111
  when 200...300
92
- UI.message("DEBUG: #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
93
112
  response.body
94
113
  when 401
95
114
  UI.user_error!("Auth Error, provided invalid token")
@@ -111,17 +130,24 @@ module Fastlane
111
130
  def self.create_dsym_upload(api_token, owner_name, app_name)
112
131
  connection = self.connection
113
132
 
114
- response = connection.post("v0.1/apps/#{owner_name}/#{app_name}/symbol_uploads") do |req|
133
+ url = "v0.1/apps/#{owner_name}/#{app_name}/symbol_uploads"
134
+ body = {
135
+ symbol_type: 'Apple'
136
+ }
137
+
138
+ UI.message("DEBUG: POST #{url}") if ENV['DEBUG']
139
+ UI.message("DEBUG: POST body #{JSON.pretty_generate(body)}\n") if ENV['DEBUG']
140
+
141
+ response = connection.post(url) do |req|
115
142
  req.headers['X-API-Token'] = api_token
116
143
  req.headers['internal-request-source'] = "fastlane"
117
- req.body = {
118
- symbol_type: 'Apple'
119
- }
144
+ req.body = body
120
145
  end
121
146
 
147
+ UI.message("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
148
+
122
149
  case response.status
123
150
  when 200...300
124
- UI.message("DEBUG: #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
125
151
  response.body
126
152
  when 401
127
153
  UI.user_error!("Auth Error, provided invalid token")
@@ -139,17 +165,24 @@ module Fastlane
139
165
  def self.update_symbol_upload(api_token, owner_name, app_name, symbol_upload_id, status)
140
166
  connection = self.connection
141
167
 
142
- response = connection.patch("v0.1/apps/#{owner_name}/#{app_name}/symbol_uploads/#{symbol_upload_id}") do |req|
168
+ url = "v0.1/apps/#{owner_name}/#{app_name}/symbol_uploads/#{symbol_upload_id}"
169
+ body = {
170
+ status: status
171
+ }
172
+
173
+ UI.message("DEBUG: PATCH #{url}") if ENV['DEBUG']
174
+ UI.message("DEBUG: PATCH body #{JSON.pretty_generate(body)}\n") if ENV['DEBUG']
175
+
176
+ response = connection.patch(url) do |req|
143
177
  req.headers['X-API-Token'] = api_token
144
178
  req.headers['internal-request-source'] = "fastlane"
145
- req.body = {
146
- "status" => status
147
- }
179
+ req.body = body
148
180
  end
149
181
 
182
+ UI.message("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
183
+
150
184
  case response.status
151
185
  when 200...300
152
- UI.message("DEBUG: #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
153
186
  response.body
154
187
  when 401
155
188
  UI.user_error!("Auth Error, provided invalid token")
@@ -166,6 +199,9 @@ module Fastlane
166
199
  def self.upload_symbol(api_token, owner_name, app_name, symbol, symbol_type, symbol_upload_id, upload_url)
167
200
  connection = self.connection(upload_url, true)
168
201
 
202
+ UI.message("DEBUG: PUT #{upload_url}") if ENV['DEBUG']
203
+ UI.message("DEBUG: PUT body <data>\n") if ENV['DEBUG']
204
+
169
205
  response = connection.put do |req|
170
206
  req.headers['x-ms-blob-type'] = "BlockBlob"
171
207
  req.headers['Content-Length'] = File.size(symbol).to_s
@@ -173,20 +209,22 @@ module Fastlane
173
209
  req.body = Faraday::UploadIO.new(symbol, 'application/octet-stream') if symbol && File.exist?(symbol)
174
210
  end
175
211
 
176
- logType = "dSYM" if (symbol_type == "Apple")
177
- logType = "mapping" if (symbol_type == "Android")
212
+ UI.message("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
213
+
214
+ log_type = "dSYM" if symbol_type == "Apple"
215
+ log_type = "mapping" if symbol_type == "Android"
178
216
 
179
217
  case response.status
180
218
  when 200...300
181
219
  self.update_symbol_upload(api_token, owner_name, app_name, symbol_upload_id, 'committed')
182
- UI.success("#{logType} uploaded")
220
+ UI.success("#{log_type} uploaded")
183
221
  when 401
184
222
  UI.user_error!("Auth Error, provided invalid token")
185
223
  false
186
224
  else
187
- UI.error("Error uploading #{logType} #{response.status}: #{response.body}")
225
+ UI.error("Error uploading #{log_type} #{response.status}: #{response.body}")
188
226
  self.update_symbol_upload(api_token, owner_name, app_name, symbol_upload_id, 'aborted')
189
- UI.error("#{logType} upload aborted")
227
+ UI.error("#{log_type} upload aborted")
190
228
  false
191
229
  end
192
230
  end
@@ -202,12 +240,17 @@ module Fastlane
202
240
  # ipa field is used for .apk, .aab and .ipa files
203
241
  options[:ipa] = Faraday::UploadIO.new(file, 'application/octet-stream') if file && File.exist?(file)
204
242
 
243
+ UI.message("DEBUG: POST #{upload_url}") if ENV['DEBUG']
244
+ UI.message("DEBUG: POST body <data>\n") if ENV['DEBUG']
245
+
205
246
  response = connection.post do |req|
206
247
  req.options.timeout = timeout
207
248
  req.headers['internal-request-source'] = "fastlane"
208
249
  req.body = options
209
250
  end
210
251
 
252
+ UI.message("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
253
+
211
254
  case response.status
212
255
  when 200...300
213
256
  UI.message("Binary uploaded")
@@ -227,23 +270,30 @@ module Fastlane
227
270
  def self.update_release_upload(api_token, owner_name, app_name, upload_id, status)
228
271
  connection = self.connection
229
272
 
230
- response = connection.patch("v0.1/apps/#{owner_name}/#{app_name}/release_uploads/#{upload_id}") do |req|
273
+ url = "v0.1/apps/#{owner_name}/#{app_name}/release_uploads/#{upload_id}"
274
+ body = {
275
+ status: status
276
+ }
277
+
278
+ UI.message("DEBUG: PATCH #{url}") if ENV['DEBUG']
279
+ UI.message("DEBUG: PATCH body #{JSON.pretty_generate(body)}\n") if ENV['DEBUG']
280
+
281
+ response = connection.patch(url) do |req|
231
282
  req.headers['X-API-Token'] = api_token
232
283
  req.headers['internal-request-source'] = "fastlane"
233
- req.body = {
234
- "status" => status
235
- }
284
+ req.body = body
236
285
  end
237
286
 
287
+ UI.message("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
288
+
238
289
  case response.status
239
290
  when 200...300
240
- UI.message("DEBUG: #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
241
291
  response.body
242
292
  when 401
243
293
  UI.user_error!("Auth Error, provided invalid token")
244
294
  false
245
295
  when 500...600
246
- UI.crash!("Internal Service Error, please try again later")
296
+ UI.abort_with_message!("Internal Service Error, please try again later")
247
297
  else
248
298
  UI.error("Error #{response.status}: #{response.body}")
249
299
  false
@@ -253,15 +303,21 @@ module Fastlane
253
303
  # get existing release
254
304
  def self.get_release(api_token, owner_name, app_name, release_id)
255
305
  connection = self.connection
256
- response = connection.get("v0.1/apps/#{owner_name}/#{app_name}/releases/#{release_id}") do |req|
306
+
307
+ url = "v0.1/apps/#{owner_name}/#{app_name}/releases/#{release_id}"
308
+
309
+ UI.message("DEBUG: GET #{url}") if ENV['DEBUG']
310
+
311
+ response = connection.get(url) do |req|
257
312
  req.headers['X-API-Token'] = api_token
258
313
  req.headers['internal-request-source'] = "fastlane"
259
314
  end
260
315
 
316
+ UI.message("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
317
+
261
318
  case response.status
262
319
  when 200...300
263
320
  release = response.body
264
- UI.message("DEBUG: #{JSON.pretty_generate(release)}") if ENV['DEBUG']
265
321
  release
266
322
  when 404
267
323
  UI.error("Not found, invalid release url")
@@ -279,15 +335,20 @@ module Fastlane
279
335
  def self.get_destination(api_token, owner_name, app_name, destination_type, destination_name)
280
336
  connection = self.connection
281
337
 
282
- response = connection.get("v0.1/apps/#{owner_name}/#{app_name}/distribution_#{destination_type}s/#{ERB::Util.url_encode(destination_name)}") do |req|
338
+ url = "v0.1/apps/#{owner_name}/#{app_name}/distribution_#{destination_type}s/#{ERB::Util.url_encode(destination_name)}"
339
+
340
+ UI.message("DEBUG: GET #{url}") if ENV['DEBUG']
341
+
342
+ response = connection.get(url) do |req|
283
343
  req.headers['X-API-Token'] = api_token
284
344
  req.headers['internal-request-source'] = "fastlane"
285
345
  end
286
346
 
347
+ UI.message("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
348
+
287
349
  case response.status
288
350
  when 200...300
289
351
  destination = response.body
290
- UI.message("DEBUG: received #{destination_type} #{JSON.pretty_generate(destination)}") if ENV['DEBUG']
291
352
  destination
292
353
  when 404
293
354
  UI.error("Not found, invalid distribution #{destination_type} name")
@@ -305,14 +366,22 @@ module Fastlane
305
366
  def self.update_release(api_token, owner_name, app_name, release_id, release_notes = '')
306
367
  connection = self.connection
307
368
 
308
- response = connection.put("v0.1/apps/#{owner_name}/#{app_name}/releases/#{release_id}") do |req|
369
+ url = "v0.1/apps/#{owner_name}/#{app_name}/releases/#{release_id}"
370
+ body = {
371
+ release_notes: release_notes
372
+ }
373
+
374
+ UI.message("DEBUG: PUT #{url}") if ENV['DEBUG']
375
+ UI.message("DEBUG: PUT body #{JSON.pretty_generate(body)}\n") if ENV['DEBUG']
376
+
377
+ response = connection.put(url) do |req|
309
378
  req.headers['X-API-Token'] = api_token
310
379
  req.headers['internal-request-source'] = "fastlane"
311
- req.body = {
312
- release_notes: release_notes
313
- }
380
+ req.body = body
314
381
  end
315
382
 
383
+ UI.message("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
384
+
316
385
  case response.status
317
386
  when 200...300
318
387
  # get full release info
@@ -321,8 +390,6 @@ module Fastlane
321
390
 
322
391
  download_url = release['download_url']
323
392
 
324
- UI.message("DEBUG: #{JSON.pretty_generate(release)}") if ENV['DEBUG']
325
-
326
393
  Actions.lane_context[Fastlane::Actions::SharedValues::APPCENTER_DOWNLOAD_LINK] = download_url
327
394
  Actions.lane_context[Fastlane::Actions::SharedValues::APPCENTER_BUILD_INFORMATION] = release
328
395
 
@@ -345,19 +412,25 @@ module Fastlane
345
412
  def self.update_release_metadata(api_token, owner_name, app_name, release_id, dsa_signature)
346
413
  return if dsa_signature.to_s == ''
347
414
 
348
- release_metadata = {
349
- dsa_signature: dsa_signature
415
+ url = "v0.1/apps/#{owner_name}/#{app_name}/releases/#{release_id}"
416
+ body = {
417
+ metadata: {
418
+ dsa_signature: dsa_signature
419
+ }
350
420
  }
351
421
 
422
+ UI.message("DEBUG: PATCH #{url}") if ENV['DEBUG']
423
+ UI.message("DEBUG: PATCH body #{JSON.pretty_generate(body)}\n") if ENV['DEBUG']
424
+
352
425
  connection = self.connection
353
- response = connection.patch("v0.1/apps/#{owner_name}/#{app_name}/releases/#{release_id}") do |req|
426
+ response = connection.patch(url) do |req|
354
427
  req.headers['X-API-Token'] = api_token
355
428
  req.headers['internal-request-source'] = "fastlane"
356
- req.body = {
357
- metadata: release_metadata
358
- }
429
+ req.body = body
359
430
  end
360
431
 
432
+ UI.message("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
433
+
361
434
  case response.status
362
435
  when 200...300
363
436
  UI.message("Release Metadata was successfully updated for release '#{release_id}'")
@@ -372,25 +445,32 @@ module Fastlane
372
445
  false
373
446
  end
374
447
  end
375
-
448
+
376
449
  # add release to distribution group or store
377
450
  def self.add_to_destination(api_token, owner_name, app_name, release_id, destination_type, destination_id, mandatory_update = false, notify_testers = false)
378
451
  connection = self.connection
379
452
 
380
- UI.message("DEBUG: getting #{release_id}") if ENV['DEBUG']
453
+ url = "v0.1/apps/#{owner_name}/#{app_name}/releases/#{release_id}/#{destination_type}s"
454
+ body = {
455
+ id: destination_id
456
+ }
381
457
 
382
- body = { "id" => destination_id }
383
458
  if destination_type == "group"
384
459
  body["mandatory_update"] = mandatory_update
385
460
  body["notify_testers"] = notify_testers
386
461
  end
387
462
 
388
- response = connection.post("v0.1/apps/#{owner_name}/#{app_name}/releases/#{release_id}/#{destination_type}s") do |req|
463
+ UI.message("DEBUG: POST #{url}") if ENV['DEBUG']
464
+ UI.message("DEBUG: POST body #{JSON.pretty_generate(body)}\n") if ENV['DEBUG']
465
+
466
+ response = connection.post(url) do |req|
389
467
  req.headers['X-API-Token'] = api_token
390
468
  req.headers['internal-request-source'] = "fastlane"
391
469
  req.body = body
392
470
  end
393
471
 
472
+ UI.message("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
473
+
394
474
  case response.status
395
475
  when 200...300
396
476
  # get full release info
@@ -399,8 +479,6 @@ module Fastlane
399
479
 
400
480
  download_url = release['download_url']
401
481
 
402
- UI.message("DEBUG: received release #{JSON.pretty_generate(release)}") if ENV['DEBUG']
403
-
404
482
  Actions.lane_context[Fastlane::Actions::SharedValues::APPCENTER_DOWNLOAD_LINK] = download_url
405
483
  Actions.lane_context[Fastlane::Actions::SharedValues::APPCENTER_BUILD_INFORMATION] = release
406
484
 
@@ -423,11 +501,17 @@ module Fastlane
423
501
  def self.get_app(api_token, owner_name, app_name)
424
502
  connection = self.connection
425
503
 
426
- response = connection.get("v0.1/apps/#{owner_name}/#{app_name}") do |req|
504
+ url = "v0.1/apps/#{owner_name}/#{app_name}"
505
+
506
+ UI.message("DEBUG: GET #{url}") if ENV['DEBUG']
507
+
508
+ response = connection.get(url) do |req|
427
509
  req.headers['X-API-Token'] = api_token
428
510
  req.headers['internal-request-source'] = "fastlane"
429
511
  end
430
512
 
513
+ UI.message("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
514
+
431
515
  case response.status
432
516
  when 200...300
433
517
  UI.message("DEBUG: #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
@@ -448,23 +532,28 @@ module Fastlane
448
532
  def self.create_app(api_token, owner_type, owner_name, app_name, app_display_name, os, platform)
449
533
  connection = self.connection
450
534
 
451
- endpoint = owner_type == "user" ? "v0.1/apps" : "v0.1/orgs/#{owner_name}/apps"
535
+ url = owner_type == "user" ? "v0.1/apps" : "v0.1/orgs/#{owner_name}/apps"
536
+ body = {
537
+ display_name: app_display_name,
538
+ name: app_name,
539
+ os: os,
540
+ platform: platform
541
+ }
542
+
543
+ UI.message("DEBUG: POST #{url}") if ENV['DEBUG']
544
+ UI.message("DEBUG: POST body #{JSON.pretty_generate(body)}\n") if ENV['DEBUG']
452
545
 
453
- response = connection.post(endpoint) do |req|
546
+ response = connection.post(url) do |req|
454
547
  req.headers['X-API-Token'] = api_token
455
548
  req.headers['internal-request-source'] = "fastlane"
456
- req.body = {
457
- "display_name" => app_display_name,
458
- "name" => app_name,
459
- "os" => os,
460
- "platform" => platform
461
- }
549
+ req.body = body
462
550
  end
463
551
 
552
+ UI.message("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
553
+
464
554
  case response.status
465
555
  when 200...300
466
556
  created = response.body
467
- UI.message("DEBUG: #{JSON.pretty_generate(created)}") if ENV['DEBUG']
468
557
  UI.success("Created #{os}/#{platform} app with name \"#{created['name']}\" and display name \"#{created['display_name']}\" for #{owner_type} \"#{owner_name}\"")
469
558
  true
470
559
  when 401
@@ -479,16 +568,19 @@ module Fastlane
479
568
  def self.fetch_distribution_groups(api_token:, owner_name:, app_name:)
480
569
  connection = self.connection
481
570
 
482
- endpoint = "/v0.1/apps/#{owner_name}/#{app_name}/distribution_groups"
571
+ url = "/v0.1/apps/#{owner_name}/#{app_name}/distribution_groups"
572
+
573
+ UI.message("DEBUG: GET #{url}") if ENV['DEBUG']
483
574
 
484
- response = connection.get(endpoint) do |req|
575
+ response = connection.get(url) do |req|
485
576
  req.headers['X-API-Token'] = api_token
486
577
  req.headers['internal-request-source'] = "fastlane"
487
578
  end
488
579
 
580
+ UI.message("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
581
+
489
582
  case response.status
490
583
  when 200...300
491
- UI.message("DEBUG: #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
492
584
  response.body
493
585
  when 401
494
586
  UI.user_error!("Auth Error, provided invalid token")
@@ -505,16 +597,19 @@ module Fastlane
505
597
  def self.fetch_devices(api_token:, owner_name:, app_name:, distribution_group:)
506
598
  connection = self.connection(nil, false, true)
507
599
 
508
- endpoint = "/v0.1/apps/#{owner_name}/#{app_name}/distribution_groups/#{ERB::Util.url_encode(distribution_group)}/devices/download_devices_list"
600
+ url = "/v0.1/apps/#{owner_name}/#{app_name}/distribution_groups/#{ERB::Util.url_encode(distribution_group)}/devices/download_devices_list"
509
601
 
510
- response = connection.get(endpoint) do |req|
602
+ UI.message("DEBUG: GET #{url}") if ENV['DEBUG']
603
+
604
+ response = connection.get(url) do |req|
511
605
  req.headers['X-API-Token'] = api_token
512
606
  req.headers['internal-request-source'] = "fastlane"
513
607
  end
514
608
 
609
+ UI.message("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
610
+
515
611
  case response.status
516
612
  when 200...300
517
- UI.message("DEBUG: #{response.body.inspect}") if ENV['DEBUG']
518
613
  response.body
519
614
  when 401
520
615
  UI.user_error!("Auth Error, provided invalid token")
@@ -528,17 +623,87 @@ module Fastlane
528
623
  end
529
624
  end
530
625
 
531
- # Note: This does not support testing environment (INT)
626
+ def self.fetch_releases(api_token:, owner_name:, app_name:)
627
+ connection = self.connection(nil, false, true)
628
+
629
+ url = "/v0.1/apps/#{owner_name}/#{app_name}/releases"
630
+
631
+ UI.message("DEBUG: GET #{url}") if ENV['DEBUG']
632
+
633
+ response = connection.get(url) do |req|
634
+ req.headers['X-API-Token'] = api_token
635
+ req.headers['internal-request-source'] = "fastlane"
636
+ end
637
+
638
+ UI.message("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
639
+
640
+ case response.status
641
+ when 200...300
642
+ JSON.parse(response.body)
643
+ when 401
644
+ UI.user_error!("Auth Error, provided invalid token")
645
+ false
646
+ when 404
647
+ UI.error("Not found, invalid owner or application name")
648
+ false
649
+ else
650
+ UI.error("Error #{response.status}: #{response.body}")
651
+ false
652
+ end
653
+ end
654
+
532
655
  def self.get_release_url(owner_type, owner_name, app_name, release_id)
533
656
  owner_path = owner_type == "user" ? "users/#{owner_name}" : "orgs/#{owner_name}"
657
+ if ENV['APPCENTER_ENV']&.upcase == 'INT'
658
+ return "https://portal-server-core-integration.dev.avalanch.es/#{owner_path}/apps/#{app_name}/distribute/releases/#{release_id}"
659
+ end
660
+
534
661
  return "https://appcenter.ms/#{owner_path}/apps/#{app_name}/distribute/releases/#{release_id}"
535
662
  end
536
663
 
537
- # Note: This does not support testing environment (INT)
538
664
  def self.get_install_url(owner_type, owner_name, app_name)
539
665
  owner_path = owner_type == "user" ? "users/#{owner_name}" : "orgs/#{owner_name}"
666
+ if ENV['APPCENTER_ENV']&.upcase == 'INT'
667
+ return "https://install.portal-server-core-integration.dev.avalanch.es/#{owner_path}/apps/#{app_name}"
668
+ end
669
+
540
670
  return "https://install.appcenter.ms/#{owner_path}/apps/#{app_name}"
541
671
  end
672
+
673
+ # add new created app to existing distribution group
674
+ def self.add_new_app_to_distribution_group(api_token:, owner_name:, app_name:, destination_name:)
675
+ url = URI.escape("/v0.1/orgs/#{owner_name}/distribution_groups/#{destination_name}/apps")
676
+ body = {
677
+ apps: [
678
+ { name: app_name }
679
+ ]
680
+ }
681
+
682
+ UI.message("DEBUG: POST #{url}") if ENV['DEBUG']
683
+ UI.message("DEBUG: POST body #{JSON.pretty_generate(body)}\n") if ENV['DEBUG']
684
+
685
+ response = connection.post(url) do |req|
686
+ req.headers['X-API-Token'] = api_token
687
+ req.headers['internal-request-source'] = "fastlane"
688
+ req.body = body
689
+ end
690
+
691
+ UI.message("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG']
692
+
693
+ case response.status
694
+ when 200...300
695
+ created = response.body
696
+ UI.success("Added new app #{app_name} to distribution group #{destination_name}")
697
+ when 401
698
+ UI.user_error!("Auth Error, provided invalid token")
699
+ when 404
700
+ UI.error("Not found, invalid distribution group name #{destination_name}")
701
+ when 409
702
+ UI.success("App already added to distribution group #{destination_name}")
703
+ else
704
+ UI.error("Error adding app to distribution group #{response.status}: #{response.body}")
705
+ end
706
+ end
542
707
  end
543
708
  end
544
709
  end