2018-09-14 01:42:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-08-23 12:53:29 -04:00
|
|
|
module RendersCommits
|
2019-11-15 10:06:12 -05:00
|
|
|
def limited_commits(commits, commits_count)
|
|
|
|
if commits_count > MergeRequestDiff::COMMITS_SAFE_SIZE
|
2018-08-21 13:47:04 -04:00
|
|
|
[
|
|
|
|
commits.first(MergeRequestDiff::COMMITS_SAFE_SIZE),
|
2019-11-15 10:06:12 -05:00
|
|
|
commits_count - MergeRequestDiff::COMMITS_SAFE_SIZE
|
2018-08-21 13:47:04 -04:00
|
|
|
]
|
|
|
|
else
|
|
|
|
[commits, 0]
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# This is used as a helper method in a controller.
|
|
|
|
# rubocop: disable Gitlab/ModuleWithInstanceVariables
|
2019-11-15 10:06:12 -05:00
|
|
|
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-08-21 13:47:04 -04:00
|
|
|
prepare_commits_for_rendering(limited)
|
|
|
|
end
|
|
|
|
# rubocop: enable Gitlab/ModuleWithInstanceVariables
|
|
|
|
|
2017-08-23 12:53:29 -04:00
|
|
|
def prepare_commits_for_rendering(commits)
|
2021-04-12 17:11:12 -04:00
|
|
|
commits.each(&:lazy_author) # preload commits' authors
|
2021-04-26 17:10:25 -04:00
|
|
|
commits.each(&:lazy_latest_pipeline)
|
2021-04-12 17:11:12 -04:00
|
|
|
|
2017-11-22 02:50:36 -05:00
|
|
|
Banzai::CommitRenderer.render(commits, @project, current_user) # rubocop:disable Gitlab/ModuleWithInstanceVariables
|
2017-08-23 12:53:29 -04:00
|
|
|
|
|
|
|
commits
|
|
|
|
end
|
2018-12-10 00:23:15 -05:00
|
|
|
|
|
|
|
def valid_ref?(ref_name)
|
|
|
|
return true unless ref_name.present?
|
|
|
|
|
|
|
|
Gitlab::GitRefValidator.validate(ref_name)
|
|
|
|
end
|
2017-08-23 12:53:29 -04:00
|
|
|
end
|