From c0faf91ff23815404a95cf4510b43dcf5e331c4f Mon Sep 17 00:00:00 2001 From: Robert Speicher Date: Sat, 2 May 2015 23:11:21 -0400 Subject: 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. --- app/models/commit.rb | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'app/models/commit.rb') 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 -- cgit v1.2.1