diff options
author | micael.bergeron <micaelbergeron@gmail.com> | 2017-11-16 09:23:32 -0500 |
---|---|---|
committer | micael.bergeron <micaelbergeron@gmail.com> | 2017-11-16 09:23:32 -0500 |
commit | 71b2cc1dd8497959306601eece8ebbf008562d07 (patch) | |
tree | 0d77ad873a4f3141989bce09756e7fdc201b03df | |
parent | 160324d08b3756f6c5fbf79b23f09d66e5a19d9e (diff) | |
download | gitlab-ce-71b2cc1dd8497959306601eece8ebbf008562d07.tar.gz |
reverting to the simpler approach
-rw-r--r-- | app/models/commit.rb | 2 | ||||
-rw-r--r-- | app/models/note.rb | 14 | ||||
-rw-r--r-- | app/models/system_note_metadata.rb | 10 | ||||
-rw-r--r-- | app/services/system_note_service.rb | 4 | ||||
-rw-r--r-- | spec/models/commit_spec.rb | 23 |
5 files changed, 28 insertions, 25 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb index b5411b2bf75..6dba154a6ea 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -26,7 +26,7 @@ class Commit DIFF_HARD_LIMIT_LINES = 50000 MIN_SHA_LENGTH = 7 - COMMIT_SHA_PATTERN = /(?<!\s[~#!@:])\h{#{MIN_SHA_LENGTH},40}/.freeze + COMMIT_SHA_PATTERN = /\h{#{MIN_SHA_LENGTH},40}/.freeze def banzai_render_context(field) context = { pipeline: :single_line, project: self.project } diff --git a/app/models/note.rb b/app/models/note.rb index f9676361072..4bbb54ba9bf 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -169,7 +169,13 @@ class Note < ActiveRecord::Base end def cross_reference? - system? && matches_cross_reference_regex? + return unless system? + + if force_cross_reference_regex_check? + matches_cross_reference_regex? + else + SystemNoteService.cross_reference?(note) + end end def diff_note? @@ -382,4 +388,10 @@ class Note < ActiveRecord::Base def set_discussion_id self.discussion_id ||= discussion_class.discussion_id(self) end + + def force_cross_reference_regex_check? + return unless system? + + SystemNoteMetadata::TYPES_WITH_CROSS_REFERENCES.include?(system_note_metadata&.action) + end end diff --git a/app/models/system_note_metadata.rb b/app/models/system_note_metadata.rb index 1f9f8d7286b..4065c1594c3 100644 --- a/app/models/system_note_metadata.rb +++ b/app/models/system_note_metadata.rb @@ -1,4 +1,14 @@ class SystemNoteMetadata < ActiveRecord::Base + # These notes's action text might contain a reference that is external. + # We should always force a deep validation upon references that are found + # in this note type. + # Other notes can always be safely shown as all its references are + # in the same project (i.e. with the same permissions) + TYPES_WITH_CROSS_REFERENCES = %w[ + cross_reference + milestone + ] + ICON_TYPES = %w[ commit description merge confidential visible label assignee cross_reference title time_tracking branch milestone discussion task moved diff --git a/app/services/system_note_service.rb b/app/services/system_note_service.rb index e946218824c..fe71a405565 100644 --- a/app/services/system_note_service.rb +++ b/app/services/system_note_service.rb @@ -583,6 +583,10 @@ module SystemNoteService create_note(NoteSummary.new(issuable, issuable.project, author, body, action: action)) end + def cross_reference?(note_text) + note_text =~ /\A#{cross_reference_note_prefix}/i + end + private def notes_for_mentioner(mentioner, noteable, notes) diff --git a/spec/models/commit_spec.rb b/spec/models/commit_spec.rb index 3994eaba5d9..e3cfa149e3a 100644 --- a/spec/models/commit_spec.rb +++ b/spec/models/commit_spec.rb @@ -468,27 +468,4 @@ eos expect(described_class.valid_hash?('a' * 41)).to be false end end - - describe '.reference_pattern' do - where(:ref, :matches?) do - sha = Digest::SHA1.hexdigest 'thisisacommitid' - - [ - [sha.first(Commit::MIN_SHA_LENGTH - 1), false], - [sha.first(Commit::MIN_SHA_LENGTH), true], - [sha, true], - ['~' << sha, false], # labels - ['!' << sha, false], # merge_request - [':' << sha, false], # emoji - ['#' << sha, false], # issue - ['@' << sha, false], # user - ] - end - - with_them do - it "should match only on commit references" do - expect(Commit.reference_pattern.match(ref).present?).to eq(matches?) - end - end - end end |