Class: Fastlane::Helper::AppcenterHelper
- Inherits:
-
Object
- Object
- Fastlane::Helper::AppcenterHelper
- Defined in:
- lib/fastlane/plugin/appcenter/helper/appcenter_helper.rb
Constant Summary collapse
- RELEASE_UPLOAD_STATUS_POLL_INTERVAL =
Time to wait between 2 status polls in seconds
1
- MAX_REQUEST_RETRIES =
Maximum number of retries for a request
2
- REQUEST_RETRY_INTERVAL =
Delay between retries in seconds
5
Class Method Summary collapse
-
.add_new_app_to_distribution_group(api_token:, owner_name:, app_name:, destination_name:) ⇒ Object
add new created app to existing distribution group.
-
.add_to_destination(api_token, owner_name, app_name, release_id, destination_type, destination_id, mandatory_update = false, notify_testers = false) ⇒ Object
add release to distribution group or store.
-
.connection(upload_url = nil, dsym = false, csv = false) ⇒ Object
create request.
-
.create_app(api_token, owner_type, owner_name, app_name, app_display_name, os, platform) ⇒ Object
returns true if app exists, false in case of 404 and error otherwise.
-
.create_dsym_upload(api_token, owner_name, app_name) ⇒ Object
creates new dSYM upload in appcenter returns: symbol_upload_id upload_url expiration_date.
-
.create_mapping_upload(api_token, owner_name, app_name, file_name, build_number, version) ⇒ Object
creates new mapping upload in appcenter returns: symbol_upload_id upload_url expiration_date.
-
.create_release_upload(api_token, owner_name, app_name, body) ⇒ Object
creates new release upload returns: upload_id upload_url.
- .fetch_devices(api_token:, owner_name:, app_name:, distribution_group:) ⇒ Object
- .fetch_distribution_groups(api_token:, owner_name:, app_name:) ⇒ Object
- .fetch_releases(api_token:, owner_name:, app_name:) ⇒ Object
-
.file_extname_full(path) ⇒ Object
basic utility method to check file types that App Center will accept, accounting for file types that can and should be zip-compressed before they are uploaded.
-
.finish_release_upload(finish_url, api_token, owner_name, app_name, upload_id, timeout) ⇒ Object
Verifies a successful upload to App Center returns: successful upload response body.
-
.get_app(api_token, owner_name, app_name) ⇒ Object
returns true if app exists, false in case of 404 and error otherwise.
-
.get_destination(api_token, owner_name, app_name, destination_type, destination_name) ⇒ Object
get distribution group or store.
- .get_install_url(owner_type, owner_name, app_name) ⇒ Object
-
.get_release(api_token, owner_name, app_name, release_id) ⇒ Object
get existing release.
- .get_release_url(owner_type, owner_name, app_name, release_id) ⇒ Object
-
.poll_for_release_id(api_token, url) ⇒ Object
Polls the upload for a release id.
-
.set_release_upload_metadata(set_metadata_url, api_token, owner_name, app_name, upload_id, timeout) ⇒ Object
sets metadata for new upload in App Center returns: chunk size.
-
.update_release(api_token, owner_name, app_name, release_id, release_notes = '') ⇒ Object
add release to destination.
-
.update_release_metadata(api_token, owner_name, app_name, release_id, dsa_signature) ⇒ Object
updates release metadata.
-
.update_release_upload(api_token, owner_name, app_name, upload_id, status) ⇒ Object
Commits or aborts the upload process for a release.
-
.update_symbol_upload(api_token, owner_name, app_name, symbol_upload_id, status) ⇒ Object
commits or aborts symbol upload.
-
.upload_build(api_token, owner_name, app_name, file, upload_id, upload_url, content_type, chunk_size, timeout) ⇒ Object
upload binary for specified upload_url if succeed, then commits the release otherwise aborts.
-
.upload_symbol(api_token, owner_name, app_name, symbol, symbol_type, symbol_upload_id, upload_url) ⇒ Object
upload symbol (dSYM or mapping) files to specified upload url if succeed, then commits the upload otherwise aborts.
Class Method Details
.add_new_app_to_distribution_group(api_token:, owner_name:, app_name:, destination_name:) ⇒ Object
add new created app to existing distribution group
811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 |
# File 'lib/fastlane/plugin/appcenter/helper/appcenter_helper.rb', line 811 def self.add_new_app_to_distribution_group(api_token:, owner_name:, app_name:, destination_name:) url = URI.escape("/v0.1/orgs/#{owner_name}/distribution_groups/#{destination_name}/apps") body = { apps: [ { name: app_name } ] } UI.("DEBUG: POST #{url}") if ENV['DEBUG'] UI.("DEBUG: POST body #{JSON.pretty_generate(body)}\n") if ENV['DEBUG'] response = connection.post(url) do |req| req.headers['X-API-Token'] = api_token req.headers['internal-request-source'] = "fastlane" req.body = body end UI.("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG'] case response.status when 200...300 created = response.body UI.success("Added new app #{app_name} to distribution group #{destination_name}") when 401 UI.user_error!("Auth Error, provided invalid token") when 404 UI.error("Not found, invalid distribution group name #{destination_name}") when 409 UI.success("App already added to distribution group #{destination_name}") else UI.error("Error adding app to distribution group #{response.status}: #{response.body}") end end |
.add_to_destination(api_token, owner_name, app_name, release_id, destination_type, destination_id, mandatory_update = false, notify_testers = false) ⇒ Object
add release to distribution group or store
587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 |
# File 'lib/fastlane/plugin/appcenter/helper/appcenter_helper.rb', line 587 def self.add_to_destination(api_token, owner_name, app_name, release_id, destination_type, destination_id, mandatory_update = false, notify_testers = false) connection = self.connection url = "v0.1/apps/#{owner_name}/#{app_name}/releases/#{release_id}/#{destination_type}s" body = { id: destination_id } if destination_type == "group" body["mandatory_update"] = mandatory_update body["notify_testers"] = notify_testers end UI.("DEBUG: POST #{url}") if ENV['DEBUG'] UI.("DEBUG: POST body #{JSON.pretty_generate(body)}\n") if ENV['DEBUG'] response = connection.post(url) do |req| req.headers['X-API-Token'] = api_token req.headers['internal-request-source'] = "fastlane" req.body = body end UI.("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG'] case response.status when 200...300 # get full release info release = self.get_release(api_token, owner_name, app_name, release_id) return false unless release download_url = release['download_url'] Actions.lane_context[Fastlane::Actions::SharedValues::APPCENTER_DOWNLOAD_LINK] = download_url Actions.lane_context[Fastlane::Actions::SharedValues::APPCENTER_BUILD_INFORMATION] = release UI.("Release '#{release_id}' (#{release['short_version']}) was successfully distributed'") release when 404 UI.error("Not found, invalid distribution #{destination_type} name") false when 401 UI.user_error!("Auth Error, provided invalid token") false else UI.error("Error adding to #{destination_type} #{response.status}: #{response.body}") false end end |
.connection(upload_url = nil, dsym = false, csv = false) ⇒ Object
create request
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/fastlane/plugin/appcenter/helper/appcenter_helper.rb', line 32 def self.connection(upload_url = nil, dsym = false, csv = false) require 'faraday' require 'faraday_middleware' default_api_url = "https://api.appcenter.ms" if ENV['APPCENTER_ENV']&.upcase == 'INT' default_api_url = "https://api-gateway-core-integration.dev.avalanch.es" end = { url: upload_url || default_api_url } UI.("DEBUG: BASE URL #{[:url]}") if ENV['DEBUG'] Faraday.new() do |builder| if upload_url builder.request :multipart unless dsym builder.request :url_encoded unless dsym else builder.request :json end builder.response :json, content_type: /\bjson$/ unless csv builder.use FaradayMiddleware::FollowRedirects builder.adapter :net_http end end |
.create_app(api_token, owner_type, owner_name, app_name, app_display_name, os, platform) ⇒ Object
returns true if app exists, false in case of 404 and error otherwise
669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 |
# File 'lib/fastlane/plugin/appcenter/helper/appcenter_helper.rb', line 669 def self.create_app(api_token, owner_type, owner_name, app_name, app_display_name, os, platform) connection = self.connection url = owner_type == "user" ? "v0.1/apps" : "v0.1/orgs/#{owner_name}/apps" body = { display_name: app_display_name, name: app_name, os: os, platform: platform } UI.("DEBUG: POST #{url}") if ENV['DEBUG'] UI.("DEBUG: POST body #{JSON.pretty_generate(body)}\n") if ENV['DEBUG'] response = connection.post(url) do |req| req.headers['X-API-Token'] = api_token req.headers['internal-request-source'] = "fastlane" req.body = body end UI.("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG'] case response.status when 200...300 created = response.body UI.success("Created #{os}/#{platform} app with name \"#{created['name']}\" and display name \"#{created['display_name']}\" for #{owner_type} \"#{owner_name}\"") true when 401 UI.user_error!("Auth Error, provided invalid token") false else UI.error("Error creating app #{response.status}: #{response.body}") false end end |
.create_dsym_upload(api_token, owner_name, app_name) ⇒ Object
creates new dSYM upload in appcenter returns: symbol_upload_id upload_url expiration_date
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 172 173 |
# File 'lib/fastlane/plugin/appcenter/helper/appcenter_helper.rb', line 141 def self.create_dsym_upload(api_token, owner_name, app_name) connection = self.connection url = "v0.1/apps/#{owner_name}/#{app_name}/symbol_uploads" body = { symbol_type: 'Apple' } UI.("DEBUG: POST #{url}") if ENV['DEBUG'] UI.("DEBUG: POST body #{JSON.pretty_generate(body)}\n") if ENV['DEBUG'] response = connection.post(url) do |req| req.headers['X-API-Token'] = api_token req.headers['internal-request-source'] = "fastlane" req.body = body end UI.("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG'] case response.status when 200...300 response.body when 401 UI.user_error!("Auth Error, provided invalid token") false when 404 UI.error("Not found, invalid owner or application name") false else UI.error("Error #{response.status}: #{response.body}") false end end |
.create_mapping_upload(api_token, owner_name, app_name, file_name, build_number, version) ⇒ Object
creates new mapping upload in appcenter returns: symbol_upload_id upload_url expiration_date
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/fastlane/plugin/appcenter/helper/appcenter_helper.rb', line 99 def self.create_mapping_upload(api_token, owner_name, app_name, file_name, build_number, version) connection = self.connection url = "v0.1/apps/#{owner_name}/#{app_name}/symbol_uploads" body = { symbol_type: "AndroidProguard", file_name: file_name, build: build_number, version: version, } UI.("DEBUG: POST #{url}") if ENV['DEBUG'] UI.("DEBUG: POST body #{JSON.pretty_generate(body)}\n") if ENV['DEBUG'] response = connection.post(url) do |req| req.headers['X-API-Token'] = api_token req.headers['internal-request-source'] = "fastlane" req.body = body end UI.("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG'] case response.status when 200...300 response.body when 401 UI.user_error!("Auth Error, provided invalid token") false when 404 UI.error("Not found, invalid owner or application name") false else UI.error("Error #{response.status}: #{response.body}") false end end |
.create_release_upload(api_token, owner_name, app_name, body) ⇒ Object
creates new release upload returns: upload_id upload_url
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/fastlane/plugin/appcenter/helper/appcenter_helper.rb', line 63 def self.create_release_upload(api_token, owner_name, app_name, body) connection = self.connection url = "v0.1/apps/#{owner_name}/#{app_name}/uploads/releases" body ||= {} UI.("DEBUG: POST #{url}") if ENV['DEBUG'] UI.("DEBUG: POST body: #{JSON.pretty_generate(body)}\n") if ENV['DEBUG'] response = connection.post(url) do |req| req.headers['X-API-Token'] = api_token req.headers['internal-request-source'] = "fastlane" req.body = body end UI.("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG'] case response.status when 200...300 response.body when 401 UI.user_error!("Auth Error, provided invalid token") false when 404 UI.error("Not found, invalid owner or application name") false when 500...600 UI.("Internal Service Error, please try again later") else UI.error("Error #{response.status}: #{response.body}") false end end |
.fetch_devices(api_token:, owner_name:, app_name:, distribution_group:) ⇒ Object
734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 |
# File 'lib/fastlane/plugin/appcenter/helper/appcenter_helper.rb', line 734 def self.fetch_devices(api_token:, owner_name:, app_name:, distribution_group:) connection = self.connection(nil, false, true) url = "/v0.1/apps/#{owner_name}/#{app_name}/distribution_groups/#{ERB::Util.url_encode(distribution_group)}/devices/download_devices_list" UI.("DEBUG: GET #{url}") if ENV['DEBUG'] response = connection.get(url) do |req| req.headers['X-API-Token'] = api_token req.headers['internal-request-source'] = "fastlane" end UI.("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG'] case response.status when 200...300 response.body when 401 UI.user_error!("Auth Error, provided invalid token") false when 404 UI.error("Not found, invalid owner, application or distribution group name") false else UI.error("Error #{response.status}: #{response.body}") false end end |
.fetch_distribution_groups(api_token:, owner_name:, app_name:) ⇒ Object
705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 |
# File 'lib/fastlane/plugin/appcenter/helper/appcenter_helper.rb', line 705 def self.fetch_distribution_groups(api_token:, owner_name:, app_name:) connection = self.connection url = "/v0.1/apps/#{owner_name}/#{app_name}/distribution_groups" UI.("DEBUG: GET #{url}") if ENV['DEBUG'] response = connection.get(url) do |req| req.headers['X-API-Token'] = api_token req.headers['internal-request-source'] = "fastlane" end UI.("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG'] case response.status when 200...300 response.body when 401 UI.user_error!("Auth Error, provided invalid token") false when 404 UI.error("Not found, invalid owner or application name") false else UI.error("Error #{response.status}: #{response.body}") false end end |
.fetch_releases(api_token:, owner_name:, app_name:) ⇒ Object
763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 |
# File 'lib/fastlane/plugin/appcenter/helper/appcenter_helper.rb', line 763 def self.fetch_releases(api_token:, owner_name:, app_name:) connection = self.connection(nil, false, true) url = "/v0.1/apps/#{owner_name}/#{app_name}/releases" UI.("DEBUG: GET #{url}") if ENV['DEBUG'] response = connection.get(url) do |req| req.headers['X-API-Token'] = api_token req.headers['internal-request-source'] = "fastlane" end UI.("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG'] case response.status when 200...300 JSON.parse(response.body) when 401 UI.user_error!("Auth Error, provided invalid token") false when 404 UI.error("Not found, invalid owner or application name") false else UI.error("Error #{response.status}: #{response.body}") false end end |
.file_extname_full(path) ⇒ Object
basic utility method to check file types that App Center will accept, accounting for file types that can and should be zip-compressed before they are uploaded
23 24 25 26 27 28 29 |
# File 'lib/fastlane/plugin/appcenter/helper/appcenter_helper.rb', line 23 def self.file_extname_full(path) %w(.app.zip .dSYM.zip).each do |suffix| return suffix if path.to_s.downcase.end_with? suffix.downcase end File.extname path end |
.finish_release_upload(finish_url, api_token, owner_name, app_name, upload_id, timeout) ⇒ Object
Verifies a successful upload to App Center returns: successful upload response body.
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 |
# File 'lib/fastlane/plugin/appcenter/helper/appcenter_helper.rb', line 279 def self.finish_release_upload(finish_url, api_token, owner_name, app_name, upload_id, timeout) connection = self.connection(finish_url) UI.("DEBUG: POST #{finish_url}") if ENV['DEBUG'] response = connection.post do |req| req..timeout = timeout req.headers['internal-request-source'] = "fastlane" end UI.("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG'] case response.status when 200...300 if response.body['error'] == false UI.("Upload finished") self.update_release_upload(api_token, owner_name, app_name, upload_id, 'uploadFinished') else UI.error("Error finishing upload: #{response.body['message']}") false end when 401 UI.user_error!("Auth Error, provided invalid token") false else UI.error("Error finishing upload: #{response.status}: #{response.body}") false end end |
.get_app(api_token, owner_name, app_name) ⇒ Object
returns true if app exists, false in case of 404 and error otherwise
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 |
# File 'lib/fastlane/plugin/appcenter/helper/appcenter_helper.rb', line 638 def self.get_app(api_token, owner_name, app_name) connection = self.connection url = "v0.1/apps/#{owner_name}/#{app_name}" UI.("DEBUG: GET #{url}") if ENV['DEBUG'] response = connection.get(url) do |req| req.headers['X-API-Token'] = api_token req.headers['internal-request-source'] = "fastlane" end UI.("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG'] case response.status when 200...300 UI.("DEBUG: #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG'] true when 404 UI.("DEBUG: #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG'] false when 401 UI.user_error!("Auth Error, provided invalid token") false else UI.error("Error getting app #{owner_name}/#{app_name}, #{response.status}: #{response.body}") false end end |
.get_destination(api_token, owner_name, app_name, destination_type, destination_name) ⇒ Object
get distribution group or store
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 |
# File 'lib/fastlane/plugin/appcenter/helper/appcenter_helper.rb', line 472 def self.get_destination(api_token, owner_name, app_name, destination_type, destination_name) connection = self.connection url = "v0.1/apps/#{owner_name}/#{app_name}/distribution_#{destination_type}s/#{ERB::Util.url_encode(destination_name)}" UI.("DEBUG: GET #{url}") if ENV['DEBUG'] response = connection.get(url) do |req| req.headers['X-API-Token'] = api_token req.headers['internal-request-source'] = "fastlane" end UI.("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG'] case response.status when 200...300 destination = response.body destination when 404 UI.error("Not found, invalid distribution #{destination_type} name") false when 401 UI.user_error!("Auth Error, provided invalid token") false else UI.error("Error getting #{destination_type} #{response.status}: #{response.body}") false end end |
.get_install_url(owner_type, owner_name, app_name) ⇒ Object
801 802 803 804 805 806 807 808 |
# File 'lib/fastlane/plugin/appcenter/helper/appcenter_helper.rb', line 801 def self.get_install_url(owner_type, owner_name, app_name) owner_path = owner_type == "user" ? "users/#{owner_name}" : "orgs/#{owner_name}" if ENV['APPCENTER_ENV']&.upcase == 'INT' return "https://install.portal-server-core-integration.dev.avalanch.es/#{owner_path}/apps/#{app_name}" end return "https://install.appcenter.ms/#{owner_path}/apps/#{app_name}" end |
.get_release(api_token, owner_name, app_name, release_id) ⇒ Object
get existing release
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 |
# File 'lib/fastlane/plugin/appcenter/helper/appcenter_helper.rb', line 407 def self.get_release(api_token, owner_name, app_name, release_id) connection = self.connection url = "v0.1/apps/#{owner_name}/#{app_name}/releases/#{release_id}" UI.("DEBUG: GET #{url}") if ENV['DEBUG'] response = connection.get(url) do |req| req.headers['X-API-Token'] = api_token req.headers['internal-request-source'] = "fastlane" end UI.("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG'] case response.status when 200...300 release = response.body release when 404 UI.error("Not found, invalid release url") false when 401 UI.user_error!("Auth Error, provided invalid token") false else UI.error("Error fetching information about release #{response.status}: #{response.body}") false end end |
.get_release_url(owner_type, owner_name, app_name, release_id) ⇒ Object
792 793 794 795 796 797 798 799 |
# File 'lib/fastlane/plugin/appcenter/helper/appcenter_helper.rb', line 792 def self.get_release_url(owner_type, owner_name, app_name, release_id) owner_path = owner_type == "user" ? "users/#{owner_name}" : "orgs/#{owner_name}" if ENV['APPCENTER_ENV']&.upcase == 'INT' return "https://portal-server-core-integration.dev.avalanch.es/#{owner_path}/apps/#{app_name}/distribute/releases/#{release_id}" end return "https://appcenter.ms/#{owner_path}/apps/#{app_name}/distribute/releases/#{release_id}" end |
.poll_for_release_id(api_token, url) ⇒ Object
Polls the upload for a release id. When a release is uploaded, we have to check for a successful extraction before we can continue. returns: release_distinct_id
441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 |
# File 'lib/fastlane/plugin/appcenter/helper/appcenter_helper.rb', line 441 def self.poll_for_release_id(api_token, url) connection = self.connection while true UI.("DEBUG: GET #{url}") if ENV['DEBUG'] response = connection.get(url) do |req| req.headers['X-API-Token'] = api_token req.headers['internal-request-source'] = "fastlane" end UI.("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG'] case response.status when 200...300 case response.body['upload_status'] when "readyToBePublished" return response.body['release_distinct_id'] when "error" UI.error("Error fetching release: #{response.body['error_details']}") return false else sleep(RELEASE_UPLOAD_STATUS_POLL_INTERVAL) end else UI.error("Error fetching information about release #{response.status}: #{response.body}") return false end end end |
.set_release_upload_metadata(set_metadata_url, api_token, owner_name, app_name, upload_id, timeout) ⇒ Object
sets metadata for new upload in App Center returns: chunk size
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
# File 'lib/fastlane/plugin/appcenter/helper/appcenter_helper.rb', line 246 def self.(, api_token, owner_name, app_name, upload_id, timeout) connection = self.connection() UI.("DEBUG: POST #{}") if ENV['DEBUG'] UI.("DEBUG: POST body <data>\n") if ENV['DEBUG'] response = connection.post do |req| req..timeout = timeout req.headers['internal-request-source'] = "fastlane" end UI.("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG'] case response.status when 200...300 chunk_size = response.body['chunk_size'] unless chunk_size.is_a? Integer UI.error("Set metadata didn't return chunk size: #{response.status}: #{response.body}") false else UI.("Metadata set") chunk_size end when 401 UI.user_error!("Auth Error, provided invalid token") false else UI.error("Error setting metadata: #{response.status}: #{response.body}") false end end |
.update_release(api_token, owner_name, app_name, release_id, release_notes = '') ⇒ Object
add release to destination
503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 |
# File 'lib/fastlane/plugin/appcenter/helper/appcenter_helper.rb', line 503 def self.update_release(api_token, owner_name, app_name, release_id, release_notes = '') connection = self.connection url = "v0.1/apps/#{owner_name}/#{app_name}/releases/#{release_id}" body = { release_notes: release_notes } UI.("DEBUG: PUT #{url}") if ENV['DEBUG'] UI.("DEBUG: PUT body #{JSON.pretty_generate(body)}\n") if ENV['DEBUG'] response = connection.put(url) do |req| req.headers['X-API-Token'] = api_token req.headers['internal-request-source'] = "fastlane" req.body = body end UI.("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG'] case response.status when 200...300 # get full release info release = self.get_release(api_token, owner_name, app_name, release_id) return false unless release download_url = release['download_url'] Actions.lane_context[Fastlane::Actions::SharedValues::APPCENTER_DOWNLOAD_LINK] = download_url Actions.lane_context[Fastlane::Actions::SharedValues::APPCENTER_BUILD_INFORMATION] = release UI.("Release '#{release_id}' (#{release['short_version']}) was successfully updated") release when 404 UI.error("Not found, invalid release id") false when 401 UI.user_error!("Auth Error, provided invalid token") false else UI.error("Error adding updating release #{response.status}: #{response.body}") false end end |
.update_release_metadata(api_token, owner_name, app_name, release_id, dsa_signature) ⇒ Object
updates release metadata
549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 |
# File 'lib/fastlane/plugin/appcenter/helper/appcenter_helper.rb', line 549 def self.(api_token, owner_name, app_name, release_id, dsa_signature) return if dsa_signature.to_s == '' url = "v0.1/apps/#{owner_name}/#{app_name}/releases/#{release_id}" body = { metadata: { dsa_signature: dsa_signature } } UI.("DEBUG: PATCH #{url}") if ENV['DEBUG'] UI.("DEBUG: PATCH body #{JSON.pretty_generate(body)}\n") if ENV['DEBUG'] connection = self.connection response = connection.patch(url) do |req| req.headers['X-API-Token'] = api_token req.headers['internal-request-source'] = "fastlane" req.body = body end UI.("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG'] case response.status when 200...300 UI.("Release Metadata was successfully updated for release '#{release_id}'") when 404 UI.error("Not found, invalid release id") false when 401 UI.user_error!("Auth Error, provided invalid token") false else UI.error("Error adding updating release metadata #{response.status}: #{response.body}") false end end |
.update_release_upload(api_token, owner_name, app_name, upload_id, status) ⇒ Object
Commits or aborts the upload process for a release
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 |
# File 'lib/fastlane/plugin/appcenter/helper/appcenter_helper.rb', line 372 def self.update_release_upload(api_token, owner_name, app_name, upload_id, status) connection = self.connection url = "v0.1/apps/#{owner_name}/#{app_name}/uploads/releases/#{upload_id}" body = { upload_status: status, id: upload_id } UI.("DEBUG: PATCH #{url}") if ENV['DEBUG'] UI.("DEBUG: PATCH body #{JSON.pretty_generate(body)}\n") if ENV['DEBUG'] response = connection.patch(url) do |req| req.headers['X-API-Token'] = api_token req.headers['internal-request-source'] = "fastlane" req.body = body end UI.("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG'] case response.status when 200...300 response.body when 401 UI.user_error!("Auth Error, provided invalid token") false when 500...600 UI.("Internal Service Error, please try again later") else UI.error("Error #{response.status}: #{response.body}") false end end |
.update_symbol_upload(api_token, owner_name, app_name, symbol_upload_id, status) ⇒ Object
commits or aborts symbol upload
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/fastlane/plugin/appcenter/helper/appcenter_helper.rb', line 176 def self.update_symbol_upload(api_token, owner_name, app_name, symbol_upload_id, status) connection = self.connection url = "v0.1/apps/#{owner_name}/#{app_name}/symbol_uploads/#{symbol_upload_id}" body = { status: status } UI.("DEBUG: PATCH #{url}") if ENV['DEBUG'] UI.("DEBUG: PATCH body #{JSON.pretty_generate(body)}\n") if ENV['DEBUG'] response = connection.patch(url) do |req| req.headers['X-API-Token'] = api_token req.headers['internal-request-source'] = "fastlane" req.body = body end UI.("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG'] case response.status when 200...300 response.body when 401 UI.user_error!("Auth Error, provided invalid token") false else UI.error("Error #{response.status}: #{response.body}") false end end |
.upload_build(api_token, owner_name, app_name, file, upload_id, upload_url, content_type, chunk_size, timeout) ⇒ Object
upload binary for specified upload_url if succeed, then commits the release otherwise aborts
310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 |
# File 'lib/fastlane/plugin/appcenter/helper/appcenter_helper.rb', line 310 def self.upload_build(api_token, owner_name, app_name, file, upload_id, upload_url, content_type, chunk_size, timeout) block_number = 1 File.open(file).each_chunk(chunk_size) do |chunk| upload_chunk_url = "#{upload_url}&block_number=#{block_number}" retries = 0 while retries <= MAX_REQUEST_RETRIES begin connection = self.connection(upload_chunk_url, true) UI.("DEBUG: POST #{upload_chunk_url}") if ENV['DEBUG'] UI.("DEBUG: POST body <data>\n") if ENV['DEBUG'] response = connection.post do |req| req..timeout = timeout req.headers['internal-request-source'] = "fastlane" req.headers['Content-Length'] = chunk.length.to_s req.headers['Content-Type'] = 'application/octet-stream' req.body = chunk end UI.("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG'] status = response.status = response.body rescue Faraday::Error => e # Low level HTTP errors, we will retry them status = 0 = e. end case status when 200...300 if response.body['error'] == false UI.("Chunk uploaded") block_number += 1 break else UI.error("Error uploading binary #{response.body['message']}") return false end when 401 UI.user_error!("Auth Error, provided invalid token") return false when 400...407, 409...428, 430...499 UI.user_error!("Client error: #{response.status}: #{response.body}") return false else if retries < MAX_REQUEST_RETRIES UI.("DEBUG: Retryable error uploading binary #{status}: #{}") retries += 1 sleep(REQUEST_RETRY_INTERVAL) else UI.error("Error uploading binary #{status}: #{}") return false end end end end UI.("Binary uploaded") end |
.upload_symbol(api_token, owner_name, app_name, symbol, symbol_type, symbol_upload_id, upload_url) ⇒ Object
upload symbol (dSYM or mapping) files to specified upload url if succeed, then commits the upload otherwise aborts
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 |
# File 'lib/fastlane/plugin/appcenter/helper/appcenter_helper.rb', line 210 def self.upload_symbol(api_token, owner_name, app_name, symbol, symbol_type, symbol_upload_id, upload_url) connection = self.connection(upload_url, true) UI.("DEBUG: PUT #{upload_url}") if ENV['DEBUG'] UI.("DEBUG: PUT body <data>\n") if ENV['DEBUG'] response = connection.put do |req| req.headers['x-ms-blob-type'] = "BlockBlob" req.headers['Content-Length'] = File.size(symbol).to_s req.headers['internal-request-source'] = "fastlane" req.body = Faraday::UploadIO.new(symbol, 'application/octet-stream') if symbol && File.exist?(symbol) end UI.("DEBUG: #{response.status} #{JSON.pretty_generate(response.body)}\n") if ENV['DEBUG'] log_type = "dSYM" if symbol_type == "Apple" log_type = "mapping" if symbol_type == "Android" case response.status when 200...300 self.update_symbol_upload(api_token, owner_name, app_name, symbol_upload_id, 'committed') UI.success("#{log_type} uploaded") when 401 UI.user_error!("Auth Error, provided invalid token") false else UI.error("Error uploading #{log_type} #{response.status}: #{response.body}") self.update_symbol_upload(api_token, owner_name, app_name, symbol_upload_id, 'aborted') UI.error("#{log_type} upload aborted") false end end |