Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
李少辉-开发者
gitlab-foss
提交
baae3291
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,发现更多精彩内容 >>
提交
baae3291
编写于
3月 05, 2015
作者:
D
Dmitriy Zaporozhets
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'master' of gitlab.com:gitlab-org/gitlab-ce
上级
e7c90e58
671c3134
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
185 addition
and
5 deletion
+185
-5
CHANGELOG
CHANGELOG
+1
-0
app/models/project_services/hipchat_service.rb
app/models/project_services/hipchat_service.rb
+82
-5
spec/models/project_services/hipchat_service_spec.rb
spec/models/project_services/hipchat_service_spec.rb
+102
-0
未找到文件。
CHANGELOG
浏览文件 @
baae3291
Please view this file on the master branch, on stable branches it's out of date.
v 7.9.0 (unreleased)
- Added issue and merge request events to HipChat and Slack service (Stan Hu)
- Fix merge request URL passed to Webhooks. (Stan Hu)
- Fix bug that caused a server error when editing a comment to "+1" or "-1" (Stan Hu)
- Move labels/milestones tabs to sidebar
...
...
app/models/project_services/hipchat_service.rb
浏览文件 @
baae3291
...
...
@@ -45,7 +45,7 @@ class HipchatService < Service
end
def
supported_events
%w(push)
%w(push
issue merge_request
)
end
def
execute
(
data
)
...
...
@@ -62,7 +62,21 @@ class HipchatService < Service
@gate
||=
HipChat
::
Client
.
new
(
token
,
options
)
end
def
create_message
(
push
)
def
create_message
(
data
)
object_kind
=
data
[
:object_kind
]
message
=
\
case
object_kind
when
"push"
create_push_message
(
data
)
when
"issue"
create_issue_message
(
data
)
unless
is_update?
(
data
)
when
"merge_request"
create_merge_request_message
(
data
)
unless
is_update?
(
data
)
end
end
def
create_push_message
(
push
)
ref
=
push
[
:ref
].
gsub
(
"refs/heads/"
,
""
)
before
=
push
[
:before
]
after
=
push
[
:after
]
...
...
@@ -71,9 +85,9 @@ class HipchatService < Service
message
<<
"
#{
push
[
:user_name
]
}
"
if
before
.
include?
(
'000000'
)
message
<<
"pushed new branch <a href=
\"
"
\
"
#{
project
.
web
_url
}
/commits/
#{
URI
.
escape
(
ref
)
}
\"
>
#{
ref
}
</a>"
\
" to <a href=
\"
#{
project
.
web
_url
}
\"
>"
\
"
#{
project
.
name_with_namespace
.
gsub!
(
/\s/
,
""
)
}
</a>
\n
"
"
#{
project_url
}
/commits/
#{
URI
.
escape
(
ref
)
}
\"
>
#{
ref
}
</a>"
\
" to <a href=
\"
#{
project_url
}
\"
>"
\
"
#{
project
_url
}
</a>
\n
"
elsif
after
.
include?
(
'000000'
)
message
<<
"removed branch
#{
ref
}
from <a href=
\"
#{
project
.
web_url
}
\"
>
#{
project
.
name_with_namespace
.
gsub!
(
/\s/
,
''
)
}
</a>
\n
"
else
...
...
@@ -93,4 +107,67 @@ class HipchatService < Service
message
end
def
create_issue_message
(
data
)
username
=
data
[
:user
][
:username
]
obj_attr
=
data
[
:object_attributes
]
obj_attr
=
HashWithIndifferentAccess
.
new
(
obj_attr
)
title
=
obj_attr
[
:title
]
state
=
obj_attr
[
:state
]
issue_iid
=
obj_attr
[
:iid
]
issue_url
=
obj_attr
[
:url
]
description
=
obj_attr
[
:description
]
issue_link
=
"<a href=
\"
#{
issue_url
}
\"
>#
#{
issue_iid
}
</a>"
message
=
"
#{
username
}
#{
state
}
issue
#{
issue_link
}
in
#{
project_link
}
: <b>
#{
title
}
</b>"
if
description
description
=
description
.
truncate
(
200
,
separator:
' '
,
omission:
'...'
)
message
<<
"<pre>
#{
description
}
</pre>"
end
message
end
def
create_merge_request_message
(
data
)
username
=
data
[
:user
][
:username
]
obj_attr
=
data
[
:object_attributes
]
obj_attr
=
HashWithIndifferentAccess
.
new
(
obj_attr
)
merge_request_id
=
obj_attr
[
:iid
]
source_branch
=
obj_attr
[
:source_branch
]
target_branch
=
obj_attr
[
:target_branch
]
state
=
obj_attr
[
:state
]
description
=
obj_attr
[
:description
]
title
=
obj_attr
[
:title
]
merge_request_url
=
"
#{
project_url
}
/merge_requests/
#{
merge_request_id
}
"
merge_request_link
=
"<a href=
\"
#{
merge_request_url
}
\"
>#
#{
merge_request_id
}
</a>"
message
=
"
#{
username
}
#{
state
}
merge request
#{
merge_request_link
}
in "
\
"
#{
project_link
}
: <b>
#{
title
}
</b>"
if
description
description
=
description
.
truncate
(
200
,
separator:
' '
,
omission:
'...'
)
message
<<
"<pre>
#{
description
}
</pre>"
end
message
end
def
project_name
project
.
name_with_namespace
.
gsub
(
/\s/
,
''
)
end
def
project_url
project
.
web_url
end
def
project_link
"<a href=
\"
#{
project_url
}
\"
>
#{
project_name
}
</a>"
end
def
is_update?
(
data
)
data
[
:object_attributes
][
:action
]
==
'update'
end
end
spec/models/project_services/hipchat_service_spec.rb
0 → 100644
浏览文件 @
baae3291
# == Schema Information
#
# Table name: services
#
# id :integer not null, primary key
# type :string(255)
# title :string(255)
# project_id :integer not null
# created_at :datetime
# updated_at :datetime
# active :boolean default(FALSE), not null
# properties :text
# push_events :boolean default(TRUE)
# issues_events :boolean default(TRUE)
# merge_requests_events :boolean default(TRUE)
# tag_push_events :boolean default(TRUE)
#
require
'spec_helper'
describe
HipchatService
do
describe
"Associations"
do
it
{
is_expected
.
to
belong_to
:project
}
it
{
is_expected
.
to
have_one
:service_hook
}
end
describe
"Execute"
do
let
(
:hipchat
)
{
HipchatService
.
new
}
let
(
:user
)
{
create
(
:user
,
username:
'username'
)
}
let
(
:project
)
{
create
(
:project
,
name:
'project'
)
}
let
(
:api_url
)
{
'https://hipchat.example.com/v2/room/123456/notification?auth_token=verySecret'
}
let
(
:project_name
)
{
project
.
name_with_namespace
.
gsub
(
/\s/
,
''
)
}
before
(
:each
)
do
hipchat
.
stub
(
project_id:
project
.
id
,
project:
project
,
room:
123456
,
server:
'https://hipchat.example.com'
,
token:
'verySecret'
)
WebMock
.
stub_request
(
:post
,
api_url
)
end
context
'push events'
do
let
(
:push_sample_data
)
{
Gitlab
::
PushDataBuilder
.
build_sample
(
project
,
user
)
}
it
"should call Hipchat API for push events"
do
hipchat
.
execute
(
push_sample_data
)
expect
(
WebMock
).
to
have_requested
(
:post
,
api_url
).
once
end
end
context
'issue events'
do
let
(
:issue
)
{
create
(
:issue
,
title:
'Awesome issue'
,
description:
'please fix'
)
}
let
(
:issue_service
)
{
Issues
::
CreateService
.
new
(
project
,
user
)
}
let
(
:issues_sample_data
)
{
issue_service
.
hook_data
(
issue
,
'open'
)
}
it
"should call Hipchat API for issue events"
do
hipchat
.
execute
(
issues_sample_data
)
expect
(
WebMock
).
to
have_requested
(
:post
,
api_url
).
once
end
it
"should create an issue message"
do
message
=
hipchat
.
send
(
:create_issue_message
,
issues_sample_data
)
obj_attr
=
issues_sample_data
[
:object_attributes
]
expect
(
message
).
to
eq
(
"
#{
user
.
username
}
opened issue "
\
"<a href=
\"
#{
obj_attr
[
:url
]
}
\"
>#
#{
obj_attr
[
"iid"
]
}
</a> in "
\
"<a href=
\"
#{
project
.
web_url
}
\"
>
#{
project_name
}
</a>: "
\
"<b>Awesome issue</b>"
\
"<pre>please fix</pre>"
)
end
end
context
'merge request events'
do
let
(
:merge_request
)
{
create
(
:merge_request
,
description:
'please fix'
,
title:
'Awesome merge request'
,
target_project:
project
,
source_project:
project
)
}
let
(
:merge_service
)
{
MergeRequests
::
CreateService
.
new
(
project
,
user
)
}
let
(
:merge_sample_data
)
{
merge_service
.
hook_data
(
merge_request
,
'open'
)
}
it
"should call Hipchat API for merge requests events"
do
hipchat
.
execute
(
merge_sample_data
)
expect
(
WebMock
).
to
have_requested
(
:post
,
api_url
).
once
end
it
"should create a merge request message"
do
message
=
hipchat
.
send
(
:create_merge_request_message
,
merge_sample_data
)
obj_attr
=
merge_sample_data
[
:object_attributes
]
expect
(
message
).
to
eq
(
"
#{
user
.
username
}
opened merge request "
\
"<a href=
\"
#{
obj_attr
[
:url
]
}
\"
>#
#{
obj_attr
[
"iid"
]
}
</a> in "
\
"<a href=
\"
#{
project
.
web_url
}
\"
>
#{
project_name
}
</a>: "
\
"<b>Awesome merge request</b>"
\
"<pre>please fix</pre>"
)
end
end
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录