diff --git a/app/controllers/projects/commit_controller.rb b/app/controllers/projects/commit_controller.rb index 35df421e09d..78d42d695b6 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 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 diff --git a/app/models/merge_request.rb b/app/models/merge_request.rb index 9c9e2762507..e242cae8ea1 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 31e0167d247..3affd6d6463 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 c7e45a2c2c7..0d7ffbeebd9 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 05106fa7898..b91590a1a90 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 8e1aaa4d051..083fca9b658 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 0f2abd1b49c..ea6b0ee796d 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 f8da452e4c0..f44eb872122 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 9c37c036eae..ad2ac143d97 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