summaryrefslogtreecommitdiff
path: root/app/models
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2016-10-26 23:21:50 +0200
committerBob Van Landuyt <bob@vanlanduyt.co>2016-12-05 20:55:45 +0100
commit1123057ab792ac73b1611f4d3a9faf79369dd6da (patch)
treeae88332a5d2d47d5a814583fbe874582ebaf859c /app/models
parent5fedc46343d054df28ce81a320f33d1d43d02bc8 (diff)
downloadgitlab-ce-1123057ab792ac73b1611f4d3a9faf79369dd6da.tar.gz
Feature: delegate all open discussions to Issue
When a merge request can only be merged when all discussions are resolved. This feature allows to easily delegate those discussions to a new issue, while marking them as resolved in the merge request. The user is presented with a new issue, prepared with mentions of all unresolved discussions, including the first unresolved note of the discussion, time and link to the note. When the issue is created, the discussions in the merge request will get a system note directing the user to the newly created issue.
Diffstat (limited to 'app/models')
-rw-r--r--app/models/discussion.rb4
-rw-r--r--app/models/merge_request.rb8
-rw-r--r--app/models/note.rb2
3 files changed, 13 insertions, 1 deletions
diff --git a/app/models/discussion.rb b/app/models/discussion.rb
index 75a85563235..bbe813db823 100644
--- a/app/models/discussion.rb
+++ b/app/models/discussion.rb
@@ -88,6 +88,10 @@ class Discussion
@first_note ||= @notes.first
end
+ def first_note_to_resolve
+ @first_note_to_resolve ||= notes.detect(&:to_be_resolved?)
+ end
+
def last_note
@last_note ||= @notes.last
end
diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb
index bfb016df46d..a6fc9bb120d 100644
--- a/app/models/merge_request.rb
+++ b/app/models/merge_request.rb
@@ -480,6 +480,14 @@ class MergeRequest < ActiveRecord::Base
@diff_discussions ||= self.notes.diff_notes.discussions
end
+ def resolvable_discussions
+ @resolvable_discussions ||= diff_discussions.select(&:to_be_resolved?)
+ end
+
+ def discussions_can_be_resolved_by?(user)
+ resolvable_discussions.all? { |discussion| discussion.can_resolve?(user) }
+ end
+
def find_diff_discussion(discussion_id)
notes = self.notes.diff_notes.where(discussion_id: discussion_id).fresh.to_a
return if notes.empty?
diff --git a/app/models/note.rb b/app/models/note.rb
index 5b50ca285c3..08bd08743ef 100644
--- a/app/models/note.rb
+++ b/app/models/note.rb
@@ -99,7 +99,7 @@ class Note < ActiveRecord::Base
end
def discussions
- Discussion.for_notes(all)
+ Discussion.for_notes(fresh)
end
def grouped_diff_discussions