@@ -5,35 +5,17 @@ def self.run(params)
55 app_display_name = params [ :app_display_name ]
66
77 app_center_org_name = params [ :app_center_org_name ]
8- app_center_info = if app_center_org_name && defined? ( SharedValues ::APPCENTER_BUILD_INFORMATION )
9- lane_context [ SharedValues ::APPCENTER_BUILD_INFORMATION ] || { }
10- else
11- { }
12- end
8+ app_center_info = extract_app_center_info ( app_center_org_name )
139 app_center_app_name = params [ :app_center_app_name ] || app_center_info [ 'app_name' ]
1410 app_center_app_display_name = app_center_info [ 'app_display_name' ] || app_center_app_name
1511 app_center_release_id = params [ :app_center_release_id ] || app_center_info [ 'id' ]
1612
17- # Consolidate the list of Metadata to display with some implicit metadata if available
18- metadata = params [ :metadata ] &.transform_keys ( &:to_s ) || { }
19- metadata [ 'Build Number' ] ||= app_center_info [ 'version' ]
20- metadata [ 'Version' ] ||= app_center_info [ 'short_version' ]
21- metadata [ app_center_info [ 'app_os' ] == 'Android' ? 'Application ID' : 'Bundle ID' ] ||= app_center_info [ 'bundle_identifier' ]
22- # (Feel free to add more CI-specific env vars in the line below to support other CI providers if you need)
23- metadata [ 'Commit' ] ||= ENV . fetch ( 'BUILDKITE_COMMIT' , nil ) || other_action . last_git_commit [ :abbreviated_commit_hash ]
13+ # Assemble explicit metadata passed as params with implicit metadata derived from App Center params or lane_context
14+ metadata = consolidate_metadata ( params , app_center_info )
2415
2516 # Installation Link(s) -- either download_url param, or App Center Build link, or both
26- install_url = nil
27- if params [ :download_url ]
28- install_url = params [ :download_url ]
29- metadata [ 'Direct Download' ] = "<a href='#{ install_url } '><code>#{ File . basename ( install_url ) } </code></a>"
30- end
31- if app_center_org_name && app_center_app_name
32- install_url = "https://install.appcenter.ms/orgs/#{ app_center_org_name } /apps/#{ app_center_app_name } /releases/#{ app_center_release_id } "
33- metadata [ 'App Center Build' ] = "<a href='#{ install_url } '>#{ app_center_app_display_name } \# #{ app_center_release_id } </a>"
34- end
35- UI . user_error! ( NO_INSTALL_URL_ERROR_MESSAGE ) if install_url . nil?
36- qr_code_url = "https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl=#{ CGI . escape ( install_url ) } &choe=UTF-8"
17+ qr_code_url , extra_metadata = build_install_links ( params [ :download_url ] , app_center_org_name , app_center_app_name , app_center_app_display_name , app_center_release_id )
18+ metadata . merge! ( extra_metadata )
3719
3820 # Build the comment parts
3921 icon_img_tag = img_tag ( params [ :app_icon ] || app_center_info [ 'app_icon_url' ] , alt : app_display_name )
@@ -70,6 +52,40 @@ def self.run(params)
7052
7153 DEFAULT_APP_CENTER_FOOTNOTE = '<em>Automatticians: You can use our internal self-serve MC tool to give yourself access to App Center if needed.</em>' . freeze
7254
55+ def self . extract_app_center_info ( app_center_org_name )
56+ if app_center_org_name && defined? ( SharedValues ::APPCENTER_BUILD_INFORMATION )
57+ lane_context [ SharedValues ::APPCENTER_BUILD_INFORMATION ] || { }
58+ else
59+ { }
60+ end
61+ end
62+
63+ def self . build_install_links ( download_url , app_center_org_name , app_center_app_name , app_center_app_display_name , app_center_release_id )
64+ install_url = nil
65+ extra_metadata = { }
66+ if download_url
67+ install_url = download_url
68+ extra_metadata [ 'Direct Download' ] = "<a href='#{ install_url } '><code>#{ File . basename ( install_url ) } </code></a>"
69+ end
70+ if app_center_org_name && app_center_app_name
71+ install_url = "https://install.appcenter.ms/orgs/#{ app_center_org_name } /apps/#{ app_center_app_name } /releases/#{ app_center_release_id } "
72+ extra_metadata [ 'App Center Build' ] = "<a href='#{ install_url } '>#{ app_center_app_display_name } \# #{ app_center_release_id } </a>"
73+ end
74+ UI . user_error! ( NO_INSTALL_URL_ERROR_MESSAGE ) if install_url . nil?
75+ qr_code_url = "https://chart.googleapis.com/chart?chs=500x500&cht=qr&chl=#{ CGI . escape ( install_url ) } &choe=UTF-8"
76+ [ qr_code_url , extra_metadata ]
77+ end
78+
79+ def self . consolidate_metadata ( params , app_center_info )
80+ metadata = params [ :metadata ] &.transform_keys ( &:to_s ) || { }
81+ metadata [ 'Build Number' ] ||= app_center_info [ 'version' ]
82+ metadata [ 'Version' ] ||= app_center_info [ 'short_version' ]
83+ metadata [ app_center_info [ 'app_os' ] == 'Android' ? 'Application ID' : 'Bundle ID' ] ||= app_center_info [ 'bundle_identifier' ]
84+ # (Feel free to add more CI-specific env vars in the line below to support other CI providers if you need)
85+ metadata [ 'Commit' ] ||= ENV . fetch ( 'BUILDKITE_COMMIT' , nil ) || other_action . last_git_commit [ :abbreviated_commit_hash ]
86+ metadata
87+ end
88+
7389 def self . img_tag ( url_or_emoji , alt : '' )
7490 return nil if url_or_emoji . nil?
7591
0 commit comments