diff options
Diffstat (limited to 'app/models/project.rb')
-rw-r--r-- | app/models/project.rb | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index 8030c645e2e..9616e8c9748 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -719,14 +719,25 @@ class Project < ApplicationRecord repository.commits_by(oids: oids) end - # ref can't be HEAD, can only be branch/tag name or SHA + # ref can't be HEAD, can only be branch/tag name def latest_successful_build_for(job_name, ref = default_branch) + return unless ref + latest_pipeline = ci_pipelines.latest_successful_for(ref) return unless latest_pipeline latest_pipeline.builds.latest.with_artifacts_archive.find_by(name: job_name) end + def latest_successful_build_for_sha(job_name, sha = commit(default_branch).id) + return unless sha + + latest_pipeline = ci_pipelines.latest_successful_for_sha(sha) + return unless latest_pipeline + + latest_pipeline.builds.latest.with_artifacts_archive.find_by(name: job_name) + end + def latest_successful_build_for!(job_name, ref = default_branch) latest_successful_build_for(job_name, ref) || raise(ActiveRecord::RecordNotFound.new("Couldn't find job #{job_name}")) end |