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
0
Merge Requests
0
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
Tatuya Kamada
gitlab-ce
Commits
e0c186c3
Commit
e0c186c3
authored
Feb 25, 2015
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add option to send EmailsOnPush from committer email if domain matches.
See #1809.
parent
0e7d1fd4
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
51 additions
and
10 deletions
+51
-10
app/controllers/admin/services_controller.rb
app/controllers/admin/services_controller.rb
+2
-1
app/controllers/projects/services_controller.rb
app/controllers/projects/services_controller.rb
+2
-1
app/mailers/emails/projects.rb
app/mailers/emails/projects.rb
+3
-3
app/mailers/notify.rb
app/mailers/notify.rb
+6
-1
app/models/project_services/emails_on_push_service.rb
app/models/project_services/emails_on_push_service.rb
+7
-1
app/workers/emails_on_push_worker.rb
app/workers/emails_on_push_worker.rb
+2
-2
spec/mailers/notify_spec.rb
spec/mailers/notify_spec.rb
+29
-1
No files found.
app/controllers/admin/services_controller.rb
View file @
e0c186c3
...
@@ -45,7 +45,8 @@ class Admin::ServicesController < Admin::ApplicationController
...
@@ -45,7 +45,8 @@ class Admin::ServicesController < Admin::ApplicationController
:room
,
:recipients
,
:project_url
,
:webhook
,
:room
,
:recipients
,
:project_url
,
:webhook
,
:user_key
,
:device
,
:priority
,
:sound
,
:bamboo_url
,
:username
,
:password
,
:user_key
,
:device
,
:priority
,
:sound
,
:bamboo_url
,
:username
,
:password
,
:build_key
,
:server
,
:teamcity_url
,
:build_type
,
:build_key
,
:server
,
:teamcity_url
,
:build_type
,
:description
,
:issues_url
,
:new_issue_url
,
:restrict_to_branch
:description
,
:issues_url
,
:new_issue_url
,
:restrict_to_branch
,
:send_from_committer_email
])
])
end
end
end
end
app/controllers/projects/services_controller.rb
View file @
e0c186c3
...
@@ -50,7 +50,8 @@ class Projects::ServicesController < Projects::ApplicationController
...
@@ -50,7 +50,8 @@ class Projects::ServicesController < Projects::ApplicationController
:room
,
:recipients
,
:project_url
,
:webhook
,
:room
,
:recipients
,
:project_url
,
:webhook
,
:user_key
,
:device
,
:priority
,
:sound
,
:bamboo_url
,
:username
,
:password
,
:user_key
,
:device
,
:priority
,
:sound
,
:bamboo_url
,
:username
,
:password
,
:build_key
,
:server
,
:teamcity_url
,
:build_type
,
:build_key
,
:server
,
:teamcity_url
,
:build_type
,
:description
,
:issues_url
,
:new_issue_url
,
:restrict_to_branch
:description
,
:issues_url
,
:new_issue_url
,
:restrict_to_branch
,
:send_from_committer_email
)
)
end
end
end
end
app/mailers/emails/projects.rb
View file @
e0c186c3
...
@@ -16,13 +16,13 @@ module Emails
...
@@ -16,13 +16,13 @@ module Emails
subject:
subject
(
"Project was moved"
))
subject:
subject
(
"Project was moved"
))
end
end
def
repository_push_email
(
project_id
,
recipient
,
author_id
,
branch
,
compare
)
def
repository_push_email
(
project_id
,
recipient
,
author_id
,
branch
,
compare
,
send_from_committer_email
=
false
)
@project
=
Project
.
find
(
project_id
)
@project
=
Project
.
find
(
project_id
)
@author
=
User
.
find
(
author_id
)
@author
=
User
.
find
(
author_id
)
@compare
=
compare
@compare
=
compare
@commits
=
Commit
.
decorate
(
compare
.
commits
)
@commits
=
Commit
.
decorate
(
compare
.
commits
)
@diffs
=
compare
.
diffs
@diffs
=
compare
.
diffs
@branch
=
branch
@branch
=
branch
.
gsub
(
"refs/heads/"
,
""
)
@subject
=
"[
#{
@project
.
path_with_namespace
}
][
#{
@branch
}
] "
@subject
=
"[
#{
@project
.
path_with_namespace
}
][
#{
@branch
}
] "
...
@@ -40,7 +40,7 @@ module Emails
...
@@ -40,7 +40,7 @@ module Emails
@disable_footer
=
true
@disable_footer
=
true
mail
(
from:
sender
(
author_id
),
mail
(
from:
sender
(
author_id
,
send_from_committer_email
),
to:
recipient
,
to:
recipient
,
subject:
@subject
)
subject:
@subject
)
end
end
...
...
app/mailers/notify.rb
View file @
e0c186c3
...
@@ -45,10 +45,15 @@ class Notify < ActionMailer::Base
...
@@ -45,10 +45,15 @@ class Notify < ActionMailer::Base
# Return an email address that displays the name of the sender.
# Return an email address that displays the name of the sender.
# Only the displayed name changes; the actual email address is always the same.
# Only the displayed name changes; the actual email address is always the same.
def
sender
(
sender_id
)
def
sender
(
sender_id
,
send_from_user_email
=
false
)
if
sender
=
User
.
find
(
sender_id
)
if
sender
=
User
.
find
(
sender_id
)
address
=
default_sender_address
address
=
default_sender_address
address
.
display_name
=
sender
.
name
address
.
display_name
=
sender
.
name
if
send_from_user_email
&&
sender
.
email
.
end_with?
(
"@
#{
Gitlab
.
config
.
gitlab
.
host
}
"
)
address
.
address
=
sender
.
email
end
address
.
format
address
.
format
end
end
end
end
...
...
app/models/project_services/emails_on_push_service.rb
View file @
e0c186c3
...
@@ -14,6 +14,7 @@
...
@@ -14,6 +14,7 @@
#
#
class
EmailsOnPushService
<
Service
class
EmailsOnPushService
<
Service
prop_accessor
:send_from_committer_email
prop_accessor
:recipients
prop_accessor
:recipients
validates
:recipients
,
presence:
true
,
if: :activated?
validates
:recipients
,
presence:
true
,
if: :activated?
...
@@ -29,12 +30,17 @@ class EmailsOnPushService < Service
...
@@ -29,12 +30,17 @@ class EmailsOnPushService < Service
'emails_on_push'
'emails_on_push'
end
end
def
send_from_committer_email?
self
.
send_from_committer_email
==
"1"
end
def
execute
(
push_data
)
def
execute
(
push_data
)
EmailsOnPushWorker
.
perform_async
(
project_id
,
recipients
,
push_data
)
EmailsOnPushWorker
.
perform_async
(
project_id
,
recipients
,
push_data
,
self
.
send_from_committer_email?
)
end
end
def
fields
def
fields
[
[
{
type:
'checkbox'
,
name:
'send_from_committer_email'
,
title:
"Send from committer email if domain matches"
},
{
type:
'textarea'
,
name:
'recipients'
,
placeholder:
'Emails separated by whitespace'
},
{
type:
'textarea'
,
name:
'recipients'
,
placeholder:
'Emails separated by whitespace'
},
]
]
end
end
...
...
app/workers/emails_on_push_worker.rb
View file @
e0c186c3
class
EmailsOnPushWorker
class
EmailsOnPushWorker
include
Sidekiq
::
Worker
include
Sidekiq
::
Worker
def
perform
(
project_id
,
recipients
,
push_data
)
def
perform
(
project_id
,
recipients
,
push_data
,
send_from_committer_email
=
false
)
project
=
Project
.
find
(
project_id
)
project
=
Project
.
find
(
project_id
)
before_sha
=
push_data
[
"before"
]
before_sha
=
push_data
[
"before"
]
after_sha
=
push_data
[
"after"
]
after_sha
=
push_data
[
"after"
]
...
@@ -19,7 +19,7 @@ class EmailsOnPushWorker
...
@@ -19,7 +19,7 @@ class EmailsOnPushWorker
return
false
unless
compare
&&
compare
.
commits
.
present?
return
false
unless
compare
&&
compare
.
commits
.
present?
recipients
.
split
(
" "
).
each
do
|
recipient
|
recipients
.
split
(
" "
).
each
do
|
recipient
|
Notify
.
repository_push_email
(
project_id
,
recipient
,
author_id
,
branch
,
compare
).
deliver
Notify
.
repository_push_email
(
project_id
,
recipient
,
author_id
,
branch
,
compare
,
send_from_committer_email
).
deliver
end
end
ensure
ensure
compare
=
nil
compare
=
nil
...
...
spec/mailers/notify_spec.rb
View file @
e0c186c3
...
@@ -569,8 +569,9 @@ describe Notify do
...
@@ -569,8 +569,9 @@ describe Notify do
let
(
:compare
)
{
Gitlab
::
Git
::
Compare
.
new
(
project
.
repository
.
raw_repository
,
sample_image_commit
.
id
,
sample_commit
.
id
)
}
let
(
:compare
)
{
Gitlab
::
Git
::
Compare
.
new
(
project
.
repository
.
raw_repository
,
sample_image_commit
.
id
,
sample_commit
.
id
)
}
let
(
:commits
)
{
Commit
.
decorate
(
compare
.
commits
)
}
let
(
:commits
)
{
Commit
.
decorate
(
compare
.
commits
)
}
let
(
:diff_path
)
{
namespace_project_compare_path
(
project
.
namespace
,
project
,
from:
commits
.
first
,
to:
commits
.
last
)
}
let
(
:diff_path
)
{
namespace_project_compare_path
(
project
.
namespace
,
project
,
from:
commits
.
first
,
to:
commits
.
last
)
}
let
(
:send_from_committer_email
)
{
false
}
subject
{
Notify
.
repository_push_email
(
project
.
id
,
'devs@company.name'
,
user
.
id
,
'master'
,
compare
)
}
subject
{
Notify
.
repository_push_email
(
project
.
id
,
'devs@company.name'
,
user
.
id
,
'master'
,
compare
,
send_from_committer_email
)
}
it
'is sent as the author'
do
it
'is sent as the author'
do
sender
=
subject
.
header
[
:from
].
addrs
[
0
]
sender
=
subject
.
header
[
:from
].
addrs
[
0
]
...
@@ -601,6 +602,33 @@ describe Notify do
...
@@ -601,6 +602,33 @@ describe Notify do
it
'doesn not contain the misleading footer'
do
it
'doesn not contain the misleading footer'
do
is_expected
.
not_to
have_body_text
/you are a member of/
is_expected
.
not_to
have_body_text
/you are a member of/
end
end
context
"when set to send from committer email if domain matches"
do
let
(
:send_from_committer_email
)
{
true
}
context
"when the committer email domain matches"
do
before
do
allow
(
Gitlab
.
config
.
gitlab
).
to
receive
(
:host
).
and_return
(
"gitlab.dev"
)
user
.
update_attribute
(
:email
,
"user@
#{
Gitlab
.
config
.
gitlab
.
host
}
"
)
user
.
confirm!
end
it
"is sent from the committer email"
do
sender
=
subject
.
header
[
:from
].
addrs
[
0
]
expect
(
sender
.
address
).
to
eq
(
user
.
email
)
end
end
context
"when the committer email doesn't match"
do
it
"is sent from the default email"
do
sender
=
subject
.
header
[
:from
].
addrs
[
0
]
expect
(
sender
.
address
).
to
eq
(
gitlab_sender
)
end
end
end
end
end
describe
'email on push with a single commit'
do
describe
'email on push with a single commit'
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