Commit 01ba92f9 authored by Robert Speicher's avatar Robert Speicher

Merge branch 'suggestion-author' into 'master'

Commit author for suggestions is note author

See merge request gitlab-org/gitlab!39940
parents 0fc28358 ac859468
......@@ -36,12 +36,22 @@ module Suggestions
.track_apply_suggestion_action(user: current_user)
end
def author
authors = suggestion_set.authors
return unless authors.one?
Gitlab::Git::User.from_gitlab(authors.first)
end
def multi_service
params = {
commit_message: commit_message,
branch_name: suggestion_set.branch,
start_branch: suggestion_set.branch,
actions: suggestion_set.actions
actions: suggestion_set.actions,
author_name: author&.name,
author_email: author&.email
}
::Files::MultiService.new(suggestion_set.project, current_user, params)
......
---
title: Commit author for suggestions is note author
merge_request: 39940
author:
type: added
......@@ -515,6 +515,9 @@ to your branch to address your reviewers' requests.
![A code change suggestion displayed, with the button to apply the batch of suggestions highlighted.](img/apply_batch_of_suggestions_v13_1.jpg "Apply a batch of suggestions")
WARNING:
Suggestions applied from multiple authors creates a commit authored by the user applying the suggestions.
## Start a thread by replying to a standard comment
> - [Introduced](https://gitlab.com/gitlab-org/gitlab-foss/-/issues/30299) in GitLab 11.9
......
......@@ -39,6 +39,10 @@ module Gitlab
@file_paths ||= suggestions.map(&:file_path).uniq
end
def authors
suggestions.map { |suggestion| suggestion.note.author }.uniq
end
private
def first_suggestion
......
......@@ -67,11 +67,13 @@ RSpec.describe Suggestions::ApplyService do
apply(suggestions)
commit = project.repository.commit
author = suggestions.first.note.author
expect(user.commit_email).not_to eq(user.email)
expect(commit.author_email).to eq(user.commit_email)
expect(commit.author_email).to eq(author.commit_email)
expect(commit.committer_email).to eq(user.commit_email)
expect(commit.author_name).to eq(user.name)
expect(commit.author_name).to eq(author.name)
expect(commit.committer_name).to eq(user.name)
end
it 'tracks apply suggestion event' do
......@@ -319,6 +321,73 @@ RSpec.describe Suggestions::ApplyService do
end
end
context 'single suggestion' do
let(:author) { suggestions.first.note.author }
let(:commit) { project.repository.commit }
context 'author of suggestion applies suggestion' do
before do
suggestion.note.update!(author_id: user.id)
apply(suggestions)
end
it 'created commit by same author and committer' do
expect(user.commit_email).to eq(author.commit_email)
expect(author).to eq(user)
expect(commit.author_email).to eq(author.commit_email)
expect(commit.committer_email).to eq(user.commit_email)
expect(commit.author_name).to eq(author.name)
expect(commit.committer_name).to eq(user.name)
end
end
context 'another user applies suggestion' do
before do
apply(suggestions)
end
it 'created commit has authors info and commiters info' do
expect(user.commit_email).not_to eq(user.email)
expect(author).not_to eq(user)
expect(commit.author_email).to eq(author.commit_email)
expect(commit.committer_email).to eq(user.commit_email)
expect(commit.author_name).to eq(author.name)
expect(commit.committer_name).to eq(user.name)
end
end
end
context 'multiple suggestions' do
let(:author_emails) { suggestions.map {|s| s.note.author.commit_email } }
let(:first_author) { suggestion.note.author }
let(:commit) { project.repository.commit }
context 'when all the same author' do
before do
apply(suggestions)
end
it 'uses first authors information' do
expect(author_emails).to include(first_author.commit_email).exactly(3)
expect(commit.author_email).to eq(first_author.commit_email)
end
end
context 'when all different authors' do
before do
suggestion2.note.update!(author_id: create(:user).id)
suggestion3.note.update!(author_id: create(:user).id)
apply(suggestions)
end
it 'uses committers information' do
expect(commit.author_email).to eq(user.commit_email)
expect(commit.committer_email).to eq(user.commit_email)
end
end
end
context 'multiple suggestions applied sequentially' do
def apply_suggestion(suggestion)
suggestion.reload
......
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