debian-mirror-gitlab/app/models/ci/commit_with_pipeline.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

55 lines
1.3 KiB
Ruby
Raw Normal View History

2021-03-08 18:12:59 +05:30
# frozen_string_literal: true
class Ci::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
2021-06-08 01:23:25 +05:30
def lazy_latest_pipeline
2023-07-09 08:55:56 +05:30
BatchLoader.for(sha).batch(key: project.id) do |shas, loader|
2021-06-08 01:23:25 +05:30
preload_pipelines = project.ci_pipelines.latest_pipeline_per_commit(shas.compact)
shas.each do |sha|
pipeline = preload_pipelines[sha]
loader.call(sha, pipeline)
end
end
end
2021-03-08 18:12:59 +05:30
def latest_pipeline(ref = nil)
@latest_pipelines.fetch(ref) do |ref|
2021-06-08 01:23:25 +05:30
@latest_pipelines[ref] = if ref
latest_pipeline_for_project(ref, project)
else
lazy_latest_pipeline&.itself
end
2021-03-08 18:12:59 +05:30
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