Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
3c5c658a
Commit
3c5c658a
authored
Sep 17, 2018
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use the correct email address when committing via a file service
parent
983bd38f
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
42 additions
and
3 deletions
+42
-3
app/services/files/base_service.rb
app/services/files/base_service.rb
+4
-2
spec/factories/users.rb
spec/factories/users.rb
+8
-0
spec/services/files/create_service_spec.rb
spec/services/files/create_service_spec.rb
+14
-1
spec/services/files/delete_service_spec.rb
spec/services/files/delete_service_spec.rb
+8
-0
spec/services/files/update_service_spec.rb
spec/services/files/update_service_spec.rb
+8
-0
No files found.
app/services/files/base_service.rb
View file @
3c5c658a
...
...
@@ -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
]
...
...
spec/factories/users.rb
View file @
3c5c658a
...
...
@@ -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'
...
...
spec/services/files/create_service_spec.rb
View file @
3c5c658a
...
...
@@ -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
spec/services/files/delete_service_spec.rb
View file @
3c5c658a
...
...
@@ -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
...
...
spec/services/files/update_service_spec.rb
View file @
3c5c658a
...
...
@@ -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
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment