← Back to team overview

launchpad-reviewers team mailing list archive

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

 

Ines Almeida has proposed merging ~ines-almeida/launchpad:add-bug-webhooks/add-tags-to-payload into launchpad:master.

Commit message:
Add tags to payload and trigger events on tags changed

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~ines-almeida/launchpad/+git/launchpad/+merge/446380

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
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~ines-almeida/launchpad:add-bug-webhooks/add-tags-to-payload into launchpad:master.
diff --git a/lib/lp/bugs/subscribers/bugactivity.py b/lib/lp/bugs/subscribers/bugactivity.py
index d1d1bc8..f67491c 100644
--- a/lib/lp/bugs/subscribers/bugactivity.py
+++ b/lib/lp/bugs/subscribers/bugactivity.py
@@ -1,6 +1,8 @@
 # Copyright 2009-2016 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
+from typing import List
+
 from lazr.enum import BaseItem
 from zope.component import getUtility
 from zope.proxy import isProxy
@@ -57,6 +59,8 @@ def get_string_representation(obj):
         return obj
     elif isinstance(obj, bool):
         return str(obj)
+    elif isinstance(obj, List):
+        return ", ".join(obj)
     else:
         return None
 
diff --git a/lib/lp/bugs/subscribers/webhooks.py b/lib/lp/bugs/subscribers/webhooks.py
index 43a51c2..7f5b16c 100644
--- a/lib/lp/bugs/subscribers/webhooks.py
+++ b/lib/lp/bugs/subscribers/webhooks.py
@@ -81,7 +81,7 @@ def get_bugtask_attributes(bugtask: IBugTask, bug: IBug):
     data = compose_webhook_payload(
         IBug,
         bug,
-        ["title", "description", "owner"],
+        ["title", "description", "owner", "tags"],
         preferred_names={"owner": "reporter"},
     )
     data.update(
diff --git a/lib/lp/bugs/tests/test_subscribers.py b/lib/lp/bugs/tests/test_subscribers.py
index f6fce0d..5a7362b 100644
--- a/lib/lp/bugs/tests/test_subscribers.py
+++ b/lib/lp/bugs/tests/test_subscribers.py
@@ -109,6 +109,7 @@ class TestBugWebhooksTriggered(TestCaseWithFactory):
             "importance": Equals(bugtask.importance.title),
             "assignee": Equals(assignee),
             "date_created": Equals(bugtask.datecreated.isoformat()),
+            "tags": Equals(bugtask.bug.tags),
         }
 
         expected_payload = {
@@ -225,3 +226,35 @@ class TestBugWebhooksTriggered(TestCaseWithFactory):
         self._assert_last_webhook_delivery(
             comment_hook, "bug:comment:0.1", c_exptd_payload
         )
+
+    def test_tagging_bug_trigers_webhooks(self):
+        """Adding bug tags will trigger webhook"""
+        bug = self.bugtask.bug
+        with person_logged_in(self.owner), notify_modified(
+            bug, ["tags"], user=self.owner
+        ):
+            bug.tags = ["foo", "bar"]
+        expected_payload = self._build_bugtask_expected_payload(
+            self.bugtask, "tags-changed", {"tags": []}
+        )
+        self._assert_last_webhook_delivery(
+            self.hook, "bug:0.1", expected_payload
+        )
+
+    def test_tags_changed_trigers_webhooks(self):
+        """Modifying the bug tags will trigger webhook"""
+        bug = self.bugtask.bug
+
+        with person_logged_in(bug.owner):
+            bug.tags = ["foo"]
+
+        with person_logged_in(self.owner), notify_modified(
+            bug, ["tags"], user=self.owner
+        ):
+            bug.tags = ["bar", "test"]
+        expected_payload = self._build_bugtask_expected_payload(
+            self.bugtask, "tags-changed", {"tags": ["foo"]}
+        )
+        self._assert_last_webhook_delivery(
+            self.hook, "bug:0.1", expected_payload
+        )