Put 'hidden commits' logic in CommitsHelper

This commit is contained in:
Jacob Vosmaer 2016-03-04 15:45:58 +01:00
parent 5eeea4b7c6
commit f943156b5e
3 changed files with 23 additions and 12 deletions

View File

@ -211,4 +211,16 @@ module CommitsHelper
def clean(string)
Sanitize.clean(string, remove_contents: true)
end
def limited_commits(commits)
if commits.size > MergeRequestDiff::COMMITS_SAFE_SIZE
# Not 100% sure we need to decorate but it is idempotent and not so slow
[
commits.first(MergeRequestDiff::COMMITS_SAFE_SIZE),
commits.size - MergeRequestDiff::COMMITS_SAFE_SIZE
]
else
[commits, 0]
end
end
end

View File

@ -1,11 +1,14 @@
- commits, hidden = limited_commits(@commits, @project)
- commits = Commit.decorate(commits, @project)
%div.panel.panel-default
.panel-heading
Commits (#{@commits.count})
- if @commits.size > MergeRequestDiff::COMMITS_SAFE_SIZE
- if hidden > 0
%ul.well-list
- Commit.decorate(@commits.first(MergeRequestDiff::COMMITS_SAFE_SIZE), @project).each do |commit|
- commits.each do |commit|
= render "projects/commits/inline_commit", commit: commit, project: @project
%li.warning-row.unstyled
other #{@commits.size - MergeRequestDiff::COMMITS_SAFE_SIZE} commits hidden to prevent performance issues.
other #{hidden} commits hidden to prevent performance issues.
- else
%ul.well-list= render Commit.decorate(@commits, @project), project: @project
%ul.well-list= render commits, project: @project

View File

@ -1,11 +1,7 @@
- unless defined?(project)
- project = @project
- if @commits.size > MergeRequestDiff::COMMITS_SAFE_SIZE
- commits = @commits.first(MergeRequestDiff::COMMITS_SAFE_SIZE)
- overflow = true
- else
- commits = @commits
- overflow = false
- commits, hidden = limited_commits(@commits)
- commits.group_by { |c| c.committed_date.to_date }.sort.reverse.each do |day, commits|
.row.commits-row
@ -20,6 +16,6 @@
= render commits, project: project
%hr.lists-separator
- if overflow
- if hidden > 0
.alert.alert-warning
Not shown: #{@commits.size - MergeRequestDiff::COMMITS_SAFE_SIZE} more commits
Not shown: #{hidden} more commits