Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
4b6e6d0a
G
gitlab-foss
项目概览
李少辉-开发者
/
gitlab-foss
通知
15
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
G
gitlab-foss
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4b6e6d0a
编写于
7月 18, 2016
作者:
R
Robert Speicher
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'issue_13343' into 'master'
Allow build email service to be tested Fixes #13343 See merge request !5223
上级
9065f9c5
2e9d5358
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
79 addition
and
2 deletion
+79
-2
CHANGELOG
CHANGELOG
+1
-0
app/controllers/projects/services_controller.rb
app/controllers/projects/services_controller.rb
+2
-1
app/mailers/emails/builds.rb
app/mailers/emails/builds.rb
+1
-0
app/models/project_services/builds_email_service.rb
app/models/project_services/builds_email_service.rb
+27
-0
app/models/service.rb
app/models/service.rb
+9
-0
app/views/projects/services/_form.html.haml
app/views/projects/services/_form.html.haml
+1
-1
spec/models/project_services/builds_email_service_spec.rb
spec/models/project_services/builds_email_service_spec.rb
+38
-0
未找到文件。
CHANGELOG
浏览文件 @
4b6e6d0a
...
...
@@ -26,6 +26,7 @@ v 8.10.0 (unreleased)
- Add a new column `artifacts_size` to table `ci_builds` !4964
- Let Workhorse serve format-patch diffs
- Display tooltip for mentioned users and groups !5261 (winniehell)
- Allow build email service to be tested
- Added day name to contribution calendar tooltips
- Make images fit to the size of the viewport !4810
- Fix check for New Branch button on Issue page !4630 (winniehell)
...
...
app/controllers/projects/services_controller.rb
浏览文件 @
4b6e6d0a
...
...
@@ -45,8 +45,9 @@ class Projects::ServicesController < Projects::ApplicationController
end
def
test
data
=
Gitlab
::
PushDataBuilder
.
build_sample
(
project
,
current_user
)
data
=
@service
.
test_data
(
project
,
current_user
)
outcome
=
@service
.
test
(
data
)
if
outcome
[
:success
]
message
=
{
notice:
'We sent a request to the provided URL'
}
else
...
...
app/mailers/emails/builds.rb
浏览文件 @
4b6e6d0a
...
...
@@ -6,6 +6,7 @@ module Emails
add_project_headers
add_build_headers
(
'failed'
)
mail
(
to:
to
,
subject:
subject
(
"Build failed for
#{
@project
.
name
}
"
,
@build
.
short_sha
))
end
...
...
app/models/project_services/builds_email_service.rb
浏览文件 @
4b6e6d0a
...
...
@@ -42,6 +42,19 @@ class BuildsEmailService < Service
end
end
def
can_test?
project
.
builds
.
count
>
0
end
def
disabled_title
"Please setup a build on your repository."
end
def
test_data
(
project
=
nil
,
user
=
nil
)
build
=
project
.
builds
.
last
Gitlab
::
BuildDataBuilder
.
build
(
build
)
end
def
fields
[
{
type:
'textarea'
,
name:
'recipients'
,
placeholder:
'Emails separated by comma'
},
...
...
@@ -50,6 +63,20 @@ class BuildsEmailService < Service
]
end
def
test
(
data
)
begin
# bypass build status verification when testing
data
[
:build_status
]
=
"failed"
data
[
:build_allow_failure
]
=
false
result
=
execute
(
data
)
rescue
StandardError
=>
error
return
{
success:
false
,
result:
error
}
end
{
success:
true
,
result:
result
}
end
def
should_build_be_notified?
(
data
)
case
data
[
:build_status
]
when
'success'
...
...
app/models/service.rb
浏览文件 @
4b6e6d0a
...
...
@@ -76,6 +76,10 @@ class Service < ActiveRecord::Base
[]
end
def
test_data
(
project
,
user
)
Gitlab
::
PushDataBuilder
.
build_sample
(
project
,
user
)
end
def
supported_events
%w(push tag_push issue merge_request wiki_page)
end
...
...
@@ -94,6 +98,11 @@ class Service < ActiveRecord::Base
!
project
.
empty_repo?
end
# reason why service cannot be tested
def
disabled_title
"Please setup a project repository."
end
# Provide convenient accessor methods
# for each serialized property.
# Also keep track of updated properties in a similar way as ActiveModel::Dirty
...
...
app/views/projects/services/_form.html.haml
浏览文件 @
4b6e6d0a
...
...
@@ -12,5 +12,5 @@
-
if
@service
.
valid?
&&
@service
.
activated?
-
disabled
=
@service
.
can_test?
?
''
:
'disabled'
=
link_to
'Test settings'
,
test_namespace_project_service_path
(
@project
.
namespace
,
@project
,
@service
.
to_param
),
class:
"btn
#{
disabled
}
"
=
link_to
'Test settings'
,
test_namespace_project_service_path
(
@project
.
namespace
,
@project
,
@service
),
class:
"btn
#{
disabled
}
"
,
title:
@service
.
disabled_title
=
link_to
"Cancel"
,
namespace_project_services_path
(
@project
.
namespace
,
@project
),
class:
"btn btn-cancel"
spec/models/project_services/builds_email_service_spec.rb
浏览文件 @
4b6e6d0a
...
...
@@ -23,6 +23,44 @@ describe BuildsEmailService do
end
end
describe
'#test_data'
do
let
(
:build
)
{
create
(
:ci_build
)
}
let
(
:project
)
{
build
.
project
}
let
(
:user
)
{
create
(
:user
)
}
before
{
project
.
team
<<
[
user
,
:developer
]
}
it
'builds test data'
do
data
=
subject
.
test_data
(
project
)
expect
(
data
[
:object_kind
]).
to
eq
(
"build"
)
end
end
describe
'#test'
do
it
'sends email'
do
data
=
Gitlab
::
BuildDataBuilder
.
build
(
create
(
:ci_build
))
subject
.
recipients
=
'test@gitlab.com'
expect
(
BuildEmailWorker
).
to
receive
(
:perform_async
)
subject
.
test
(
data
)
end
context
'notify only failed builds is true'
do
it
'sends email'
do
data
=
Gitlab
::
BuildDataBuilder
.
build
(
create
(
:ci_build
))
data
[
:build_status
]
=
"success"
subject
.
recipients
=
'test@gitlab.com'
expect
(
subject
).
not_to
receive
(
:notify_only_broken_builds
)
expect
(
BuildEmailWorker
).
to
receive
(
:perform_async
)
subject
.
test
(
data
)
end
end
end
describe
'#execute'
do
it
'sends email'
do
subject
.
recipients
=
'test@gitlab.com'
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录