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
Kazuhiko Shiozaki
gitlab-ce
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 Emails
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 @@ module Emails
@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 @@ module Emails
# 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 @@ class Notify < BaseMailer
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 @@ class Notify < BaseMailer
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 @@ module Gitlab
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 @@ describe Notify do
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 @@ describe Notify do
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 @@ describe Notify do
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 @@ describe Notify do
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 @@ describe Notify do
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 @@ describe Notify do
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 @@ describe Notify do
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 @@ describe Notify do
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 @@ describe Notify do
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 @@ describe Notify do
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