From 84a1590252c63c710bceaa7a394799cdc5109505 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Tue, 21 Apr 2015 15:09:15 +0200 Subject: Let commit model know about its project. --- app/models/commit.rb | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'app/models/commit.rb') diff --git a/app/models/commit.rb b/app/models/commit.rb index 1cabc060c2a..d4e9ebacac6 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -6,6 +6,8 @@ class Commit attr_mentionable :safe_message + 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 +20,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 +43,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 @@ -169,6 +172,6 @@ class Commit end def parents - @parents ||= Commit.decorate(super) + @parents ||= Commit.decorate(super, project) end end -- cgit v1.2.1 From 27af24c1c951385bccd298c98044d57ff22ccd1c Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Tue, 21 Apr 2015 15:15:49 +0200 Subject: No longer needed to pass project argument to commit methods. --- app/models/commit.rb | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'app/models/commit.rb') diff --git a/app/models/commit.rb b/app/models/commit.rb index d4e9ebacac6..1985793c600 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -103,7 +103,7 @@ class Commit description.present? end - def hook_attrs(project) + def hook_attrs path_with_namespace = project.path_with_namespace { @@ -120,7 +120,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 @@ -137,22 +137,22 @@ class Commit User.find_for_commit(committer_email, committer_name) end - def participants(project, current_user = nil) + def participants(current_user = nil) users = [] users << author users << committer - users.push *self.mentioned_users(current_user, project) + users.push *self.mentioned_users(current_user) - notes(project).each do |note| + notes.each do |note| users << note.author - users.push *note.mentioned_users(current_user, project) + users.push *note.mentioned_users(current_user) end users.uniq end - def notes(project) + def notes project.notes.for_commit_id(self.id) end -- cgit v1.2.1 From e739eb036df23db4a03681190bf07ba0b8f1302c Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Tue, 21 Apr 2015 15:23:20 +0200 Subject: Move participants method to shared Participable concern. --- app/models/commit.rb | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) (limited to 'app/models/commit.rb') diff --git a/app/models/commit.rb b/app/models/commit.rb index 1985793c600..be5a118bfec 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -3,8 +3,10 @@ class Commit include StaticModel extend ActiveModel::Naming include Mentionable + include Participable attr_mentionable :safe_message + participant :author, :committer, :notes, :mentioned_users attr_accessor :project @@ -137,21 +139,6 @@ class Commit User.find_for_commit(committer_email, committer_name) end - def participants(current_user = nil) - users = [] - users << author - users << committer - - users.push *self.mentioned_users(current_user) - - notes.each do |note| - users << note.author - users.push *note.mentioned_users(current_user) - end - - users.uniq - end - def notes project.notes.for_commit_id(self.id) end -- cgit v1.2.1