Commit 27af24c1 authored by Douwe Maan's avatar Douwe Maan

No longer needed to pass project argument to commit methods.

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