@@ -136,9 +136,12 @@ private def github_run_link(repo_owner : String, repo_name : String, run_id : In
136136 " https://github.com" + GitHubRoutes .gen_run(repo_owner: repo_owner, repo_name: repo_name, run_id: run_id) + " #artifacts"
137137end
138138
139- private def github_actions_link (repo_owner : String , repo_name : String , * , event : String , branch : String ) : String
139+ private def github_actions_link (
140+ repo_owner : String , repo_name : String , * ,
141+ event : String , branch : String , status : String
142+ ) : String
140143 " https://github.com/#{ repo_owner } /#{ repo_name } /actions?" + HTTP ::Params .encode({
141- query: " event:#{ event } is:success branch:#{ branch } " ,
144+ query: " event:#{ event } is:#{ status } branch:#{ branch } " ,
142145 })
143146end
144147
@@ -228,7 +231,10 @@ class NightlyLink
228231
229232 run, artifact = @@examples_cache .fetch(example_workflow) do
230233 token = GitHubApp .token(FALLBACK_INSTALL_ID )
231- run_ = get_latest_run(args[:repo_owner ], args[:repo_name ], args[:workflow ] + " .yml" , args[:branch ], token)
234+ run_ = get_latest_run(
235+ args[:repo_owner ], args[:repo_name ],
236+ workflow: args[:workflow ] + " .yml" , branch: args[:branch ], status: " success" , token: token
237+ )
232238 artifact_ = Artifacts .for_run(args[:repo_owner ], args[:repo_name ], run_.id, token, expires_in: 3 .hours).first
233239 {run_, artifact_}
234240 end
@@ -301,8 +307,12 @@ class NightlyLink
301307 unless workflow.to_i64?(whitespace: false ) || workflow.ends_with?(" .yml" ) || workflow.ends_with?(" .yaml" )
302308 workflow += " .yml"
303309 end
310+ status = ctx.request.query_params.fetch(" status" , " success" )
311+ if ! status.in?(" success" , " completed" )
312+ raise HTTPException .new(:BadRequest , " ?status must be 'success' (default) or 'completed'" )
313+ end
304314
305- run = get_latest_run(repo_owner, repo_name, workflow, branch, token)
315+ run = get_latest_run(repo_owner, repo_name, workflow: workflow , branch: branch, status: status, token: token)
306316 repo_owner, repo_name = run.repository.owner, run.repository.name
307317 if run.updated_at < 90 .days.ago
308318 message = " Warning: the latest successful run is older than 90 days, and its artifacts likely expired."
@@ -384,12 +394,15 @@ class NightlyLink
384394 ECR .embed(" templates/artifact_list.html" , ctx.response)
385395 end
386396
387- private def get_latest_run (repo_owner : String , repo_name : String , workflow : String , branch : String , token : InstallationToken )
397+ private def get_latest_run (
398+ repo_owner : String , repo_name : String ,
399+ workflow : String , branch : String , status : String , token : InstallationToken
400+ )
388401 futures = [{" push" , 5 .minutes}, {" schedule" , 1 .hour}].map do |(event , expires_in )|
389402 future do
390403 begin
391404 WorkflowRuns .for_workflow(
392- repo_owner, repo_name, workflow, branch: branch, event: event,
405+ repo_owner, repo_name, workflow, branch: branch, event: event, status: status,
393406 token: token, max_items: 1 , expires_in: expires_in
394407 )
395408 rescue e : Halite ::Exception ::ClientError
@@ -405,7 +418,7 @@ class NightlyLink
405418 end
406419 runs = futures.map(& .get.first?).compact
407420 if runs.empty?
408- gh_link = github_actions_link(repo_owner, repo_name, event: " push" , branch: branch)
421+ gh_link = github_actions_link(repo_owner, repo_name, event: " push" , branch: branch, status: status )
409422 raise HTTPException .new(:NotFound ,
410423 " No successful runs found for workflow '#{ workflow } ' and branch '#{ branch } '.\n " +
411424 " Check on GitHub: <#{ gh_link } >"
@@ -439,13 +452,18 @@ class NightlyLink
439452 unless workflow.to_i64?(whitespace: false ) || workflow.ends_with?(" .yml" ) || workflow.ends_with?(" .yaml" )
440453 workflow += " .yml"
441454 end
442- run = get_latest_run(repo_owner, repo_name, workflow, branch, token)
455+ status = ctx.request.query_params.fetch(" status" , " success" )
456+ if ! status.in?(" success" , " completed" )
457+ raise HTTPException .new(:BadRequest , " ?status must be 'success' (default) or 'completed'" )
458+ end
459+
460+ run = get_latest_run(repo_owner, repo_name, workflow: workflow, branch: branch, status: status, token: token)
443461 repo_owner, repo_name = run.repository.owner, run.repository.name
444462
445463 links = by_run(nil , repo_owner, repo_name, run.id, artifact, run.check_suite_id, h, zip: zip)
446464 title = {" Repository #{ repo_owner } /#{ repo_name } " , " Workflow #{ workflow } | Branch #{ branch } | Artifact #{ artifact } " }
447465 links << ArtifactLink .new(
448- github_actions_link(repo_owner, repo_name, event: run.event, branch: branch),
466+ github_actions_link(repo_owner, repo_name, event: run.event, branch: branch, status: status ),
449467 " Browse workflow runs on branch '#{ branch } '" , ext: true
450468 )
451469 canonical = abs_url(NightlyLink .gen_by_branch(
0 commit comments