Class: Ci::CommitWithPipeline
- Inherits:
-
SimpleDelegator
- Object
- SimpleDelegator
- Ci::CommitWithPipeline
- Includes:
- Presentable
- Defined in:
- app/models/ci/commit_with_pipeline.rb
Instance Method Summary collapse
-
#initialize(commit) ⇒ CommitWithPipeline
constructor
A new instance of CommitWithPipeline.
- #last_pipeline ⇒ Object
- #latest_pipeline(ref = nil) ⇒ Object
- #latest_pipeline_for_project(ref, pipeline_project) ⇒ Object
- #lazy_latest_pipeline ⇒ Object
- #pipelines ⇒ Object
- #set_latest_pipeline_for_ref(ref, pipeline) ⇒ Object
- #status(ref = nil) ⇒ Object
Methods included from Presentable
Constructor Details
#initialize(commit) ⇒ CommitWithPipeline
Returns a new instance of CommitWithPipeline.
6 7 8 9 |
# File 'app/models/ci/commit_with_pipeline.rb', line 6 def initialize(commit) @latest_pipelines = {} super(commit) end |
Instance Method Details
#last_pipeline ⇒ Object
15 16 17 18 19 |
# File 'app/models/ci/commit_with_pipeline.rb', line 15 def last_pipeline strong_memoize(:last_pipeline) do pipelines.last end end |
#latest_pipeline(ref = nil) ⇒ Object
33 34 35 36 37 38 39 40 41 |
# File 'app/models/ci/commit_with_pipeline.rb', line 33 def latest_pipeline(ref = nil) @latest_pipelines.fetch(ref) do |ref| @latest_pipelines[ref] = if ref latest_pipeline_for_project(ref, project) else lazy_latest_pipeline&.itself end end end |
#latest_pipeline_for_project(ref, pipeline_project) ⇒ Object
43 44 45 |
# File 'app/models/ci/commit_with_pipeline.rb', line 43 def latest_pipeline_for_project(ref, pipeline_project) pipeline_project.ci_pipelines.latest_pipeline_per_commit(id, ref)[id] end |
#lazy_latest_pipeline ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 |
# File 'app/models/ci/commit_with_pipeline.rb', line 21 def lazy_latest_pipeline BatchLoader.for(sha).batch(key: project.id) do |shas, loader| 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 |
#pipelines ⇒ Object
11 12 13 |
# File 'app/models/ci/commit_with_pipeline.rb', line 11 def pipelines project.ci_pipelines.where(sha: sha) end |
#set_latest_pipeline_for_ref(ref, pipeline) ⇒ Object
47 48 49 |
# File 'app/models/ci/commit_with_pipeline.rb', line 47 def set_latest_pipeline_for_ref(ref, pipeline) @latest_pipelines[ref] = pipeline end |
#status(ref = nil) ⇒ Object
51 52 53 |
# File 'app/models/ci/commit_with_pipeline.rb', line 51 def status(ref = nil) latest_pipeline(ref)&.status end |