Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatija Čupić <matteeyah@gmail.com>2019-07-17 16:33:52 +0300
committerMatija Čupić <matteeyah@gmail.com>2019-07-23 21:55:59 +0300
commit7cee6139c07db7ba4fd6febf74c24dbfaee8e59d (patch)
treee140f84706d0067f7a788bb4aa9ee677b3851f2b /app/models/project.rb
parentd892e80bf0161b535389c91ccb53539e4f08d790 (diff)
Find build by sha from ref
Adds ability to find builds by sha when only specifying a ref.
Diffstat (limited to 'app/models/project.rb')
-rw-r--r--app/models/project.rb13
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