diff options
author | Oswaldo Ferreira <oswaldo@gitlab.com> | 2018-07-12 16:35:08 -0300 |
---|---|---|
committer | Oswaldo Ferreira <oswaldo@gitlab.com> | 2018-07-12 16:35:08 -0300 |
commit | 7492e35dd1b11f075f603dd32a90f56a0f2ef79f (patch) | |
tree | 973c3d4acab516c77b026785440ec8ff6d9a7d88 /app/controllers/commit_collection.rb | |
parent | f3e3618398c3e7a91ed9db8adaf7e72af08e94d8 (diff) | |
download | gitlab-ce-osw-test-diffs.tar.gz |
stuffosw-test-diffs
Diffstat (limited to 'app/controllers/commit_collection.rb')
-rw-r--r-- | app/controllers/commit_collection.rb | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/app/controllers/commit_collection.rb b/app/controllers/commit_collection.rb new file mode 100644 index 00000000000..dd93af9df64 --- /dev/null +++ b/app/controllers/commit_collection.rb @@ -0,0 +1,44 @@ +# 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 + + # 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 + statuses = project.pipelines.latest_status_per_commit(map(&:id), ref) + + 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 |