diff --git a/app/controllers/projects/commit_controller.rb b/app/controllers/projects/commit_controller.rb index 35df421e09de6d161cea226d99a60c5775c3ac79..78d42d695b68e7404a7e5b42f7dba8369b82286f 100644 --- a/app/controllers/projects/commit_controller.rb +++ b/app/controllers/projects/commit_controller.rb @@ -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 = { diff --git a/app/models/commit.rb b/app/models/commit.rb index d4e9ebacac60dc1fdb51ed55d01cd6ce4188e9c1..1985793c6003d26b4513160eb557829825249834 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 diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 9c9e27625070d0f9dc4637540ada6b8ad2fda5bb..e242cae8ea15951fb451433bc1fc572cd6512974 100644 --- a/app/models/merge_request.rb +++ b/app/models/merge_request.rb @@ -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) diff --git a/app/services/git_push_service.rb b/app/services/git_push_service.rb index 31e0167d24757280188fc3ceed87cab890b733b6..3affd6d6463e5cc21415f6dc353283aaddcb4865 100644 --- a/app/services/git_push_service.rb +++ b/app/services/git_push_service.rb @@ -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 diff --git a/app/services/notification_service.rb b/app/services/notification_service.rb index c7e45a2c2c705ab1addf21ef552c16f4d3f9405f..0d7ffbeebd9a68b045b77a8b62d6893fd51a266a 100644 --- a/app/services/notification_service.rb +++ b/app/services/notification_service.rb @@ -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 diff --git a/app/services/projects/participants_service.rb b/app/services/projects/participants_service.rb index 05106fa78982e9b3094c926b574809ac4dd800a3..b91590a1a9019af31e5149c7c64a712846457088 100644 --- a/app/services/projects/participants_service.rb +++ b/app/services/projects/participants_service.rb @@ -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 diff --git a/app/views/projects/commits/_commit.html.haml b/app/views/projects/commits/_commit.html.haml index 8e1aaa4d051c0da760105c4f819825ac0f4b6a0b..083fca9b6582fbeeff93ec3f9060e3dca1b678fe 100644 --- a/app/views/projects/commits/_commit.html.haml +++ b/app/views/projects/commits/_commit.html.haml @@ -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 diff --git a/lib/gitlab/note_data_builder.rb b/lib/gitlab/note_data_builder.rb index 0f2abd1b49c6d612e7699cbd2bf7c0c21cd8c5e2..ea6b0ee796dd86a8a01b2c3df3b24c6d501a268e 100644 --- a/lib/gitlab/note_data_builder.rb +++ b/lib/gitlab/note_data_builder.rb @@ -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 diff --git a/lib/gitlab/push_data_builder.rb b/lib/gitlab/push_data_builder.rb index f8da452e4c07cf676294419fa044679095020cbe..f44eb872122b3da1f9d1372d700a0a309d739fb9 100644 --- a/lib/gitlab/push_data_builder.rb +++ b/lib/gitlab/push_data_builder.rb @@ -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" diff --git a/spec/models/commit_spec.rb b/spec/models/commit_spec.rb index 9c37c036eae443b5701bf6dcd7288e72453a0482..ad2ac143d972c99e996d0e4475c79cde45423f1d 100644 --- a/spec/models/commit_spec.rb +++ b/spec/models/commit_spec.rb @@ -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