Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
projects.thm.de
GitLab
Commits
84124380
Commit
84124380
authored
Dec 19, 2015
by
Anton Baklanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added X-GitLab-... headers to emails from CI and Email On Push services
Fixes #2098
parent
340df52b
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
84 additions
and
9 deletions
+84
-9
CHANGELOG
CHANGELOG
+1
-0
app/mailers/emails/builds.rb
app/mailers/emails/builds.rb
+13
-0
app/mailers/emails/projects.rb
app/mailers/emails/projects.rb
+5
-1
app/mailers/notify.rb
app/mailers/notify.rb
+9
-6
lib/gitlab/email/message/repository_push.rb
lib/gitlab/email/message/repository_push.rb
+1
-0
spec/mailers/notify_spec.rb
spec/mailers/notify_spec.rb
+55
-2
No files found.
CHANGELOG
View file @
84124380
...
...
@@ -68,6 +68,7 @@ v 8.4.0 (unreleased)
- Increase default size of `data` column in `events` table when using MySQL
- Expose button to CI Lint tool on project builds page
- Fix: Creator should be added as a master of the project on creation
- Added X-GitLab-... headers to emails from CI and Email On Push services
v 8.3.4
- Use gitlab-workhorse 0.5.4 (fixes API routing bug)
...
...
app/mailers/emails/builds.rb
View file @
84124380
...
...
@@ -3,13 +3,26 @@ module Builds
def
build_fail_email
(
build_id
,
to
)
@build
=
Ci
::
Build
.
find
(
build_id
)
@project
=
@build
.
project
add_project_headers
add_build_headers
headers
[
'X-GitLab-Build-Status'
]
=
"failed"
mail
(
to:
to
,
subject:
subject
(
"Build failed for
#{
@project
.
name
}
"
,
@build
.
short_sha
))
end
def
build_success_email
(
build_id
,
to
)
@build
=
Ci
::
Build
.
find
(
build_id
)
@project
=
@build
.
project
add_project_headers
add_build_headers
headers
[
'X-GitLab-Build-Status'
]
=
"success"
mail
(
to:
to
,
subject:
subject
(
"Build success for
#{
@project
.
name
}
"
,
@build
.
short_sha
))
end
private
def
add_build_headers
headers
[
'X-GitLab-Build-Id'
]
=
@build
.
id
headers
[
'X-GitLab-Build-Ref'
]
=
@build
.
ref
end
end
end
app/mailers/emails/projects.rb
View file @
84124380
...
...
@@ -43,7 +43,7 @@ def project_invite_declined_email(project_id, invite_email, access_level, create
@current_user
=
@created_by
=
User
.
find
(
created_by_id
)
@access_level
=
access_level
@invite_email
=
invite_email
@target_url
=
namespace_project_url
(
@project
.
namespace
,
@project
)
mail
(
to:
@created_by
.
notification_email
,
...
...
@@ -65,6 +65,10 @@ def repository_push_email(project_id, recipient, opts = {})
# used in notify layout
@target_url
=
@message
.
target_url
@project
=
Project
.
find
project_id
add_project_headers
headers
[
'X-GitLab-Author'
]
=
@message
.
author_username
mail
(
from:
sender
(
@message
.
author_id
,
@message
.
send_from_committer_email?
),
reply_to:
@message
.
reply_to
,
...
...
app/mailers/notify.rb
View file @
84124380
...
...
@@ -100,12 +100,7 @@ def message_id(model)
end
def
mail_thread
(
model
,
headers
=
{})
if
@project
headers
[
'X-GitLab-Project'
]
=
@project
.
name
headers
[
'X-GitLab-Project-Id'
]
=
@project
.
id
headers
[
'X-GitLab-Project-Path'
]
=
@project
.
path_with_namespace
end
add_project_headers
headers
[
"X-GitLab-
#{
model
.
class
.
name
}
-ID"
]
=
model
.
id
headers
[
'X-GitLab-Reply-Key'
]
=
reply_key
...
...
@@ -152,4 +147,12 @@ def mail_answer_thread(model, headers = {})
def
reply_key
@reply_key
||=
SentNotification
.
reply_key
end
def
add_project_headers
return
unless
@project
headers
[
'X-GitLab-Project'
]
=
@project
.
name
headers
[
'X-GitLab-Project-Id'
]
=
@project
.
id
headers
[
'X-GitLab-Project-Path'
]
=
@project
.
path_with_namespace
end
end
lib/gitlab/email/message/repository_push.rb
View file @
84124380
...
...
@@ -9,6 +9,7 @@ class RepositoryPush
delegate
:namespace
,
:name_with_namespace
,
to: :project
,
prefix: :project
delegate
:name
,
to: :author
,
prefix: :author
delegate
:username
,
to: :author
,
prefix: :author
def
initialize
(
notify
,
project_id
,
recipient
,
opts
=
{})
raise
ArgumentError
,
'Missing options: author_id, ref, action'
unless
...
...
spec/mailers/notify_spec.rb
View file @
84124380
...
...
@@ -40,14 +40,38 @@
end
end
shared_examples
'an email with X-GitLab headers containing project details'
do
it
'has X-GitLab-Project* headers'
do
is_expected
.
to
have_header
'X-GitLab-Project'
,
/
#{
project
.
name
}
/
is_expected
.
to
have_header
'X-GitLab-Project-Id'
,
/
#{
project
.
id
}
/
is_expected
.
to
have_header
'X-GitLab-Project-Path'
,
/
#{
project
.
path_with_namespace
}
/
end
end
shared_examples
'an email with X-GitLab headers containing build details'
do
it
'has X-GitLab-Build* headers'
do
is_expected
.
to
have_header
'X-GitLab-Build-Id'
,
/
#{
build
.
id
}
/
is_expected
.
to
have_header
'X-GitLab-Build-Ref'
,
/
#{
build
.
ref
}
/
end
end
shared_examples
'an email that contains a header with author username'
do
it
'has X-GitLab-Author header containing author\'s username'
do
is_expected
.
to
have_header
'X-GitLab-Author'
,
user
.
username
end
end
shared_examples
'an email starting a new thread'
do
|
message_id_prefix
|
include_examples
'an email with X-GitLab headers containing project details'
it
'has a discussion identifier'
do
is_expected
.
to
have_header
'Message-ID'
,
/<
#{
message_id_prefix
}
(.*)@
#{
Gitlab
.
config
.
gitlab
.
host
}
>/
is_expected
.
to
have_header
'X-GitLab-Project'
,
/
#{
project
.
name
}
/
end
end
shared_examples
'an answer to an existing thread'
do
|
thread_id_prefix
|
include_examples
'an email with X-GitLab headers containing project details'
it
'has a subject that begins with Re: '
do
is_expected
.
to
have_subject
/^Re: /
end
...
...
@@ -56,7 +80,6 @@
is_expected
.
to
have_header
'Message-ID'
,
/<(.*)@
#{
Gitlab
.
config
.
gitlab
.
host
}
>/
is_expected
.
to
have_header
'References'
,
/<
#{
thread_id_prefix
}
(.*)@
#{
Gitlab
.
config
.
gitlab
.
host
}
>/
is_expected
.
to
have_header
'In-Reply-To'
,
/<
#{
thread_id_prefix
}
(.*)@
#{
Gitlab
.
config
.
gitlab
.
host
}
>/
is_expected
.
to
have_header
'X-GitLab-Project'
,
/
#{
project
.
name
}
/
end
end
...
...
@@ -656,6 +679,8 @@
it_behaves_like
'it should not have Gmail Actions links'
it_behaves_like
"a user cannot unsubscribe through footer link"
it_behaves_like
'an email with X-GitLab headers containing project details'
it_behaves_like
'an email that contains a header with author username'
it
'is sent as the author'
do
sender
=
subject
.
header
[
:from
].
addrs
[
0
]
...
...
@@ -685,6 +710,8 @@
it_behaves_like
'it should not have Gmail Actions links'
it_behaves_like
"a user cannot unsubscribe through footer link"
it_behaves_like
'an email with X-GitLab headers containing project details'
it_behaves_like
'an email that contains a header with author username'
it
'is sent as the author'
do
sender
=
subject
.
header
[
:from
].
addrs
[
0
]
...
...
@@ -713,6 +740,8 @@
it_behaves_like
'it should not have Gmail Actions links'
it_behaves_like
"a user cannot unsubscribe through footer link"
it_behaves_like
'an email with X-GitLab headers containing project details'
it_behaves_like
'an email that contains a header with author username'
it
'is sent as the author'
do
sender
=
subject
.
header
[
:from
].
addrs
[
0
]
...
...
@@ -737,6 +766,8 @@
it_behaves_like
'it should not have Gmail Actions links'
it_behaves_like
"a user cannot unsubscribe through footer link"
it_behaves_like
'an email with X-GitLab headers containing project details'
it_behaves_like
'an email that contains a header with author username'
it
'is sent as the author'
do
sender
=
subject
.
header
[
:from
].
addrs
[
0
]
...
...
@@ -765,6 +796,8 @@
it_behaves_like
'it should not have Gmail Actions links'
it_behaves_like
"a user cannot unsubscribe through footer link"
it_behaves_like
'an email with X-GitLab headers containing project details'
it_behaves_like
'an email that contains a header with author username'
it
'is sent as the author'
do
sender
=
subject
.
header
[
:from
].
addrs
[
0
]
...
...
@@ -871,6 +904,8 @@
it_behaves_like
'it should show Gmail Actions View Commit link'
it_behaves_like
"a user cannot unsubscribe through footer link"
it_behaves_like
'an email with X-GitLab headers containing project details'
it_behaves_like
'an email that contains a header with author username'
it
'is sent as the author'
do
sender
=
subject
.
header
[
:from
].
addrs
[
0
]
...
...
@@ -904,6 +939,15 @@
subject
{
Notify
.
build_success_email
(
build
.
id
,
'wow@example.com'
)
}
it_behaves_like
'an email with X-GitLab headers containing build details'
it_behaves_like
'an email with X-GitLab headers containing project details'
do
let
(
:project
)
{
build
.
project
}
end
it
'has header indicating build status'
do
is_expected
.
to
have_header
'X-GitLab-Build-Status'
,
'success'
end
it
'has the correct subject'
do
should
have_subject
/Build success for/
end
...
...
@@ -918,6 +962,15 @@
subject
{
Notify
.
build_fail_email
(
build
.
id
,
'wow@example.com'
)
}
it_behaves_like
'an email with X-GitLab headers containing build details'
it_behaves_like
'an email with X-GitLab headers containing project details'
do
let
(
:project
)
{
build
.
project
}
end
it
'has header indicating build status'
do
is_expected
.
to
have_header
'X-GitLab-Build-Status'
,
'failed'
end
it
'has the correct subject'
do
should
have_subject
/Build failed for/
end
...
...
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