Commit 3c5c658a authored by Nick Thomas's avatar Nick Thomas

Use the correct email address when committing via a file service

parent 983bd38f
......@@ -7,8 +7,10 @@ module Files
def initialize(*args)
super
@author_email = params[:author_email] || current_user&.email
@author_name = params[:author_name] || current_user&.name
git_user = Gitlab::Git::User.from_gitlab(current_user) if current_user.present?
@author_email = params[:author_email] || git_user&.email
@author_name = params[:author_name] || git_user&.name
@commit_message = params[:commit_message]
@last_commit_sha = params[:last_commit_sha]
......
......@@ -58,6 +58,14 @@ FactoryBot.define do
project_view :readme
end
trait :commit_email do
after(:create) do |user, evaluator|
additional = create(:email, :confirmed, user: user, email: "commit-#{user.email}")
user.update!(commit_email: additional.email)
end
end
factory :omniauth_user do
transient do
extern_uid '123456'
......
......@@ -3,7 +3,7 @@ require "spec_helper"
describe Files::CreateService do
let(:project) { create(:project, :repository) }
let(:repository) { project.repository }
let(:user) { create(:user) }
let(:user) { create(:user, :commit_email) }
let(:file_content) { 'Test file content' }
let(:branch_name) { project.default_branch }
let(:start_branch) { branch_name }
......@@ -20,6 +20,8 @@ describe Files::CreateService do
}
end
let(:commit) { repository.head_commit }
subject { described_class.new(project, user, commit_params) }
before do
......@@ -75,4 +77,15 @@ describe Files::CreateService do
end
end
end
context 'commit attribute' do
let(:file_path) { 'test-commit-attributes.txt' }
it 'uses the commit email' do
subject.execute
expect(commit.author_email).to eq(user.commit_email)
expect(commit.committer_email).to eq(user.commit_email)
end
end
end
......@@ -8,6 +8,7 @@ describe Files::DeleteService do
let(:file_path) { 'files/ruby/popen.rb' }
let(:branch_name) { project.default_branch }
let(:last_commit_sha) { nil }
let(:commit) { project.repository.head_commit }
let(:commit_params) do
{
......@@ -34,6 +35,13 @@ describe Files::DeleteService do
expect(blob).to be_nil
end
it 'uses the commit email' do
subject.execute
expect(commit.author_email).to eq(user.commit_email)
expect(commit.committer_email).to eq(user.commit_email)
end
end
before do
......
......@@ -9,6 +9,7 @@ describe Files::UpdateService do
let(:new_contents) { 'New Content' }
let(:branch_name) { project.default_branch }
let(:last_commit_sha) { nil }
let(:commit) { project.repository.commit }
let(:commit_params) do
{
......@@ -54,6 +55,13 @@ describe Files::UpdateService do
expect(results.data).to eq(new_contents)
end
it 'uses the commit email' do
subject.execute
expect(commit.author_email).to eq(user.commit_email)
expect(commit.committer_email).to eq(user.commit_email)
end
end
context "when the last_commit_sha is not supplied" do
......
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