Merge ~ines-almeida/launchpad:add-bug-webhooks/add-tags-to-payload into launchpad:master

Proposed by Ines Almeida
Status: Merged
Approved by: Ines Almeida
Approved revision: 2442b25f789d5d4614324ffacb3c4ba1458678da
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~ines-almeida/launchpad:add-bug-webhooks/add-tags-to-payload
Merge into: launchpad:master
Diff against target: 74 lines (+36/-1)
3 files modified
lib/lp/bugs/subscribers/bugactivity.py (+2/-0)
lib/lp/bugs/subscribers/webhooks.py (+1/-1)
lib/lp/bugs/tests/test_subscribers.py (+33/-0)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+446380@code.launchpad.net

Commit message

Add tags to payload and trigger events on tags changed

Description of the change

The reason why the `tags` events were not worked previously was because `get_string_representation()` wasn't returning representations of lists. This is fixed by this change, plus we now send the `tags` field within the payload for bug webhooks

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/bugs/subscribers/bugactivity.py b/lib/lp/bugs/subscribers/bugactivity.py
2index d1d1bc8..51bbf7d 100644
3--- a/lib/lp/bugs/subscribers/bugactivity.py
4+++ b/lib/lp/bugs/subscribers/bugactivity.py
5@@ -57,6 +57,8 @@ def get_string_representation(obj):
6 return obj
7 elif isinstance(obj, bool):
8 return str(obj)
9+ elif isinstance(obj, list):
10+ return ", ".join(obj)
11 else:
12 return None
13
14diff --git a/lib/lp/bugs/subscribers/webhooks.py b/lib/lp/bugs/subscribers/webhooks.py
15index 43a51c2..7f5b16c 100644
16--- a/lib/lp/bugs/subscribers/webhooks.py
17+++ b/lib/lp/bugs/subscribers/webhooks.py
18@@ -81,7 +81,7 @@ def get_bugtask_attributes(bugtask: IBugTask, bug: IBug):
19 data = compose_webhook_payload(
20 IBug,
21 bug,
22- ["title", "description", "owner"],
23+ ["title", "description", "owner", "tags"],
24 preferred_names={"owner": "reporter"},
25 )
26 data.update(
27diff --git a/lib/lp/bugs/tests/test_subscribers.py b/lib/lp/bugs/tests/test_subscribers.py
28index f6fce0d..4ebf04a 100644
29--- a/lib/lp/bugs/tests/test_subscribers.py
30+++ b/lib/lp/bugs/tests/test_subscribers.py
31@@ -109,6 +109,7 @@ class TestBugWebhooksTriggered(TestCaseWithFactory):
32 "importance": Equals(bugtask.importance.title),
33 "assignee": Equals(assignee),
34 "date_created": Equals(bugtask.datecreated.isoformat()),
35+ "tags": Equals(bugtask.bug.tags),
36 }
37
38 expected_payload = {
39@@ -225,3 +226,35 @@ class TestBugWebhooksTriggered(TestCaseWithFactory):
40 self._assert_last_webhook_delivery(
41 comment_hook, "bug:comment:0.1", c_exptd_payload
42 )
43+
44+ def test_tagging_bug_triggers_webhooks(self):
45+ """Adding bug tags will trigger webhook"""
46+ bug = self.bugtask.bug
47+ with person_logged_in(self.owner), notify_modified(
48+ bug, ["tags"], user=self.owner
49+ ):
50+ bug.tags = ["foo", "bar"]
51+ expected_payload = self._build_bugtask_expected_payload(
52+ self.bugtask, "tags-changed", {"tags": []}
53+ )
54+ self._assert_last_webhook_delivery(
55+ self.hook, "bug:0.1", expected_payload
56+ )
57+
58+ def test_tags_changed_triggers_webhooks(self):
59+ """Modifying the bug tags will trigger webhook"""
60+ bug = self.bugtask.bug
61+
62+ with person_logged_in(bug.owner):
63+ bug.tags = ["foo"]
64+
65+ with person_logged_in(self.owner), notify_modified(
66+ bug, ["tags"], user=self.owner
67+ ):
68+ bug.tags = ["bar", "test"]
69+ expected_payload = self._build_bugtask_expected_payload(
70+ self.bugtask, "tags-changed", {"tags": ["foo"]}
71+ )
72+ self._assert_last_webhook_delivery(
73+ self.hook, "bug:0.1", expected_payload
74+ )

Subscribers

People subscribed via source and target branches

to status/vote changes: