summaryrefslogtreecommitdiff
path: root/app/models/commit.rb
diff options
context:
space:
mode:
authorRobert Speicher <rspeicher@gmail.com>2015-05-02 23:11:21 -0400
committerRobert Speicher <rspeicher@gmail.com>2015-05-26 15:48:30 -0400
commitc0faf91ff23815404a95cf4510b43dcf5e331c4f (patch)
tree81769f125569dd6ea012920544ada1e8666ba4e5 /app/models/commit.rb
parentb06dc74d611192744d34acda944d7ed9e554342a (diff)
downloadgitlab-ce-c0faf91ff23815404a95cf4510b43dcf5e331c4f.tar.gz
Add `to_reference` for models that support references
Now there is a single source of information for which attribute a model uses to be referenced, and its special character.
Diffstat (limited to 'app/models/commit.rb')
-rw-r--r--app/models/commit.rb16
1 files changed, 13 insertions, 3 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb
index 5dea7dda513..3cc8d11a4aa 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -1,9 +1,11 @@
class Commit
- include ActiveModel::Conversion
- include StaticModel
extend ActiveModel::Naming
+
+ include ActiveModel::Conversion
include Mentionable
include Participable
+ include Referable
+ include StaticModel
attr_mentionable :safe_message
participant :author, :committer, :notes, :mentioned_users
@@ -60,6 +62,14 @@ class Commit
(self.class === other) && (raw == other.raw)
end
+ def to_reference(from_project = nil)
+ if cross_project_reference?(from_project)
+ "#{project.to_reference}@#{id}"
+ else
+ id
+ end
+ end
+
def diff_line_count
@diff_line_count ||= Commit::diff_line_count(self.diffs)
@diff_line_count
@@ -132,7 +142,7 @@ class Commit
# Mentionable override.
def gfm_reference
- "commit #{id}"
+ "commit #{to_reference}"
end
def author