diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-05-27 10:03:14 +0000 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2015-05-27 10:03:14 +0000 |
commit | 701c2e9a3b4b60642eba0ee00c3e11e1e43fb131 (patch) | |
tree | c5bca23181bc9320cab36619b2287f1cc405623d /app/services | |
parent | 3ed05b2191a7ede4734e2b7952f3810e5a1ee728 (diff) | |
parent | 3cb6a338466ca9b8e2a831cce306fc6d650231ed (diff) | |
download | gitlab-ce-701c2e9a3b4b60642eba0ee00c3e11e1e43fb131.tar.gz |
Merge branch 'rs-to_reference' into 'master'
Add to_reference method to referable models
Now there is a single source of information for which attribute a model uses to be referenced, and its special character.
See merge request !641
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/system_note_service.rb | 60 |
1 files changed, 18 insertions, 42 deletions
diff --git a/app/services/system_note_service.rb b/app/services/system_note_service.rb index 1909ae0d6f1..1527ae0486d 100644 --- a/app/services/system_note_service.rb +++ b/app/services/system_note_service.rb @@ -10,7 +10,7 @@ class SystemNoteService # author - User performing the change # new_commits - Array of Commits added since last push # existing_commits - Array of Commits added in a previous push - # oldrev - TODO (rspeicher): I have no idea what this actually does + # oldrev - Optional String SHA of a previous Commit # # See new_commit_summary and existing_commit_summary. # @@ -157,11 +157,11 @@ class SystemNoteService # # Example Note text: # - # "Mentioned in #1" + # "mentioned in #1" # - # "Mentioned in !2" + # "mentioned in !2" # - # "Mentioned in 54f7727c" + # "mentioned in 54f7727c" # # See cross_reference_note_content. # @@ -169,7 +169,7 @@ class SystemNoteService def self.cross_reference(noteable, mentioner, author) return if cross_reference_disallowed?(noteable, mentioner) - gfm_reference = mentioner_gfm_ref(noteable, mentioner) + gfm_reference = mentioner.gfm_reference(noteable.project) note_options = { project: noteable.project, @@ -200,12 +200,21 @@ class SystemNoteService # # Returns Boolean def self.cross_reference_disallowed?(noteable, mentioner) - return false unless MergeRequest === mentioner - return false unless Commit === noteable + return false unless mentioner.is_a?(MergeRequest) + return false unless noteable.is_a?(Commit) mentioner.commits.include?(noteable) end + # Check if a cross reference to a noteable from a mentioner already exists + # + # This method is used to prevent multiple notes being created for a mention + # when a issue is updated, for example. + # + # noteable - Noteable object being referenced + # mentioner - Mentionable object + # + # Returns Boolean def self.cross_reference_exists?(noteable, mentioner) # Initial scope should be system notes of this noteable type notes = Note.system.where(noteable_type: noteable.class) @@ -217,7 +226,7 @@ class SystemNoteService notes = notes.where(noteable_id: noteable.id) end - gfm_reference = mentioner_gfm_ref(noteable, mentioner, true) + gfm_reference = mentioner.gfm_reference(noteable.project) notes = notes.where(note: cross_reference_note_content(gfm_reference)) notes.count > 0 @@ -229,39 +238,6 @@ class SystemNoteService Note.create(args.merge(system: true)) end - # Prepend the mentioner's namespaced project path to the GFM reference for - # cross-project references. For same-project references, return the - # unmodified GFM reference. - def self.mentioner_gfm_ref(noteable, mentioner, cross_reference = false) - # FIXME (rspeicher): This was breaking things. - # if mentioner.is_a?(Commit) && cross_reference - # return mentioner.gfm_reference.sub('commit ', 'commit %') - # end - - full_gfm_reference(mentioner.project, noteable.project, mentioner) - end - - # Return the +mentioner+ GFM reference. If the mentioner and noteable - # projects are not the same, add the mentioning project's path to the - # returned value. - def self.full_gfm_reference(mentioning_project, noteable_project, mentioner) - if mentioning_project == noteable_project - mentioner.gfm_reference - else - if mentioner.is_a?(Commit) - mentioner.gfm_reference.sub( - /(commit )/, - "\\1#{mentioning_project.path_with_namespace}@" - ) - else - mentioner.gfm_reference.sub( - /(issue |merge request )/, - "\\1#{mentioning_project.path_with_namespace}" - ) - end - end - end - def self.cross_reference_note_prefix 'mentioned in ' end @@ -286,7 +262,7 @@ class SystemNoteService # # noteable - MergeRequest object # existing_commits - Array of existing Commit objects - # oldrev - Optional String SHA of ... TODO (rspeicher): I have no idea what this actually does. + # oldrev - Optional String SHA of a previous Commit # # Examples: # |