From 430758653ce7e4d32b40648e6263b79c2709bdad Mon Sep 17 00:00:00 2001 From: Jeroen Jacobs Date: Fri, 27 Jun 2014 16:48:30 +0200 Subject: Adds comments to commits in the API --- app/models/note.rb | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) (limited to 'app/models/note.rb') diff --git a/app/models/note.rb b/app/models/note.rb index fa5fdea4eb0..d70ebcd8e6d 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -226,7 +226,7 @@ class Note < ActiveRecord::Base end def diff_file_index - line_code.split('_')[0] + line_code.split('_')[0] if line_code end def diff_file_name @@ -242,11 +242,11 @@ class Note < ActiveRecord::Base end def diff_old_line - line_code.split('_')[1].to_i + line_code.split('_')[1].to_i if line_code end def diff_new_line - line_code.split('_')[2].to_i + line_code.split('_')[2].to_i if line_code end def generate_line_code(line) @@ -267,6 +267,20 @@ class Note < ActiveRecord::Base @diff_line end + def diff_line_type + return @diff_line_type if @diff_line_type + + if diff + diff_lines.each do |line| + if generate_line_code(line) == self.line_code + @diff_line_type = line.type + end + end + end + + @diff_line_type + end + def truncated_diff_lines max_number_of_lines = 16 prev_match_line = nil -- cgit v1.2.1 From 2ee1ec430012e4489ea1d70a13bcb827cafede2e Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Wed, 5 Nov 2014 12:53:10 +0100 Subject: Do not allow cross reference note in a mr if a mr contains mentioned commit. --- app/models/note.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'app/models/note.rb') diff --git a/app/models/note.rb b/app/models/note.rb index f0ed7580b4c..4252d57ccb1 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -90,7 +90,7 @@ class Note < ActiveRecord::Base note_options.merge!(noteable: noteable) end - create(note_options) + create(note_options) unless cross_reference_disallowed?(noteable, mentioner) end def create_milestone_change_note(noteable, project, author, milestone) @@ -165,6 +165,15 @@ class Note < ActiveRecord::Base [:discussion, type.try(:underscore), id, line_code].join("-").to_sym end + # Determine if cross reference note should be created. + # eg. mentioning a commit in MR comments which exists inside a MR + # should not create "mentioned in" note. + def cross_reference_disallowed?(noteable, mentioner) + if mentioner.kind_of?(MergeRequest) + mentioner.commits.map(&:id).include? noteable.id + end + end + # Determine whether or not a cross-reference note already exists. def cross_reference_exists?(noteable, mentioner) gfm_reference = mentioner_gfm_ref(noteable, mentioner) -- cgit v1.2.1 From 383ac10ca5797818f7a61d04fbff0fbf54e87c0e Mon Sep 17 00:00:00 2001 From: Alex Elman Date: Wed, 27 Aug 2014 11:20:28 -0500 Subject: Issue-280 Send notifications when a note is added to a commit and author is a group member This fixes a bug where commit authors weren't receiving email notifications for notes added to their commits and their membership was in the group but not the project. The fix is to look up membership via the team object which accounts for both project and group members. --- app/models/note.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'app/models/note.rb') diff --git a/app/models/note.rb b/app/models/note.rb index f0ed7580b4c..996def0478a 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -251,8 +251,8 @@ class Note < ActiveRecord::Base def commit_author @commit_author ||= - project.users.find_by(email: noteable.author_email) || - project.users.find_by(name: noteable.author_name) + project.team.users.find_by(email: noteable.author_email) || + project.team.users.find_by(name: noteable.author_name) rescue nil end -- cgit v1.2.1 From 4ab728bfe89adbc8f9d430e80f0582b1775a50d5 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 15 Dec 2014 16:31:23 +0200 Subject: Fix random Argument error when update note In some strange cases Ruby thinks `system` is not AR field but Kernel.system call and raises exception during save. It should prevent this random wierd behaviour Signed-off-by: Dmitriy Zaporozhets --- app/models/note.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models/note.rb') diff --git a/app/models/note.rb b/app/models/note.rb index 5bf645bbd1d..5996298be22 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -502,6 +502,6 @@ class Note < ActiveRecord::Base end def editable? - !system + !read_attribute(:system) end end -- cgit v1.2.1 From b758b4c80bacd655f0241375c2391028cfd73f77 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Sat, 10 Jan 2015 19:26:00 -0800 Subject: If noteable is nil - make discussion outdated --- app/models/note.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'app/models/note.rb') diff --git a/app/models/note.rb b/app/models/note.rb index 5996298be22..e99bc2668d6 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -296,6 +296,7 @@ class Note < ActiveRecord::Base # If not - its outdated diff def active? return true unless self.diff + return false unless noteable noteable.diffs.each do |mr_diff| next unless mr_diff.new_path == self.diff.new_path -- cgit v1.2.1 From 5c801602189bdf179432e9ef5885f6c6fef438f2 Mon Sep 17 00:00:00 2001 From: Steven Burgart Date: Sun, 18 Jan 2015 10:29:37 -0500 Subject: Fix various typos signe-in -> signed-in go_to_gihub_for_permissions -> go_to_github_for_permissions descendand -> descendant behavour -> behaviour recepient_email -> recipient_email generate_fingerpint -> generate_fingerprint dependes -> depends Cant't -> Can't wisit -> visit notifcation -> notification sufficent_scope -> sufficient_scope? levet -> level --- app/models/note.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models/note.rb') diff --git a/app/models/note.rb b/app/models/note.rb index e99bc2668d6..b78c8b343a1 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -480,7 +480,7 @@ class Note < ActiveRecord::Base end # FIXME: Hack for polymorphic associations with STI - # For more information wisit http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#label-Polymorphic+Associations + # For more information visit http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html#label-Polymorphic+Associations def noteable_type=(sType) super(sType.to_s.classify.constantize.base_class.to_s) end -- cgit v1.2.1 From 505a492cd87be7683827c5f46a05b6a7dddffc86 Mon Sep 17 00:00:00 2001 From: Michael Clarke Date: Wed, 5 Nov 2014 20:45:18 +0000 Subject: Only count the user's last vote --- app/models/note.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'app/models/note.rb') diff --git a/app/models/note.rb b/app/models/note.rb index e99bc2668d6..1b7e412e9c5 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -459,6 +459,23 @@ class Note < ActiveRecord::Base ) end + def superceded?(notes) + return false unless vote? + notes.each do |note| + next if note == self + if note.vote? && + self[:author_id] == note[:author_id] && + self[:created_at] <= note[:created_at] + return true + end + end + false + end + + def vote? + upvote? || downvote? + end + def votable? for_issue? || (for_merge_request? && !for_diff_line?) end -- cgit v1.2.1 From a5b255fbdfcd01f355de2dca76e379e12b43d6e6 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Thu, 22 Jan 2015 09:37:47 -0800 Subject: Code improvements according to styleguide --- app/models/note.rb | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'app/models/note.rb') diff --git a/app/models/note.rb b/app/models/note.rb index cb879dc2ce3..0b988cc3e0f 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -461,14 +461,17 @@ class Note < ActiveRecord::Base def superceded?(notes) return false unless vote? + notes.each do |note| next if note == self + if note.vote? && - self[:author_id] == note[:author_id] && - self[:created_at] <= note[:created_at] + self[:author_id] == note[:author_id] && + self[:created_at] <= note[:created_at] return true end end + false end -- cgit v1.2.1 From 3e97ac2022c52a79640fccc97127f8bb059134fd Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Fri, 6 Feb 2015 10:21:48 -0800 Subject: Add index on order columns --- app/models/note.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models/note.rb') diff --git a/app/models/note.rb b/app/models/note.rb index 0b988cc3e0f..39fe421fd7a 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -49,7 +49,7 @@ class Note < ActiveRecord::Base scope :not_inline, ->{ where(line_code: [nil, '']) } scope :system, ->{ where(system: true) } scope :common, ->{ where(noteable_type: ["", nil]) } - scope :fresh, ->{ order("created_at ASC, id ASC") } + scope :fresh, ->{ order(created_at: :asc, id: :asc) } scope :inc_author_project, ->{ includes(:project, :author) } scope :inc_author, ->{ includes(:author) } -- cgit v1.2.1 From 8681cb3137511e51e19f76aef9839be28f8fcd6a Mon Sep 17 00:00:00 2001 From: Nikita Verkhovin Date: Sat, 7 Feb 2015 17:14:55 +0600 Subject: Add labels notes --- app/models/note.rb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'app/models/note.rb') diff --git a/app/models/note.rb b/app/models/note.rb index 39fe421fd7a..ccd9783e7d4 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -121,6 +121,36 @@ class Note < ActiveRecord::Base }) end + def create_labels_change_note(noteable, project, author, added_labels, removed_labels) + labels_count = added_labels.count + removed_labels.count + added_labels = added_labels.map{ |label| "~#{label.id}" }.join(' ') + removed_labels = removed_labels.map{ |label| "~#{label.id}" }.join(' ') + message = '' + + if added_labels.present? + message << "added #{added_labels}" + end + + if added_labels.present? && removed_labels.present? + message << ' and ' + end + + if removed_labels.present? + message << "removed #{removed_labels}" + end + + message << ' ' << 'label'.pluralize(labels_count) + body = "_#{message.capitalize}_" + + create( + noteable: noteable, + project: project, + author: author, + note: body, + system: true + ) + end + def create_new_commits_note(noteable, project, author, commits) commits_text = ActionController::Base.helpers.pluralize(commits.size, 'new commit') body = "Added #{commits_text}:\n\n" -- cgit v1.2.1 From 0632e85c82eeb76c9b61e497655c9cf2ef5dc262 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Fri, 20 Feb 2015 10:23:34 +0100 Subject: Fix commit comments on first line of diff not rendering in Merge Request Discussion view. --- app/models/note.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'app/models/note.rb') diff --git a/app/models/note.rb b/app/models/note.rb index ccd9783e7d4..e6c258ffbe9 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -409,19 +409,19 @@ class Note < ActiveRecord::Base prev_lines = [] diff_lines.each do |line| - if generate_line_code(line) != self.line_code - if line.type == "match" - prev_lines.clear - prev_match_line = line - else - prev_lines.push(line) - prev_lines.shift if prev_lines.length >= max_number_of_lines - end + if line.type == "match" + prev_lines.clear + prev_match_line = line else prev_lines << line - return prev_lines + + break if generate_line_code(line) == self.line_code + + prev_lines.shift if prev_lines.length >= max_number_of_lines end end + + prev_lines end def diff_lines -- cgit v1.2.1