2017-11-10 14:57:11 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# A collection of Commit instances for a specific project and Git reference.
|
|
|
|
class CommitCollection
|
|
|
|
include Enumerable
|
|
|
|
|
|
|
|
attr_reader :project, :ref, :commits
|
|
|
|
|
|
|
|
# project - The project the commits belong to.
|
|
|
|
# commits - The Commit instances to store.
|
|
|
|
# ref - The name of the ref (e.g. "master").
|
|
|
|
def initialize(project, commits, ref = nil)
|
|
|
|
@project = project
|
|
|
|
@commits = commits
|
|
|
|
@ref = ref
|
|
|
|
end
|
|
|
|
|
|
|
|
def each(&block)
|
|
|
|
commits.each(&block)
|
|
|
|
end
|
|
|
|
|
2019-01-03 05:59:14 -05:00
|
|
|
def committers
|
|
|
|
emails = commits.reject(&:merge_commit?).map(&:committer_email).uniq
|
|
|
|
|
|
|
|
User.by_any_email(emails)
|
|
|
|
end
|
|
|
|
|
2017-11-10 14:57:11 -05:00
|
|
|
# Sets the pipeline status for every commit.
|
|
|
|
#
|
|
|
|
# Setting this status ahead of time removes the need for running a query for
|
|
|
|
# every commit we're displaying.
|
|
|
|
def with_pipeline_status
|
2018-12-05 09:39:15 -05:00
|
|
|
statuses = project.ci_pipelines.latest_status_per_commit(map(&:id), ref)
|
2017-11-10 14:57:11 -05:00
|
|
|
|
|
|
|
each do |commit|
|
|
|
|
commit.set_status_for_ref(ref, statuses[commit.id])
|
|
|
|
end
|
|
|
|
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
|
|
|
def respond_to_missing?(message, inc_private = false)
|
|
|
|
commits.respond_to?(message, inc_private)
|
|
|
|
end
|
|
|
|
|
|
|
|
# rubocop:disable GitlabSecurity/PublicSend
|
|
|
|
def method_missing(message, *args, &block)
|
|
|
|
commits.public_send(message, *args, &block)
|
|
|
|
end
|
|
|
|
end
|