From ac44cb478976474548c0659c821c6fe823a90a3d Mon Sep 17 00:00:00 2001
From: Satyam Bansal <sbansal1999@gmail.com>
Date: Sun, 11 Jun 2023 20:22:46 +0530
Subject: [PATCH] Add pipeline url to webhook payload

Changelog: added
---
 doc/user/project/integrations/webhook_events.md | 3 ++-
 lib/gitlab/data_builder/pipeline.rb             | 3 ++-
 spec/lib/gitlab/data_builder/pipeline_spec.rb   | 1 +
 3 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/doc/user/project/integrations/webhook_events.md b/doc/user/project/integrations/webhook_events.md
index fda778aa167db..bd5baaeb9be50 100644
--- a/doc/user/project/integrations/webhook_events.md
+++ b/doc/user/project/integrations/webhook_events.md
@@ -1142,7 +1142,8 @@ Payload example:
           "key": "NESTOR_PROD_ENVIRONMENT",
           "value": "us-west-1"
         }
-      ]
+      ],
+      "url": "http://example.com/gitlab-org/gitlab-test/-/pipelines/31"
    },
     "merge_request": {
       "id": 1,
diff --git a/lib/gitlab/data_builder/pipeline.rb b/lib/gitlab/data_builder/pipeline.rb
index ecb0cc20a64ee..044d3bb50cd2c 100644
--- a/lib/gitlab/data_builder/pipeline.rb
+++ b/lib/gitlab/data_builder/pipeline.rb
@@ -77,7 +77,8 @@ def hook_attrs(pipeline)
           finished_at: pipeline.finished_at,
           duration: pipeline.duration,
           queued_duration: pipeline.queued_duration,
-          variables: pipeline.variables.map(&:hook_attrs)
+          variables: pipeline.variables.map(&:hook_attrs),
+          url: Gitlab::Routing.url_helpers.project_pipeline_url(pipeline.project, pipeline)
         }
       end
 
diff --git a/spec/lib/gitlab/data_builder/pipeline_spec.rb b/spec/lib/gitlab/data_builder/pipeline_spec.rb
index eb348f5b497ba..a379af7483b92 100644
--- a/spec/lib/gitlab/data_builder/pipeline_spec.rb
+++ b/spec/lib/gitlab/data_builder/pipeline_spec.rb
@@ -33,6 +33,7 @@
       expect(attributes[:iid]).to eq(pipeline.iid)
       expect(attributes[:source]).to eq(pipeline.source)
       expect(attributes[:status]).to eq(pipeline.status)
+      expect(attributes[:url]).to eq(Gitlab::Routing.url_helpers.project_pipeline_url(pipeline.project, pipeline))
       expect(attributes[:detailed_status]).to eq('passed')
       expect(build_data).to be_a(Hash)
       expect(build_data[:id]).to eq(build.id)
-- 
GitLab