summaryrefslogtreecommitdiff
path: root/app/models/commit.rb
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-04-24 12:46:39 +0000
committerDouwe Maan <douwe@gitlab.com>2015-04-24 12:46:39 +0000
commit6ae606d81f12d363e02c1dc0b5b9904d431a9a3a (patch)
tree02be1af7cca9197d076db2e926244c496fe72cd9 /app/models/commit.rb
parent9409f2a3b31178448c4f41802d2775ded9095800 (diff)
parent077a8ec270b58ed099d13447841d51b2df70541b (diff)
downloadgitlab-ce-6ae606d81f12d363e02c1dc0b5b9904d431a9a3a.tar.gz
Merge branch 'commit-project' into 'master'
Link cross-project cross-reference notes to correct project. - Fixes #1431: Don't crash when an MR from a fork has a cross-reference comment from the target project on of its commits. - Include commit comments in MR from a forked project. To accomplish this, the Commit model needs to know about its project. Adding this attribute also simplifies a bunch of other methods that deal with a note's target, that previously had to have special logic for when it belonged to a commit. See merge request !554
Diffstat (limited to 'app/models/commit.rb')
-rw-r--r--app/models/commit.rb34
1 files changed, 12 insertions, 22 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb
index 1cabc060c2a..be5a118bfec 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -3,8 +3,12 @@ class Commit
include StaticModel
extend ActiveModel::Naming
include Mentionable
+ include Participable
attr_mentionable :safe_message
+ participant :author, :committer, :notes, :mentioned_users
+
+ attr_accessor :project
# Safe amount of changes (files and lines) in one commit to render
# Used to prevent 500 error on huge commits by suppressing diff
@@ -18,12 +22,12 @@ class Commit
DIFF_HARD_LIMIT_LINES = 50000 unless defined?(DIFF_HARD_LIMIT_LINES)
class << self
- def decorate(commits)
+ def decorate(commits, project)
commits.map do |commit|
if commit.kind_of?(Commit)
commit
else
- self.new(commit)
+ self.new(commit, project)
end
end
end
@@ -41,10 +45,11 @@ class Commit
attr_accessor :raw
- def initialize(raw_commit)
+ def initialize(raw_commit, project)
raise "Nil as raw commit passed" unless raw_commit
@raw = raw_commit
+ @project = project
end
def id
@@ -100,7 +105,7 @@ class Commit
description.present?
end
- def hook_attrs(project)
+ def hook_attrs
path_with_namespace = project.path_with_namespace
{
@@ -117,7 +122,7 @@ class Commit
# Discover issues should be closed when this commit is pushed to a project's
# default branch.
- def closes_issues(project, current_user = self.committer)
+ def closes_issues(current_user = self.committer)
Gitlab::ClosingIssueExtractor.new(project, current_user).closed_by_message(safe_message)
end
@@ -134,22 +139,7 @@ class Commit
User.find_for_commit(committer_email, committer_name)
end
- def participants(project, current_user = nil)
- users = []
- users << author
- users << committer
-
- users.push *self.mentioned_users(current_user, project)
-
- notes(project).each do |note|
- users << note.author
- users.push *note.mentioned_users(current_user, project)
- end
-
- users.uniq
- end
-
- def notes(project)
+ def notes
project.notes.for_commit_id(self.id)
end
@@ -169,6 +159,6 @@ class Commit
end
def parents
- @parents ||= Commit.decorate(super)
+ @parents ||= Commit.decorate(super, project)
end
end