summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBian Jiaping <ssbianjp@gmail.com>2019-09-11 19:33:45 +0000
committerMayra Cabrera <mcabrera@gitlab.com>2019-09-11 19:33:45 +0000
commit9c0e2d5b47c09eba83c3f73d4b01e2b27378cb4d (patch)
tree1badc87a7dfc63d4cb1b53c120e1dbb6ef0dbde4
parent3fb68248921b6002f55f2b1f8c97ed1aaf9600d6 (diff)
downloadgitlab-ce-9c0e2d5b47c09eba83c3f73d4b01e2b27378cb4d.tar.gz
Add source and merge_request fields to pipeline event webhook
-rw-r--r--changelogs/unreleased/add-source-and-merge_request-to-pipeline-webhook.yml5
-rw-r--r--doc/user/project/integrations/webhooks.md13
-rw-r--r--lib/gitlab/data_builder/pipeline.rb17
-rw-r--r--spec/lib/gitlab/data_builder/pipeline_spec.rb18
4 files changed, 53 insertions, 0 deletions
diff --git a/changelogs/unreleased/add-source-and-merge_request-to-pipeline-webhook.yml b/changelogs/unreleased/add-source-and-merge_request-to-pipeline-webhook.yml
new file mode 100644
index 00000000000..e7300335427
--- /dev/null
+++ b/changelogs/unreleased/add-source-and-merge_request-to-pipeline-webhook.yml
@@ -0,0 +1,5 @@
+---
+title: Add source and merge_request fields to pipeline event webhook
+merge_request: 32373
+author: Bian Jiaping
+type: added
diff --git a/doc/user/project/integrations/webhooks.md b/doc/user/project/integrations/webhooks.md
index 211bbdc2bb9..b508d904606 100644
--- a/doc/user/project/integrations/webhooks.md
+++ b/doc/user/project/integrations/webhooks.md
@@ -1001,6 +1001,7 @@ X-Gitlab-Event: Pipeline Hook
"tag": false,
"sha": "bcbb5ec396a2c0f828686f14fac9b80b780504f2",
"before_sha": "bcbb5ec396a2c0f828686f14fac9b80b780504f2",
+ "source": "merge_request_event",
"status": "success",
"stages":[
"build",
@@ -1017,6 +1018,18 @@ X-Gitlab-Event: Pipeline Hook
}
]
},
+ "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":{
"name": "Administrator",
"username": "root",
diff --git a/lib/gitlab/data_builder/pipeline.rb b/lib/gitlab/data_builder/pipeline.rb
index e1e813849bf..da3d6c47431 100644
--- a/lib/gitlab/data_builder/pipeline.rb
+++ b/lib/gitlab/data_builder/pipeline.rb
@@ -9,6 +9,7 @@ module Gitlab
{
object_kind: 'pipeline',
object_attributes: hook_attrs(pipeline),
+ merge_request: pipeline.merge_request && merge_request_attrs(pipeline.merge_request),
user: pipeline.user.try(:hook_attrs),
project: pipeline.project.hook_attrs(backward: false),
commit: pipeline.commit.try(:hook_attrs),
@@ -23,6 +24,7 @@ module Gitlab
tag: pipeline.tag,
sha: pipeline.sha,
before_sha: pipeline.before_sha,
+ source: pipeline.source,
status: pipeline.status,
detailed_status: pipeline.detailed_status(nil).label,
stages: pipeline.stages_names,
@@ -33,6 +35,21 @@ module Gitlab
}
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)
{
id: build.id,
diff --git a/spec/lib/gitlab/data_builder/pipeline_spec.rb b/spec/lib/gitlab/data_builder/pipeline_spec.rb
index 4afb7195b7b..931477d19c2 100644
--- a/spec/lib/gitlab/data_builder/pipeline_spec.rb
+++ b/spec/lib/gitlab/data_builder/pipeline_spec.rb
@@ -28,12 +28,14 @@ describe Gitlab::DataBuilder::Pipeline do
expect(attributes[:sha]).to eq(pipeline.sha)
expect(attributes[:tag]).to eq(pipeline.tag)
expect(attributes[:id]).to eq(pipeline.id)
+ expect(attributes[:source]).to eq(pipeline.source)
expect(attributes[:status]).to eq(pipeline.status)
expect(attributes[:detailed_status]).to eq('passed')
expect(build_data).to be_a(Hash)
expect(build_data[:id]).to eq(build.id)
expect(build_data[:status]).to eq(build.status)
expect(project_data).to eq(project.hook_attrs(backward: false))
+ expect(data[:merge_request]).to be_nil
end
context 'pipeline without variables' do
@@ -60,6 +62,22 @@ describe Gitlab::DataBuilder::Pipeline do
it 'returns a source ref' do
expect(attributes[:ref]).to eq(merge_request.source_branch)
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