From 74c3132fa548d2e4956a198b1af07cf959d8391e Mon Sep 17 00:00:00 2001 From: Nelson Osacky Date: Mon, 24 Mar 2025 15:05:44 +0100 Subject: [PATCH 1/2] Add ability to upload emerge score. This is triggered by adding --score to the end of a regular upload. This works by uploads a build via the regular pathway and then triggers the score to be calculated by calling get on the score url and then prints that url to the console. --- lib/commands/upload/build.rb | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/commands/upload/build.rb b/lib/commands/upload/build.rb index bb5cbf9..2646e11 100644 --- a/lib/commands/upload/build.rb +++ b/lib/commands/upload/build.rb @@ -23,6 +23,8 @@ class Build < EmergeCLI::Commands::GlobalOptions option :base_sha, type: :string, required: false, desc: 'Base SHA' option :previous_sha, type: :string, required: false, desc: 'Previous SHA' option :pr_number, type: :string, required: false, desc: 'PR number' + option :score, type: :boolean, default: false, required: false, + desc: 'Upload build for generating Emerge Score' def initialize(network: nil, git_info_provider: nil) @network = network @@ -77,7 +79,29 @@ def call(**options) Logger.info('Upload complete successfully!') Logger.info "Time taken: #{(Time.now - start_time).round(2)} seconds" - Logger.info("✅ You can view the build analysis at https://emergetools.com/build/#{upload_id}") + + result_url = if @options[:score] + score_url = "https://emergetools.com/score/#{upload_id}" + + Logger.info 'Fetching score...' + score_response = @network.get( + path: '/score', + query: { uploadId: upload_id } + ) + + unless score_response.status == 200 + Logger.error("Score calculation trigger failed with status #{score_response.status}") + Logger.error("Response body: #{score_response.body}") + raise "Score calculation trigger failed with status #{score_response.status}" + end + + Logger.info '✅ Score calculation triggered' + score_url + else + "https://emergetools.com/build/#{upload_id}" + end + + Logger.info("✅ You can view the #{@options[:score] ? 'score' : 'build analysis'} at #{result_url}") end end From 45d35faf35c8b2fe72bf6d57bc02ae4b5f6a26ca Mon Sep 17 00:00:00 2001 From: Nelson Osacky Date: Mon, 24 Mar 2025 17:55:00 +0100 Subject: [PATCH 2/2] Fix rubocop errors --- lib/commands/upload/build.rb | 46 ++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/lib/commands/upload/build.rb b/lib/commands/upload/build.rb index 2646e11..29b57f5 100644 --- a/lib/commands/upload/build.rb +++ b/lib/commands/upload/build.rb @@ -23,8 +23,8 @@ class Build < EmergeCLI::Commands::GlobalOptions option :base_sha, type: :string, required: false, desc: 'Base SHA' option :previous_sha, type: :string, required: false, desc: 'Previous SHA' option :pr_number, type: :string, required: false, desc: 'PR number' - option :score, type: :boolean, default: false, required: false, - desc: 'Upload build for generating Emerge Score' + option :score, type: :boolean, default: false, required: false, + desc: 'Upload build for generating Emerge Score' def initialize(network: nil, git_info_provider: nil) @network = network @@ -79,28 +79,28 @@ def call(**options) Logger.info('Upload complete successfully!') Logger.info "Time taken: #{(Time.now - start_time).round(2)} seconds" - + result_url = if @options[:score] - score_url = "https://emergetools.com/score/#{upload_id}" - - Logger.info 'Fetching score...' - score_response = @network.get( - path: '/score', - query: { uploadId: upload_id } - ) - - unless score_response.status == 200 - Logger.error("Score calculation trigger failed with status #{score_response.status}") - Logger.error("Response body: #{score_response.body}") - raise "Score calculation trigger failed with status #{score_response.status}" - end - - Logger.info '✅ Score calculation triggered' - score_url - else - "https://emergetools.com/build/#{upload_id}" - end - + score_url = "https://emergetools.com/score/#{upload_id}" + + Logger.info 'Fetching score...' + score_response = @network.get( + path: '/score', + query: { uploadId: upload_id } + ) + + unless score_response.status == 200 + Logger.error("Score calculation trigger failed with status #{score_response.status}") + Logger.error("Response body: #{score_response.body}") + raise "Score calculation trigger failed with status #{score_response.status}" + end + + Logger.info '✅ Score calculation triggered' + score_url + else + "https://emergetools.com/build/#{upload_id}" + end + Logger.info("✅ You can view the #{@options[:score] ? 'score' : 'build analysis'} at #{result_url}") end end