Commit 5fbbcbca authored by GitLab Bot's avatar GitLab Bot

Automatic merge of gitlab-org/gitlab-ce master

parents bf250b44 9ac48b4e
---
title: Add source and merge_request fields to pipeline event webhook
merge_request: 32373
author: Bian Jiaping
type: added
......@@ -1001,6 +1001,7 @@ X-Gitlab-Event: Pipeline Hook
"tag": false,
"sha": "bcbb5ec396a2c0f828686f14fac9b80b780504f2",
"before_sha": "bcbb5ec396a2c0f828686f14fac9b80b780504f2",
"source": "merge_request_event",
"status": "success",
"stages":[
"build",
......@@ -1016,6 +1017,18 @@ X-Gitlab-Event: Pipeline Hook
"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":{
"name": "Administrator",
......
......@@ -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,
......
......@@ -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
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment