diff options
author | Sean McGivern <sean@mcgivern.me.uk> | 2017-11-24 12:38:45 +0300 |
---|---|---|
committer | Sean McGivern <sean@mcgivern.me.uk> | 2017-11-24 12:38:45 +0300 |
commit | c4d844f08b99a5251f0d3cea7a493cb3480d5626 (patch) | |
tree | 8daa3c05bfa562c8e8dff93bc44c3ae38e943362 /app | |
parent | 3dd5bedb54ce1bb150ab5304463c0a63d6e10ec9 (diff) | |
parent | 5c2c471a835f9588e39ec11fa79571c8b44979f8 (diff) |
Merge branch 'issue_40374' into 'master'
Fix WIP system note not being created
Closes #40374
See merge request gitlab-org/gitlab-ce!15528
Diffstat (limited to 'app')
-rw-r--r-- | app/models/concerns/issuable.rb | 7 | ||||
-rw-r--r-- | app/models/merge_request.rb | 6 | ||||
-rw-r--r-- | app/services/issuable/common_system_notes_service.rb | 14 | ||||
-rw-r--r-- | app/services/merge_requests/base_service.rb | 14 | ||||
-rw-r--r-- | app/services/system_note_service.rb | 10 |
5 files changed, 29 insertions, 22 deletions
diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb index 35090181bd9..e607707475f 100644 --- a/app/models/concerns/issuable.rb +++ b/app/models/concerns/issuable.rb @@ -345,4 +345,11 @@ module Issuable def first_contribution? false end + + ## + # Overriden in MergeRequest + # + def wipless_title_changed(old_title) + old_title != title + end end diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 5cf41b2c7cb..2753e4b16e5 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -218,6 +218,12 @@ class MergeRequest < ActiveRecord::Base work_in_progress?(title) ? title : "WIP: #{title}" end + # Verifies if title has changed not taking into account WIP prefix + # for merge requests. + def wipless_title_changed(old_title) + self.class.wipless_title(old_title) != self.wipless_title + end + def hook_attrs Gitlab::HookData::MergeRequestBuilder.new(self).build end diff --git a/app/services/issuable/common_system_notes_service.rb b/app/services/issuable/common_system_notes_service.rb index 92eaa5d5115..3da21bd8b8f 100644 --- a/app/services/issuable/common_system_notes_service.rb +++ b/app/services/issuable/common_system_notes_service.rb @@ -41,6 +41,14 @@ module Issuable end end + def create_wip_note(old_title) + return unless issuable.is_a?(MergeRequest) + + if MergeRequest.work_in_progress?(old_title) != issuable.work_in_progress? + SystemNoteService.handle_merge_request_wip(issuable, issuable.project, current_user) + end + end + def create_labels_note(old_labels) added_labels = issuable.labels - old_labels removed_labels = old_labels - issuable.labels @@ -49,7 +57,11 @@ module Issuable end def create_title_change_note(old_title) - SystemNoteService.change_title(issuable, issuable.project, current_user, old_title) + create_wip_note(old_title) + + if issuable.wipless_title_changed(old_title) + SystemNoteService.change_title(issuable, issuable.project, current_user, old_title) + end end def create_description_change_note diff --git a/app/services/merge_requests/base_service.rb b/app/services/merge_requests/base_service.rb index d3938b065bc..f6ffd48deae 100644 --- a/app/services/merge_requests/base_service.rb +++ b/app/services/merge_requests/base_service.rb @@ -4,20 +4,6 @@ module MergeRequests SystemNoteService.change_status(merge_request, merge_request.target_project, current_user, state, nil) end - def create_title_change_note(issuable, old_title) - removed_wip = MergeRequest.work_in_progress?(old_title) && !issuable.work_in_progress? - added_wip = !MergeRequest.work_in_progress?(old_title) && issuable.work_in_progress? - changed_title = MergeRequest.wipless_title(old_title) != issuable.wipless_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) - end - - super if changed_title - end - def hook_data(merge_request, action, old_rev: nil, old_labels: [], old_assignees: [], old_total_time_spent: nil) hook_data = merge_request.to_hook_data(current_user, old_labels: old_labels, old_assignees: old_assignees, old_total_time_spent: old_total_time_spent) hook_data[:object_attributes][:action] = action diff --git a/app/services/system_note_service.rb b/app/services/system_note_service.rb index fe71a405565..30a5aab13bf 100644 --- a/app/services/system_note_service.rb +++ b/app/services/system_note_service.rb @@ -241,14 +241,10 @@ module SystemNoteService create_note(NoteSummary.new(noteable, project, author, body, action: 'merge')) end - def remove_merge_request_wip(noteable, project, author) - body = 'unmarked as a **Work In Progress**' + def handle_merge_request_wip(noteable, project, author) + prefix = noteable.work_in_progress? ? "marked" : "unmarked" - create_note(NoteSummary.new(noteable, project, author, body, action: 'title')) - end - - def add_merge_request_wip(noteable, project, author) - body = 'marked as a **Work In Progress**' + body = "#{prefix} as a **Work In Progress**" create_note(NoteSummary.new(noteable, project, author, body, action: 'title')) end |