Skip to content

Commit 74c3132

Browse files
committed
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.
1 parent 0b887f3 commit 74c3132

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

lib/commands/upload/build.rb

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ class Build < EmergeCLI::Commands::GlobalOptions
2323
option :base_sha, type: :string, required: false, desc: 'Base SHA'
2424
option :previous_sha, type: :string, required: false, desc: 'Previous SHA'
2525
option :pr_number, type: :string, required: false, desc: 'PR number'
26+
option :score, type: :boolean, default: false, required: false,
27+
desc: 'Upload build for generating Emerge Score'
2628

2729
def initialize(network: nil, git_info_provider: nil)
2830
@network = network
@@ -77,7 +79,29 @@ def call(**options)
7779

7880
Logger.info('Upload complete successfully!')
7981
Logger.info "Time taken: #{(Time.now - start_time).round(2)} seconds"
80-
Logger.info("✅ You can view the build analysis at https://emergetools.com/build/#{upload_id}")
82+
83+
result_url = if @options[:score]
84+
score_url = "https://emergetools.com/score/#{upload_id}"
85+
86+
Logger.info 'Fetching score...'
87+
score_response = @network.get(
88+
path: '/score',
89+
query: { uploadId: upload_id }
90+
)
91+
92+
unless score_response.status == 200
93+
Logger.error("Score calculation trigger failed with status #{score_response.status}")
94+
Logger.error("Response body: #{score_response.body}")
95+
raise "Score calculation trigger failed with status #{score_response.status}"
96+
end
97+
98+
Logger.info '✅ Score calculation triggered'
99+
score_url
100+
else
101+
"https://emergetools.com/build/#{upload_id}"
102+
end
103+
104+
Logger.info("✅ You can view the #{@options[:score] ? 'score' : 'build analysis'} at #{result_url}")
81105
end
82106
end
83107

0 commit comments

Comments
 (0)