From 25b13eee9f8137452d77be08f0a47eca748a810c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Tue, 2 Feb 2021 17:31:19 +0100 Subject: [PATCH 1/3] Send only latest jobs in pipeline webhook --- lib/gitlab/data_builder/pipeline.rb | 2 +- spec/lib/gitlab/data_builder/pipeline_spec.rb | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/gitlab/data_builder/pipeline.rb b/lib/gitlab/data_builder/pipeline.rb index 2413f68f4d047c..3036bc57ca58e7 100644 --- a/lib/gitlab/data_builder/pipeline.rb +++ b/lib/gitlab/data_builder/pipeline.rb @@ -13,7 +13,7 @@ def build(pipeline) user: pipeline.user.try(:hook_attrs), project: pipeline.project.hook_attrs(backward: false), commit: pipeline.commit.try(:hook_attrs), - builds: pipeline.builds.map(&method(:build_hook_attrs)) + builds: pipeline.builds.latest.map(&method(:build_hook_attrs)) } end diff --git a/spec/lib/gitlab/data_builder/pipeline_spec.rb b/spec/lib/gitlab/data_builder/pipeline_spec.rb index 32619fc4c37374..fd7cadeb89ebda 100644 --- a/spec/lib/gitlab/data_builder/pipeline_spec.rb +++ b/spec/lib/gitlab/data_builder/pipeline_spec.rb @@ -104,5 +104,16 @@ expect(merge_request_attrs[:url]).to eq("http://localhost/#{merge_request.target_project.full_path}/-/merge_requests/#{merge_request.iid}") end end + + context 'when pipeline has retried builds' do + before do + create(:ci_build, :retried, pipeline: pipeline) + end + + it 'does not contain retried builds in payload' do + expect(data[:builds].count).to eq(1) + expect(build_data[:id]).to eq(build.id) + end + end end end -- GitLab From 008918d3608d2e1f832803875914afb380c3d9e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Tue, 2 Feb 2021 17:45:12 +0100 Subject: [PATCH 2/3] Add CHANGELOG entry --- .../mc-api-pipeline-webhook-remove-retried-jobs.yml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelogs/unreleased/mc-api-pipeline-webhook-remove-retried-jobs.yml diff --git a/changelogs/unreleased/mc-api-pipeline-webhook-remove-retried-jobs.yml b/changelogs/unreleased/mc-api-pipeline-webhook-remove-retried-jobs.yml new file mode 100644 index 00000000000000..f75824b04ceead --- /dev/null +++ b/changelogs/unreleased/mc-api-pipeline-webhook-remove-retried-jobs.yml @@ -0,0 +1,5 @@ +--- +title: Send only latest jobs in pipeline webhook payload. +merge_request: 53159 +author: +type: fixed -- GitLab From 6ee0e543d50d43c142a7b12fca8102550fedefff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20=C4=8Cupi=C4=87?= Date: Sat, 6 Feb 2021 19:58:26 +0100 Subject: [PATCH 3/3] Add documentation blob --- doc/user/project/integrations/webhooks.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/user/project/integrations/webhooks.md b/doc/user/project/integrations/webhooks.md index 27c2cb08d10d10..0cf01adef133d5 100644 --- a/doc/user/project/integrations/webhooks.md +++ b/doc/user/project/integrations/webhooks.md @@ -1029,6 +1029,9 @@ X-Gitlab-Event: Wiki Page Hook ### Pipeline events +In [GitLab 13.9](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/53159) +and later, the pipeline webhook returns only the latest jobs. + Triggered on status change of Pipeline. **Request Header**: -- GitLab