summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDouwe Maan <douwe@selenight.nl>2016-02-26 19:34:14 -0800
committerDouwe Maan <douwe@selenight.nl>2016-02-26 19:34:14 -0800
commitacf9778e77e5d6e36cb3eb750e88adaa5881a94a (patch)
treeb50ec601a245819389d7c8977de7e6f843789ff7
parent01160fc06182de89c400af174861f6545ad6ceb8 (diff)
downloadgitlab-ce-acf9778e77e5d6e36cb3eb750e88adaa5881a94a.tar.gz
Use specialized system notes when MR is (un)marked as WIP
-rw-r--r--CHANGELOG1
-rw-r--r--app/models/merge_request.rb8
-rw-r--r--app/services/merge_requests/base_service.rb16
-rw-r--r--app/services/system_note_service.rb12
4 files changed, 36 insertions, 1 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 5521c1286a8..5ad85ab8ccc 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -3,6 +3,7 @@ Please view this file on the master branch, on stable branches it's out of date.
v 8.6.0 (unreleased)
- Improve the formatting for the user page bio (Connor Shea)
- Fix avatar stretching by providing a cropping feature (Johann Pardanaud)
+ - Use specialized system notes when MR is (un)marked as WIP
v 8.5.1
- Fix group projects styles
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index 1543ef311d7..04c378691f3 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -259,8 +259,14 @@ class MergeRequest < ActiveRecord::Base
self.target_project.events.where(target_id: self.id, target_type: "MergeRequest", action: Event::CLOSED).last
end
+ WIP_REGEX = /\A\[?WIP(\]|:| )\s*/i.freeze
+
def work_in_progress?
- !!(title =~ /\A\[?WIP(\]|:| )/i)
+ title =~ WIP_REGEX
+ end
+
+ def wipless_title
+ self.title.sub(WIP_REGEX, "")
end
def mergeable?
diff --git a/app/services/merge_requests/base_service.rb b/app/services/merge_requests/base_service.rb
index 7b306a8a531..9370b4c01a6 100644
--- a/app/services/merge_requests/base_service.rb
+++ b/app/services/merge_requests/base_service.rb
@@ -5,6 +5,22 @@ module MergeRequests
SystemNoteService.change_status(merge_request, merge_request.target_project, current_user, merge_request.state, nil)
end
+ def create_title_change_note(issuable, old_title)
+ wipless_old_title = old_title.sub(MergeRequest::WIP_REGEX, "")
+ wipless_new_title = issuable.title.sub(MergeRequest::WIP_REGEX, "")
+
+ removed_wip = wipless_old_title == issuable.title
+ added_wip = wipless_new_title == old_title
+
+ if removed_wip
+ SystemNoteService.remove_merge_request_wip(issuable, issuable.project, current_user)
+ elsif added_wip
+ SystemNoteService.add_merge_request_wip(issuable, issuable.project, current_user)
+ else
+ super
+ end
+ end
+
def hook_data(merge_request, action)
hook_data = merge_request.to_hook_data(current_user)
merge_request_url = Gitlab::UrlBuilder.new(:merge_request).build(merge_request.id)
diff --git a/app/services/system_note_service.rb b/app/services/system_note_service.rb
index edced010811..e579ca76565 100644
--- a/app/services/system_note_service.rb
+++ b/app/services/system_note_service.rb
@@ -144,6 +144,18 @@ class SystemNoteService
create_note(noteable: noteable, project: project, author: author, note: body)
end
+ def self.remove_merge_request_wip(noteable, project, author)
+ body = 'Unmarked this merge request as Work In Progress'
+
+ create_note(noteable: noteable, project: project, author: author, note: body)
+ end
+
+ def self.add_merge_request_wip(noteable, project, author)
+ body = 'Marked this merge request as **Work In Progress**'
+
+ create_note(noteable: noteable, project: project, author: author, note: body)
+ end
+
# Called when the title of a Noteable is changed
#
# noteable - Noteable object that responds to `title`