Commit a2a00a5e authored by Douwe Maan's avatar Douwe Maan

Merge branch '51564-fix-commit-email-usage' into 'master'

Respect the user commit email in more places

Closes #51564

See merge request gitlab-org/gitlab-ce!21773
parents 139a14b6 5a883915
...@@ -184,11 +184,12 @@ class ProjectWiki ...@@ -184,11 +184,12 @@ class ProjectWiki
def commit_details(action, message = nil, title = nil) def commit_details(action, message = nil, title = nil)
commit_message = message || default_message(action, title) commit_message = message || default_message(action, title)
git_user = Gitlab::Git::User.from_gitlab(@user)
Gitlab::Git::Wiki::CommitDetails.new(@user.id, Gitlab::Git::Wiki::CommitDetails.new(@user.id,
@user.username, git_user.username,
@user.name, git_user.name,
@user.email, git_user.email,
commit_message) commit_message)
end end
......
...@@ -7,8 +7,10 @@ module Files ...@@ -7,8 +7,10 @@ module Files
def initialize(*args) def initialize(*args)
super super
@author_email = params[:author_email] || current_user&.email git_user = Gitlab::Git::User.from_gitlab(current_user) if current_user.present?
@author_name = params[:author_name] || current_user&.name
@author_email = params[:author_email] || git_user&.email
@author_name = params[:author_name] || git_user&.name
@commit_message = params[:commit_message] @commit_message = params[:commit_message]
@last_commit_sha = params[:last_commit_sha] @last_commit_sha = params[:last_commit_sha]
......
---
title: Respect the user commit email in more places
merge_request: 21773
author:
type: fixed
...@@ -591,10 +591,6 @@ module Gitlab ...@@ -591,10 +591,6 @@ module Gitlab
end end
end end
def user_to_committer(user)
Gitlab::Git.committer_hash(email: user.email, name: user.name)
end
# Delete the specified branch from the repository # Delete the specified branch from the repository
def delete_branch(branch_name) def delete_branch(branch_name)
wrapped_gitaly_errors do wrapped_gitaly_errors do
......
...@@ -58,6 +58,14 @@ FactoryBot.define do ...@@ -58,6 +58,14 @@ FactoryBot.define do
project_view :readme project_view :readme
end 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 factory :omniauth_user do
transient do transient do
extern_uid '123456' extern_uid '123456'
......
...@@ -2,12 +2,13 @@ ...@@ -2,12 +2,13 @@
require "spec_helper" require "spec_helper"
describe ProjectWiki do describe ProjectWiki do
let(:project) { create(:project, :wiki_repo) } let(:user) { create(:user, :commit_email) }
let(:project) { create(:project, :wiki_repo, namespace: user.namespace) }
let(:repository) { project.repository } let(:repository) { project.repository }
let(:user) { project.owner }
let(:gitlab_shell) { Gitlab::Shell.new } let(:gitlab_shell) { Gitlab::Shell.new }
let(:project_wiki) { described_class.new(project, user) } let(:project_wiki) { described_class.new(project, user) }
let(:raw_repository) { Gitlab::Git::Repository.new(project.repository_storage, subject.disk_path + '.git', 'foo') } let(:raw_repository) { Gitlab::Git::Repository.new(project.repository_storage, subject.disk_path + '.git', 'foo') }
let(:commit) { project_wiki.repository.head_commit }
subject { project_wiki } subject { project_wiki }
...@@ -276,6 +277,14 @@ describe ProjectWiki do ...@@ -276,6 +277,14 @@ describe ProjectWiki do
expect(subject.pages.first.page.version.message).to eq("commit message") expect(subject.pages.first.page.version.message).to eq("commit message")
end end
it 'sets the correct commit email' do
subject.create_page('test page', 'content')
expect(user.commit_email).not_to eq(user.email)
expect(commit.author_email).to eq(user.commit_email)
expect(commit.committer_email).to eq(user.commit_email)
end
it 'updates project activity' do it 'updates project activity' do
subject.create_page('Test Page', 'This is content') subject.create_page('Test Page', 'This is content')
...@@ -320,6 +329,12 @@ describe ProjectWiki do ...@@ -320,6 +329,12 @@ describe ProjectWiki do
expect(@page.version.message).to eq("updated page") expect(@page.version.message).to eq("updated page")
end end
it 'sets the correct commit email' do
expect(user.commit_email).not_to eq(user.email)
expect(commit.author_email).to eq(user.commit_email)
expect(commit.committer_email).to eq(user.commit_email)
end
it 'updates project activity' do it 'updates project activity' do
subject.update_page( subject.update_page(
@gitlab_git_wiki_page, @gitlab_git_wiki_page,
...@@ -347,6 +362,14 @@ describe ProjectWiki do ...@@ -347,6 +362,14 @@ describe ProjectWiki do
expect(subject.pages.count).to eq(0) expect(subject.pages.count).to eq(0)
end end
it 'sets the correct commit email' do
subject.delete_page(@page)
expect(user.commit_email).not_to eq(user.email)
expect(commit.author_email).to eq(user.commit_email)
expect(commit.committer_email).to eq(user.commit_email)
end
it 'updates project activity' do it 'updates project activity' do
subject.delete_page(@page) subject.delete_page(@page)
...@@ -420,7 +443,7 @@ describe ProjectWiki do ...@@ -420,7 +443,7 @@ describe ProjectWiki do
end end
def commit_details def commit_details
Gitlab::Git::Wiki::CommitDetails.new(user.id, user.username, user.name, user.email, "test commit") Gitlab::Git::Wiki::CommitDetails.new(user.id, user.username, user.name, user.commit_email, "test commit")
end end
def create_page(name, content) def create_page(name, content)
......
...@@ -3,7 +3,7 @@ require "spec_helper" ...@@ -3,7 +3,7 @@ require "spec_helper"
describe Files::CreateService do describe Files::CreateService do
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:repository) { project.repository } let(:repository) { project.repository }
let(:user) { create(:user) } let(:user) { create(:user, :commit_email) }
let(:file_content) { 'Test file content' } let(:file_content) { 'Test file content' }
let(:branch_name) { project.default_branch } let(:branch_name) { project.default_branch }
let(:start_branch) { branch_name } let(:start_branch) { branch_name }
...@@ -20,6 +20,8 @@ describe Files::CreateService do ...@@ -20,6 +20,8 @@ describe Files::CreateService do
} }
end end
let(:commit) { repository.head_commit }
subject { described_class.new(project, user, commit_params) } subject { described_class.new(project, user, commit_params) }
before do before do
...@@ -75,4 +77,16 @@ describe Files::CreateService do ...@@ -75,4 +77,16 @@ describe Files::CreateService do
end end
end end
end end
context 'commit attribute' do
let(:file_path) { 'test-commit-attributes.txt' }
it 'uses the commit email' do
subject.execute
expect(user.commit_email).not_to eq(user.email)
expect(commit.author_email).to eq(user.commit_email)
expect(commit.committer_email).to eq(user.commit_email)
end
end
end end
...@@ -4,10 +4,11 @@ describe Files::DeleteService do ...@@ -4,10 +4,11 @@ describe Files::DeleteService do
subject { described_class.new(project, user, commit_params) } subject { described_class.new(project, user, commit_params) }
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:user) { create(:user) } let(:user) { create(:user, :commit_email) }
let(:file_path) { 'files/ruby/popen.rb' } let(:file_path) { 'files/ruby/popen.rb' }
let(:branch_name) { project.default_branch } let(:branch_name) { project.default_branch }
let(:last_commit_sha) { nil } let(:last_commit_sha) { nil }
let(:commit) { project.repository.head_commit }
let(:commit_params) do let(:commit_params) do
{ {
...@@ -34,6 +35,14 @@ describe Files::DeleteService do ...@@ -34,6 +35,14 @@ describe Files::DeleteService do
expect(blob).to be_nil expect(blob).to be_nil
end end
it 'uses the commit email' do
subject.execute
expect(user.commit_email).not_to eq(user.email)
expect(commit.author_email).to eq(user.commit_email)
expect(commit.committer_email).to eq(user.commit_email)
end
end end
before do before do
......
...@@ -4,11 +4,12 @@ describe Files::UpdateService do ...@@ -4,11 +4,12 @@ describe Files::UpdateService do
subject { described_class.new(project, user, commit_params) } subject { described_class.new(project, user, commit_params) }
let(:project) { create(:project, :repository) } let(:project) { create(:project, :repository) }
let(:user) { create(:user) } let(:user) { create(:user, :commit_email) }
let(:file_path) { 'files/ruby/popen.rb' } let(:file_path) { 'files/ruby/popen.rb' }
let(:new_contents) { 'New Content' } let(:new_contents) { 'New Content' }
let(:branch_name) { project.default_branch } let(:branch_name) { project.default_branch }
let(:last_commit_sha) { nil } let(:last_commit_sha) { nil }
let(:commit) { project.repository.commit }
let(:commit_params) do let(:commit_params) do
{ {
...@@ -54,6 +55,14 @@ describe Files::UpdateService do ...@@ -54,6 +55,14 @@ describe Files::UpdateService do
expect(results.data).to eq(new_contents) expect(results.data).to eq(new_contents)
end end
it 'uses the commit email' do
subject.execute
expect(user.commit_email).not_to eq(user.email)
expect(commit.author_email).to eq(user.commit_email)
expect(commit.committer_email).to eq(user.commit_email)
end
end end
context "when the last_commit_sha is not supplied" do 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