debian-mirror-gitlab/app/controllers/concerns/renders_commits.rb

39 lines
1.2 KiB
Ruby
Raw Normal View History

2018-12-05 23:21:45 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
module RendersCommits
2019-12-26 22:10:19 +05:30
def limited_commits(commits, commits_count)
if commits_count > MergeRequestDiff::COMMITS_SAFE_SIZE
2018-11-20 20:47:30 +05:30
[
commits.first(MergeRequestDiff::COMMITS_SAFE_SIZE),
2019-12-26 22:10:19 +05:30
commits_count - MergeRequestDiff::COMMITS_SAFE_SIZE
2018-11-20 20:47:30 +05:30
]
else
[commits, 0]
end
end
# This is used as a helper method in a controller.
# rubocop: disable Gitlab/ModuleWithInstanceVariables
2019-12-26 22:10:19 +05:30
def set_commits_for_rendering(commits, commits_count: nil)
@total_commit_count = commits_count || commits.size
limited, @hidden_commit_count = limited_commits(commits, @total_commit_count)
2018-11-20 20:47:30 +05:30
prepare_commits_for_rendering(limited)
end
# rubocop: enable Gitlab/ModuleWithInstanceVariables
2018-03-17 18:26:18 +05:30
def prepare_commits_for_rendering(commits)
2021-04-29 21:17:54 +05:30
commits.each(&:lazy_author) # preload commits' authors
2021-06-08 01:23:25 +05:30
commits.each(&:lazy_latest_pipeline)
2021-04-29 21:17:54 +05:30
2018-03-17 18:26:18 +05:30
Banzai::CommitRenderer.render(commits, @project, current_user) # rubocop:disable Gitlab/ModuleWithInstanceVariables
commits
end
2019-02-15 15:39:39 +05:30
def valid_ref?(ref_name)
return true unless ref_name.present?
2023-06-20 00:43:36 +05:30
Gitlab::GitRefValidator.validate(ref_name, skip_head_ref_check: true)
2019-02-15 15:39:39 +05:30
end
2018-03-17 18:26:18 +05:30
end