Commit e078c1f1 authored by Douwe Maan's avatar Douwe Maan

Merge branch 'sh-fix-issue-9787' into 'master'

Only exclude commit authors in merge request approvers

Closes #9787

See merge request gitlab-org/gitlab-ee!9574
parents f99e69c4 4425026d
...@@ -20,8 +20,8 @@ class CommitCollection ...@@ -20,8 +20,8 @@ class CommitCollection
commits.each(&block) commits.each(&block)
end end
def committers def authors
emails = without_merge_commits.map(&:committer_email).uniq emails = without_merge_commits.map(&:author_email).uniq
User.by_any_email(emails) User.by_any_email(emails)
end end
......
...@@ -288,12 +288,12 @@ class MergeRequest < ActiveRecord::Base ...@@ -288,12 +288,12 @@ class MergeRequest < ActiveRecord::Base
work_in_progress?(title) ? title : "WIP: #{title}" work_in_progress?(title) ? title : "WIP: #{title}"
end end
def committers def commit_authors
@committers ||= commits.committers @commit_authors ||= commits.authors
end end
def authors def authors
User.from_union([committers, User.where(id: self.author_id)]) User.from_union([commit_authors, User.where(id: self.author_id)])
end end
# Verifies if title has changed not taking into account WIP prefix # Verifies if title has changed not taking into account WIP prefix
......
...@@ -52,8 +52,8 @@ A group can also be added as an approver. [In the future](https://gitlab.com/git ...@@ -52,8 +52,8 @@ A group can also be added as an approver. [In the future](https://gitlab.com/git
group approvers will be restricted. group approvers will be restricted.
If a user is added as an individual approver and is also part of a group approver, If a user is added as an individual approver and is also part of a group approver,
then that user is just counted once. The merge request author and users that have committed then that user is just counted once. The merge request author and users who have authored
to the merge request do not count as eligible approvers, commits in the merge request do not count as eligible approvers,
unless [self-approval] is explicitly enabled on the project settings. unless [self-approval] is explicitly enabled on the project settings.
### Implicit approvers ### Implicit approvers
......
...@@ -12,26 +12,26 @@ describe CommitCollection do ...@@ -12,26 +12,26 @@ describe CommitCollection do
end end
end end
describe '.committers' do describe '.authors' do
it 'returns a relation of users when users are found' do it 'returns a relation of users when users are found' do
user = create(:user, email: commit.committer_email.upcase) user = create(:user, email: commit.author_email.upcase)
collection = described_class.new(project, [commit]) collection = described_class.new(project, [commit])
expect(collection.committers).to contain_exactly(user) expect(collection.authors).to contain_exactly(user)
end end
it 'returns empty array when committers cannot be found' do it 'returns empty array when authors cannot be found' do
collection = described_class.new(project, [commit]) collection = described_class.new(project, [commit])
expect(collection.committers).to be_empty expect(collection.authors).to be_empty
end end
it 'excludes authors of merge commits' do it 'excludes authors of merge commits' do
commit = project.commit("60ecb67744cb56576c30214ff52294f8ce2def98") commit = project.commit("60ecb67744cb56576c30214ff52294f8ce2def98")
create(:user, email: commit.committer_email.upcase) create(:user, email: commit.author_email.upcase)
collection = described_class.new(project, [commit]) collection = described_class.new(project, [commit])
expect(collection.committers).to be_empty expect(collection.authors).to be_empty
end end
end end
......
...@@ -1024,23 +1024,23 @@ describe MergeRequest do ...@@ -1024,23 +1024,23 @@ describe MergeRequest do
end end
end end
describe '#committers' do describe '#commit_authors' do
it 'returns all the committers of every commit in the merge request' do it 'returns all the authors of every commit in the merge request' do
users = subject.commits.map(&:committer_email).uniq.map do |email| users = subject.commits.map(&:author_email).uniq.map do |email|
create(:user, email: email) create(:user, email: email)
end end
expect(subject.committers).to match_array(users) expect(subject.commit_authors).to match_array(users)
end end
it 'returns an empty array if no committer is associated with a user' do it 'returns an empty array if no author is associated with a user' do
expect(subject.committers).to be_empty expect(subject.commit_authors).to be_empty
end end
end end
describe '#authors' do describe '#authors' do
it 'returns a list with all the committers in the merge request and author' do it 'returns a list with all the commit authors in the merge request and author' do
users = subject.commits.map(&:committer_email).uniq.map do |email| users = subject.commits.map(&:author_email).uniq.map do |email|
create(:user, email: email) create(:user, email: email)
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