diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-09-30 15:08:09 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-09-30 15:08:09 +0000 |
commit | 538fff823de57d1ba5317961aa43091de9dc007f (patch) | |
tree | c741665b338cc0d51ce5f73f5671e5eee8e69349 /app/models/commit_with_pipeline.rb | |
parent | 3692e9f8a23386c627942ca2a9edd8c00af7e904 (diff) | |
download | gitlab-ce-538fff823de57d1ba5317961aa43091de9dc007f.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/models/commit_with_pipeline.rb')
-rw-r--r-- | app/models/commit_with_pipeline.rb | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/app/models/commit_with_pipeline.rb b/app/models/commit_with_pipeline.rb new file mode 100644 index 00000000000..f382ae8f55a --- /dev/null +++ b/app/models/commit_with_pipeline.rb @@ -0,0 +1,38 @@ +# frozen_string_literal: true + +class CommitWithPipeline < SimpleDelegator + include Presentable + + def initialize(commit) + @latest_pipelines = {} + super(commit) + end + + def pipelines + project.ci_pipelines.where(sha: sha) + end + + def last_pipeline + strong_memoize(:last_pipeline) do + pipelines.last + end + end + + def latest_pipeline(ref = nil) + @latest_pipelines.fetch(ref) do |ref| + @latest_pipelines[ref] = latest_pipeline_for_project(ref, project) + end + end + + def latest_pipeline_for_project(ref, pipeline_project) + pipeline_project.ci_pipelines.latest_pipeline_per_commit(id, ref)[id] + end + + def set_latest_pipeline_for_ref(ref, pipeline) + @latest_pipelines[ref] = pipeline + end + + def status(ref = nil) + latest_pipeline(ref)&.status + end +end |