From ed8a00b9c41c25af3fcc45892a7d5144d75c6863 Mon Sep 17 00:00:00 2001 From: Sujay Patel Date: Sat, 8 Jun 2019 11:54:20 +0530 Subject: Adding labels to note event payload. --- .../33064-add-labels-to-note-event-payload.yml | 5 ++++ doc/user/project/integrations/webhooks.md | 28 +++++++++++++++++++++- lib/gitlab/data_builder/note.rb | 1 + lib/gitlab/hook_data/issue_builder.rb | 3 ++- spec/lib/gitlab/data_builder/note_spec.rb | 2 ++ 5 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 changelogs/unreleased/33064-add-labels-to-note-event-payload.yml diff --git a/changelogs/unreleased/33064-add-labels-to-note-event-payload.yml b/changelogs/unreleased/33064-add-labels-to-note-event-payload.yml new file mode 100644 index 00000000000..e0a6253e1ef --- /dev/null +++ b/changelogs/unreleased/33064-add-labels-to-note-event-payload.yml @@ -0,0 +1,5 @@ +--- +title: Add labels to note event payload +merge_request: 29384 +author: Sujay Patel +type: added diff --git a/doc/user/project/integrations/webhooks.md b/doc/user/project/integrations/webhooks.md index a0f500a939f..d5f28ddabc1 100644 --- a/doc/user/project/integrations/webhooks.md +++ b/doc/user/project/integrations/webhooks.md @@ -653,7 +653,33 @@ X-Gitlab-Event: Note Hook "description": "test", "milestone_id": null, "state": "closed", - "iid": 17 + "iid": 17, + "labels": [ + { + "id": 25, + "title": "Afterpod", + "color": "#3e8068", + "project_id": null, + "created_at": "2019-06-05T14:32:20.211Z", + "updated_at": "2019-06-05T14:32:20.211Z", + "template": false, + "description": null, + "type": "GroupLabel", + "group_id": 4 + }, + { + "id": 86, + "title": "Element", + "color": "#231afe", + "project_id": 4, + "created_at": "2019-06-05T14:32:20.637Z", + "updated_at": "2019-06-05T14:32:20.637Z", + "template": false, + "description": null, + "type": "ProjectLabel", + "group_id": null + } + ], } } ``` diff --git a/lib/gitlab/data_builder/note.rb b/lib/gitlab/data_builder/note.rb index 65601dcdf31..16e62622ed4 100644 --- a/lib/gitlab/data_builder/note.rb +++ b/lib/gitlab/data_builder/note.rb @@ -44,6 +44,7 @@ module Gitlab data[:commit] = build_data_for_commit(project, user, note) elsif note.for_issue? data[:issue] = note.noteable.hook_attrs + data[:issue][:labels] = note.noteable.labels(&:hook_attrs) elsif note.for_merge_request? data[:merge_request] = note.noteable.hook_attrs elsif note.for_snippet? diff --git a/lib/gitlab/hook_data/issue_builder.rb b/lib/gitlab/hook_data/issue_builder.rb index d39ff8c21cc..cfc9ebe4f92 100644 --- a/lib/gitlab/hook_data/issue_builder.rb +++ b/lib/gitlab/hook_data/issue_builder.rb @@ -44,7 +44,8 @@ module Gitlab human_total_time_spent: issue.human_total_time_spent, human_time_estimate: issue.human_time_estimate, assignee_ids: issue.assignee_ids, - assignee_id: issue.assignee_ids.first # This key is deprecated + assignee_id: issue.assignee_ids.first, # This key is deprecated + labels: issue.labels } issue.attributes.with_indifferent_access.slice(*self.class.safe_hook_attributes) diff --git a/spec/lib/gitlab/data_builder/note_spec.rb b/spec/lib/gitlab/data_builder/note_spec.rb index b236c1a9c49..ed9a1e23529 100644 --- a/spec/lib/gitlab/data_builder/note_spec.rb +++ b/spec/lib/gitlab/data_builder/note_spec.rb @@ -53,6 +53,8 @@ describe Gitlab::DataBuilder::Note do .to eq(issue.reload.hook_attrs.except('updated_at')) expect(data[:issue]['updated_at']) .to be >= issue.hook_attrs['updated_at'] + expect(data[:issue]['labels']) + .to eq(issue.hook_attrs['labels']) end context 'with confidential issue' do -- cgit v1.2.1