summaryrefslogtreecommitdiff
path: root/app/models/note.rb
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-03-06 17:14:19 +0100
committerDouwe Maan <douwe@gitlab.com>2015-03-06 18:09:00 +0100
commit663b3c968f73f8ffebf32059fed86192ecbee5d8 (patch)
tree01bd5692cc2e6ced1af614da1754855c76421425 /app/models/note.rb
parent8b53d9efe648f10e0572c2d8017489d0d3bb4755 (diff)
downloadgitlab-ce-663b3c968f73f8ffebf32059fed86192ecbee5d8.tar.gz
Condense commits already in target branch when updating merge request source branch.
Diffstat (limited to 'app/models/note.rb')
-rw-r--r--app/models/note.rb31
1 files changed, 27 insertions, 4 deletions
diff --git a/app/models/note.rb b/app/models/note.rb
index e6c258ffbe9..e79b7a88344 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -151,18 +151,41 @@ class Note < ActiveRecord::Base
)
end
- def create_new_commits_note(noteable, project, author, commits)
- commits_text = ActionController::Base.helpers.pluralize(commits.size, 'new commit')
+ def create_new_commits_note(merge_request, project, author, new_commits, existing_commits = [])
+ total_count = new_commits.length + existing_commits.length
+ commits_text = ActionController::Base.helpers.pluralize(total_count, 'commit')
body = "Added #{commits_text}:\n\n"
- commits.each do |commit|
+ if existing_commits.length > 0
+ commit_ids =
+ if existing_commits.length == 1
+ existing_commits.first.short_id
+ else
+ "#{existing_commits.first.short_id}...#{existing_commits.last.short_id}"
+ end
+
+ commits_text = ActionController::Base.helpers.pluralize(existing_commits.length, 'commit')
+
+ branch =
+ if merge_request.for_fork?
+ "#{merge_request.target_project_namespace}:#{merge_request.target_branch}"
+ else
+ merge_request.target_branch
+ end
+
+ message = "* #{commit_ids} - _#{commits_text} from branch `#{branch}`_"
+ body << message
+ body << "\n"
+ end
+
+ new_commits.each do |commit|
message = "* #{commit.short_id} - #{commit.title}"
body << message
body << "\n"
end
create(
- noteable: noteable,
+ noteable: merge_request,
project: project,
author: author,
note: body,