diff options
author | Robert Speicher <rspeicher@gmail.com> | 2019-07-26 14:32:20 +0000 |
---|---|---|
committer | Robert Speicher <rspeicher@gmail.com> | 2019-07-26 14:32:20 +0000 |
commit | 900ef6fc316c7d4024545b5d08598c61fa9f3936 (patch) | |
tree | 7d3bcf2a70326434f67be6dcffa8e55489d60944 /app/models/project.rb | |
parent | 995d8e6c5e52afc294573e016f86f2a429b85d8e (diff) | |
parent | ae58f82e62d60edf0a1de2790d1798f5b5f16b28 (diff) | |
download | gitlab-ce-900ef6fc316c7d4024545b5d08598c61fa9f3936.tar.gz |
Merge branch 'mc/feature/find-all-artifacts-for-sha' into 'master'
Find build by sha from ref
Closes #64534 and #45697
See merge request gitlab-org/gitlab-ce!30843
Diffstat (limited to 'app/models/project.rb')
-rw-r--r-- | app/models/project.rb | 25 |
1 files changed, 18 insertions, 7 deletions
diff --git a/app/models/project.rb b/app/models/project.rb index 0020e423628..cca7da8c49a 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -719,16 +719,27 @@ class Project < ApplicationRecord repository.commits_by(oids: oids) end - # ref can't be HEAD, can only be branch/tag name or SHA - def latest_successful_build_for(job_name, ref = default_branch) - latest_pipeline = ci_pipelines.latest_successful_for(ref) + # ref can't be HEAD, can only be branch/tag name + def latest_successful_build_for_ref(job_name, ref = default_branch) + return unless ref + + latest_pipeline = ci_pipelines.latest_successful_for_ref(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) + 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}")) + def latest_successful_build_for_ref!(job_name, ref = default_branch) + latest_successful_build_for_ref(job_name, ref) || raise(ActiveRecord::RecordNotFound.new("Couldn't find job #{job_name}")) end def merge_base_commit(first_commit_id, second_commit_id) @@ -1503,12 +1514,12 @@ class Project < ApplicationRecord end @latest_successful_pipeline_for_default_branch = - ci_pipelines.latest_successful_for(default_branch) + ci_pipelines.latest_successful_for_ref(default_branch) end def latest_successful_pipeline_for(ref = nil) if ref && ref != default_branch - ci_pipelines.latest_successful_for(ref) + ci_pipelines.latest_successful_for_ref(ref) else latest_successful_pipeline_for_default_branch end |