BigW Consortium Gitlab

Commit 27af24c1 by Douwe Maan

No longer needed to pass project argument to commit methods.

parent 8ed7ac9d
...@@ -10,11 +10,11 @@ class Projects::CommitController < Projects::ApplicationController ...@@ -10,11 +10,11 @@ class Projects::CommitController < Projects::ApplicationController
def show def show
return git_not_found! unless @commit return git_not_found! unless @commit
@line_notes = commit.notes(@project).inline @line_notes = commit.notes.inline
@diffs = @commit.diffs @diffs = @commit.diffs
@note = @project.build_commit_note(commit) @note = @project.build_commit_note(commit)
@notes_count = commit.notes(@project).count @notes_count = commit.notes.count
@notes = commit.notes(@project).not_inline.fresh @notes = commit.notes.not_inline.fresh
@noteable = @commit @noteable = @commit
@comments_allowed = @reply_allowed = true @comments_allowed = @reply_allowed = true
@comments_target = { @comments_target = {
......
...@@ -103,7 +103,7 @@ class Commit ...@@ -103,7 +103,7 @@ class Commit
description.present? description.present?
end end
def hook_attrs(project) def hook_attrs
path_with_namespace = project.path_with_namespace path_with_namespace = project.path_with_namespace
{ {
...@@ -120,7 +120,7 @@ class Commit ...@@ -120,7 +120,7 @@ class Commit
# Discover issues should be closed when this commit is pushed to a project's # Discover issues should be closed when this commit is pushed to a project's
# default branch. # 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) Gitlab::ClosingIssueExtractor.new(project, current_user).closed_by_message(safe_message)
end end
...@@ -137,22 +137,22 @@ class Commit ...@@ -137,22 +137,22 @@ class Commit
User.find_for_commit(committer_email, committer_name) User.find_for_commit(committer_email, committer_name)
end end
def participants(project, current_user = nil) def participants(current_user = nil)
users = [] users = []
users << author users << author
users << committer 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 << note.author
users.push *note.mentioned_users(current_user, project) users.push *note.mentioned_users(current_user)
end end
users.uniq users.uniq
end end
def notes(project) def notes
project.notes.for_commit_id(self.id) project.notes.for_commit_id(self.id)
end end
......
...@@ -242,7 +242,7 @@ class MergeRequest < ActiveRecord::Base ...@@ -242,7 +242,7 @@ class MergeRequest < ActiveRecord::Base
} }
unless last_commit.nil? unless last_commit.nil?
attrs.merge!(last_commit: last_commit.hook_attrs(source_project)) attrs.merge!(last_commit: last_commit.hook_attrs)
end end
attributes.merge!(attrs) attributes.merge!(attrs)
...@@ -259,7 +259,7 @@ class MergeRequest < ActiveRecord::Base ...@@ -259,7 +259,7 @@ class MergeRequest < ActiveRecord::Base
# Return the set of issues that will be closed if this merge request is accepted. # Return the set of issues that will be closed if this merge request is accepted.
def closes_issues(current_user = self.author) def closes_issues(current_user = self.author)
if target_branch == project.default_branch if target_branch == project.default_branch
issues = commits.flat_map { |c| c.closes_issues(project, current_user) } issues = commits.flat_map { |c| c.closes_issues(current_user) }
issues.push(*Gitlab::ClosingIssueExtractor.new(project, current_user). issues.push(*Gitlab::ClosingIssueExtractor.new(project, current_user).
closed_by_message(description)) closed_by_message(description))
issues.uniq.sort_by(&:id) issues.uniq.sort_by(&:id)
......
...@@ -70,7 +70,7 @@ class GitPushService ...@@ -70,7 +70,7 @@ class GitPushService
# Close issues if these commits were pushed to the project's default branch and the commit message matches the # Close issues if these commits were pushed to the project's default branch and the commit message matches the
# closing regex. Exclude any mentioned Issues from cross-referencing even if the commits are being pushed to # closing regex. Exclude any mentioned Issues from cross-referencing even if the commits are being pushed to
# a different branch. # a different branch.
issues_to_close = commit.closes_issues(project, user) issues_to_close = commit.closes_issues(user)
# Load commit author only if needed. # Load commit author only if needed.
# For push with 1k commits it prevents 900+ requests in database # For push with 1k commits it prevents 900+ requests in database
......
...@@ -129,9 +129,7 @@ class NotificationService ...@@ -129,9 +129,7 @@ class NotificationService
# Add all users participating in the thread (author, assignee, comment authors) # Add all users participating in the thread (author, assignee, comment authors)
participants = participants =
if target.is_a?(Commit) if target.respond_to?(:participants)
target.participants(note.project, note.author)
elsif target.respond_to?(:participants)
target.participants(note.author) target.participants(note.author)
else else
note.mentioned_users note.mentioned_users
......
...@@ -13,21 +13,19 @@ module Projects ...@@ -13,21 +13,19 @@ module Projects
end end
def participants_in(type, id) def participants_in(type, id)
users = target =
case type case type
when "Issue" when "Issue"
issue = project.issues.find_by_iid(id) project.issues.find_by_iid(id)
issue.participants(current_user) if issue
when "MergeRequest" when "MergeRequest"
merge_request = project.merge_requests.find_by_iid(id) project.merge_requests.find_by_iid(id)
merge_request.participants(current_user) if merge_request
when "Commit" when "Commit"
commit = project.commit(id) project.commit(id)
commit.participants(project, current_user) if commit
end end
return [] unless target
return [] unless users users = target.participants(current_user)
sorted(users) sorted(users)
end end
......
...@@ -12,7 +12,7 @@ ...@@ -12,7 +12,7 @@
- if @note_counts - if @note_counts
- note_count = @note_counts.fetch(commit.id, 0) - note_count = @note_counts.fetch(commit.id, 0)
- else - else
- notes = commit.notes(project) - notes = commit.notes
- note_count = notes.user.count - note_count = notes.user.count
- if note_count > 0 - if note_count > 0
......
...@@ -70,7 +70,7 @@ module Gitlab ...@@ -70,7 +70,7 @@ module Gitlab
def build_data_for_commit(project, user, note) def build_data_for_commit(project, user, note)
# commit_id is the SHA hash # commit_id is the SHA hash
commit = project.commit(note.commit_id) commit = project.commit(note.commit_id)
commit.hook_attrs(project) commit.hook_attrs
end end
end end
end end
......
...@@ -30,8 +30,7 @@ module Gitlab ...@@ -30,8 +30,7 @@ module Gitlab
# For performance purposes maximum 20 latest commits # For performance purposes maximum 20 latest commits
# will be passed as post receive hook data. # will be passed as post receive hook data.
commit_attrs = commits_limited.map do |commit| commit_attrs = commits_limited.map(&:hook_attrs)
commit.hook_attrs(project)
end end
type = Gitlab::Git.tag_ref?(ref) ? "tag_push" : "push" type = Gitlab::Git.tag_ref?(ref) ? "tag_push" : "push"
......
...@@ -58,13 +58,13 @@ eos ...@@ -58,13 +58,13 @@ eos
it 'detects issues that this commit is marked as closing' do it 'detects issues that this commit is marked as closing' do
commit.stub(safe_message: "Fixes ##{issue.iid}") commit.stub(safe_message: "Fixes ##{issue.iid}")
expect(commit.closes_issues(project)).to eq([issue]) expect(commit.closes_issues).to eq([issue])
end end
it 'does not detect issues from other projects' do it 'does not detect issues from other projects' do
ext_ref = "#{other_project.path_with_namespace}##{other_issue.iid}" ext_ref = "#{other_project.path_with_namespace}##{other_issue.iid}"
commit.stub(safe_message: "Fixes #{ext_ref}") commit.stub(safe_message: "Fixes #{ext_ref}")
expect(commit.closes_issues(project)).to be_empty expect(commit.closes_issues).to be_empty
end end
end end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment