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
Boxiang Sun
gitlab-ce
Commits
9c0e2d5b
Commit
9c0e2d5b
authored
Sep 11, 2019
by
Bian Jiaping
Committed by
Mayra Cabrera
Sep 11, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add source and merge_request fields to pipeline event webhook
parent
3fb68248
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
53 additions
and
0 deletions
+53
-0
changelogs/unreleased/add-source-and-merge_request-to-pipeline-webhook.yml
...ased/add-source-and-merge_request-to-pipeline-webhook.yml
+5
-0
doc/user/project/integrations/webhooks.md
doc/user/project/integrations/webhooks.md
+13
-0
lib/gitlab/data_builder/pipeline.rb
lib/gitlab/data_builder/pipeline.rb
+17
-0
spec/lib/gitlab/data_builder/pipeline_spec.rb
spec/lib/gitlab/data_builder/pipeline_spec.rb
+18
-0
No files found.
changelogs/unreleased/add-source-and-merge_request-to-pipeline-webhook.yml
0 → 100644
View file @
9c0e2d5b
---
title
:
Add source and merge_request fields to pipeline event webhook
merge_request
:
32373
author
:
Bian Jiaping
type
:
added
doc/user/project/integrations/webhooks.md
View file @
9c0e2d5b
...
@@ -1001,6 +1001,7 @@ X-Gitlab-Event: Pipeline Hook
...
@@ -1001,6 +1001,7 @@ X-Gitlab-Event: Pipeline Hook
"tag"
:
false
,
"tag"
:
false
,
"sha"
:
"bcbb5ec396a2c0f828686f14fac9b80b780504f2"
,
"sha"
:
"bcbb5ec396a2c0f828686f14fac9b80b780504f2"
,
"before_sha"
:
"bcbb5ec396a2c0f828686f14fac9b80b780504f2"
,
"before_sha"
:
"bcbb5ec396a2c0f828686f14fac9b80b780504f2"
,
"source"
:
"merge_request_event"
,
"status"
:
"success"
,
"status"
:
"success"
,
"stages"
:[
"stages"
:[
"build"
,
"build"
,
...
@@ -1016,6 +1017,18 @@ X-Gitlab-Event: Pipeline Hook
...
@@ -1016,6 +1017,18 @@ X-Gitlab-Event: Pipeline Hook
"value"
:
"us-west-1"
"value"
:
"us-west-1"
}
}
]
]
},
"merge_request"
:
{
"id"
:
1
,
"iid"
:
1
,
"title"
:
"Test"
,
"source_branch"
:
"test"
,
"source_project_id"
:
1
,
"target_branch"
:
"master"
,
"target_project_id"
:
1
,
"state"
:
"opened"
,
"merge_status"
:
"can_be_merged"
,
"url"
:
"http://192.168.64.1:3005/gitlab-org/gitlab-test/merge_requests/1"
},
},
"user"
:{
"user"
:{
"name"
:
"Administrator"
,
"name"
:
"Administrator"
,
...
...
lib/gitlab/data_builder/pipeline.rb
View file @
9c0e2d5b
...
@@ -9,6 +9,7 @@ module Gitlab
...
@@ -9,6 +9,7 @@ module Gitlab
{
{
object_kind:
'pipeline'
,
object_kind:
'pipeline'
,
object_attributes:
hook_attrs
(
pipeline
),
object_attributes:
hook_attrs
(
pipeline
),
merge_request:
pipeline
.
merge_request
&&
merge_request_attrs
(
pipeline
.
merge_request
),
user:
pipeline
.
user
.
try
(
:hook_attrs
),
user:
pipeline
.
user
.
try
(
:hook_attrs
),
project:
pipeline
.
project
.
hook_attrs
(
backward:
false
),
project:
pipeline
.
project
.
hook_attrs
(
backward:
false
),
commit:
pipeline
.
commit
.
try
(
:hook_attrs
),
commit:
pipeline
.
commit
.
try
(
:hook_attrs
),
...
@@ -23,6 +24,7 @@ module Gitlab
...
@@ -23,6 +24,7 @@ module Gitlab
tag:
pipeline
.
tag
,
tag:
pipeline
.
tag
,
sha:
pipeline
.
sha
,
sha:
pipeline
.
sha
,
before_sha:
pipeline
.
before_sha
,
before_sha:
pipeline
.
before_sha
,
source:
pipeline
.
source
,
status:
pipeline
.
status
,
status:
pipeline
.
status
,
detailed_status:
pipeline
.
detailed_status
(
nil
).
label
,
detailed_status:
pipeline
.
detailed_status
(
nil
).
label
,
stages:
pipeline
.
stages_names
,
stages:
pipeline
.
stages_names
,
...
@@ -33,6 +35,21 @@ module Gitlab
...
@@ -33,6 +35,21 @@ module Gitlab
}
}
end
end
def
merge_request_attrs
(
merge_request
)
{
id:
merge_request
.
id
,
iid:
merge_request
.
iid
,
title:
merge_request
.
title
,
source_branch:
merge_request
.
source_branch
,
source_project_id:
merge_request
.
source_project_id
,
target_branch:
merge_request
.
target_branch
,
target_project_id:
merge_request
.
target_project_id
,
state:
merge_request
.
state
,
merge_status:
merge_request
.
merge_status
,
url:
Gitlab
::
UrlBuilder
.
build
(
merge_request
)
}
end
def
build_hook_attrs
(
build
)
def
build_hook_attrs
(
build
)
{
{
id:
build
.
id
,
id:
build
.
id
,
...
...
spec/lib/gitlab/data_builder/pipeline_spec.rb
View file @
9c0e2d5b
...
@@ -28,12 +28,14 @@ describe Gitlab::DataBuilder::Pipeline do
...
@@ -28,12 +28,14 @@ describe Gitlab::DataBuilder::Pipeline do
expect
(
attributes
[
:sha
]).
to
eq
(
pipeline
.
sha
)
expect
(
attributes
[
:sha
]).
to
eq
(
pipeline
.
sha
)
expect
(
attributes
[
:tag
]).
to
eq
(
pipeline
.
tag
)
expect
(
attributes
[
:tag
]).
to
eq
(
pipeline
.
tag
)
expect
(
attributes
[
:id
]).
to
eq
(
pipeline
.
id
)
expect
(
attributes
[
:id
]).
to
eq
(
pipeline
.
id
)
expect
(
attributes
[
:source
]).
to
eq
(
pipeline
.
source
)
expect
(
attributes
[
:status
]).
to
eq
(
pipeline
.
status
)
expect
(
attributes
[
:status
]).
to
eq
(
pipeline
.
status
)
expect
(
attributes
[
:detailed_status
]).
to
eq
(
'passed'
)
expect
(
attributes
[
:detailed_status
]).
to
eq
(
'passed'
)
expect
(
build_data
).
to
be_a
(
Hash
)
expect
(
build_data
).
to
be_a
(
Hash
)
expect
(
build_data
[
:id
]).
to
eq
(
build
.
id
)
expect
(
build_data
[
:id
]).
to
eq
(
build
.
id
)
expect
(
build_data
[
:status
]).
to
eq
(
build
.
status
)
expect
(
build_data
[
:status
]).
to
eq
(
build
.
status
)
expect
(
project_data
).
to
eq
(
project
.
hook_attrs
(
backward:
false
))
expect
(
project_data
).
to
eq
(
project
.
hook_attrs
(
backward:
false
))
expect
(
data
[
:merge_request
]).
to
be_nil
end
end
context
'pipeline without variables'
do
context
'pipeline without variables'
do
...
@@ -60,6 +62,22 @@ describe Gitlab::DataBuilder::Pipeline do
...
@@ -60,6 +62,22 @@ describe Gitlab::DataBuilder::Pipeline do
it
'returns a source ref'
do
it
'returns a source ref'
do
expect
(
attributes
[
:ref
]).
to
eq
(
merge_request
.
source_branch
)
expect
(
attributes
[
:ref
]).
to
eq
(
merge_request
.
source_branch
)
end
end
it
'returns merge request'
do
merge_request_attrs
=
data
[
:merge_request
]
expect
(
merge_request_attrs
).
to
be_a
(
Hash
)
expect
(
merge_request_attrs
[
:id
]).
to
eq
(
merge_request
.
id
)
expect
(
merge_request_attrs
[
:iid
]).
to
eq
(
merge_request
.
iid
)
expect
(
merge_request_attrs
[
:title
]).
to
eq
(
merge_request
.
title
)
expect
(
merge_request_attrs
[
:source_branch
]).
to
eq
(
merge_request
.
source_branch
)
expect
(
merge_request_attrs
[
:source_project_id
]).
to
eq
(
merge_request
.
source_project_id
)
expect
(
merge_request_attrs
[
:target_branch
]).
to
eq
(
merge_request
.
target_branch
)
expect
(
merge_request_attrs
[
:target_project_id
]).
to
eq
(
merge_request
.
target_project_id
)
expect
(
merge_request_attrs
[
:state
]).
to
eq
(
merge_request
.
state
)
expect
(
merge_request_attrs
[
:merge_status
]).
to
eq
(
merge_request
.
merge_status
)
expect
(
merge_request_attrs
[
:url
]).
to
eq
(
"http://localhost/
#{
merge_request
.
target_project
.
full_path
}
/merge_requests/
#{
merge_request
.
iid
}
"
)
end
end
end
end
end
end
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