Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

integrations: Delete the Pivotal webhook integration.

Niloth P8b714ba56bca
diff --git a/static/images/integrations/bot_avatars/pivotal.png b/static/images/integrations/bot_avatars/pivotal.png
deleted file mode 100644
index 01a2c4f4f7a..00000000000
Binary files a/static/images/integrations/bot_avatars/pivotal.png and /dev/null differ
diff --git a/static/images/integrations/logos/pivotal.svg b/static/images/integrations/logos/pivotal.svg
deleted file mode 100644
index 42e8cf384d0..00000000000
--- a/static/images/integrations/logos/pivotal.svg
+++ /dev/null
@@ -1 +0,0 @@
-<svg xmlns="http://www.w3.org/2000/svg" width="120" height="120"><path d="M51.129 119.067c-23.217-3.64-42.207-20.523-48.99-43.554-2.81-9.545-2.406-24.04.946-33.828 4.443-12.979 11.507-22.62 22.117-30.192C47.657-4.53 76.249-3.26 98.524 14.75c11.952 9.663 21.203 29.411 21.203 45.263 0 5.965-2.783 18.46-5.427 24.368-10.566 23.608-37.945 38.642-63.171 34.686zm20.056-12.586c17.247-4.492 30.533-17.82 35.05-35.162 6.477-24.867-9.44-51.105-35.05-57.775-25.023-6.518-51.237 9.325-57.927 35.01-8.913 34.22 23.708 66.84 57.927 57.927zm-16.834-16.15-5.502-9.68 3.189-5.848c2.574-4.72 3.574-5.748 5.189-5.332 1.1.283 2.748.52 3.662.528 1.073.009 3.854 3.946 7.838 11.093 3.395 6.094 6.022 11.203 5.837 11.353-.978.794-13.618 7.568-14.12 7.568-.325 0-3.066-4.357-6.093-9.681zm-22.817-5.46-6.692-3.956 6.011-9.951 6.012-9.951h6.246c6.072 0 6.289.09 7.808 3.277 1.56 3.272 1.554 3.29-4.566 13.667-3.37 5.714-6.578 10.498-7.127 10.63-.55.132-4.01-1.54-7.692-3.716zm37.268-10.536c-1.692-3.123-3.06-5.935-3.042-6.25.018-.315.878-1.585 1.91-2.822 1.764-2.115 2.634-2.25 14.467-2.25h12.59v17h-22.85l-3.075-5.678zm-.816-18.446c-1.104-2.926-.824-3.733 4.433-12.75 3.086-5.295 6.027-10.163 6.535-10.82.681-.88 2.674-.127 7.598 2.869 3.671 2.234 6.85 4.22 7.064 4.416.214.195-2.169 4.641-5.296 9.881l-5.685 9.528H75.9c-6.624 0-6.754-.052-7.914-3.124zm-43.26-6.376v-8.5h22.722l3.056 5.75 3.056 5.75-2.204 2.75c-2.188 2.73-2.295 2.75-14.417 2.75H24.727v-8.5zm26.1-9.562c-3.47-6.084-6.069-11.302-5.776-11.595.91-.91 13.96-8.4 14.136-8.114 2.791 4.512 10.54 19.03 10.54 19.748 0 .546-1.388 3.25-3.085 6.008-2.67 4.337-3.52 5.015-6.296 5.015-3.04 0-3.545-.587-9.519-11.062z" fill="#5183af"/><path d="M54.351 90.332 48.85 80.65l3.189-5.847c2.574-4.72 3.574-5.748 5.189-5.332 1.1.283 2.748.52 3.662.528 1.073.009 3.854 3.946 7.838 11.093 3.395 6.094 6.022 11.203 5.837 11.353-.978.794-13.618 7.568-14.12 7.568-.325 0-3.066-4.357-6.093-9.681zm-22.817-5.46-6.692-3.957 6.011-9.951 6.012-9.951h6.246c6.072 0 6.289.09 7.808 3.277 1.56 3.272 1.554 3.29-4.566 13.667-3.37 5.714-6.578 10.498-7.127 10.63-.55.132-4.01-1.54-7.692-3.716zm37.268-10.537c-1.692-3.123-3.06-5.935-3.042-6.25.018-.315.878-1.585 1.91-2.822 1.764-2.115 2.634-2.25 14.467-2.25h12.59v17h-22.85l-3.075-5.678zm-.816-18.446c-1.104-2.926-.824-3.733 4.433-12.75 3.086-5.295 6.027-10.163 6.535-10.82.681-.88 2.674-.127 7.598 2.869 3.671 2.234 6.85 4.22 7.064 4.416.214.195-2.169 4.641-5.296 9.881l-5.685 9.528H75.9c-6.624 0-6.754-.052-7.914-3.124zm-43.26-6.376v-8.5h22.722l3.056 5.75 3.056 5.75-2.204 2.75c-2.188 2.73-2.295 2.75-14.417 2.75H24.727v-8.5zm26.1-9.562c-3.47-6.084-6.069-11.302-5.776-11.595.91-.91 13.96-8.4 14.136-8.114 2.791 4.512 10.54 19.03 10.54 19.748 0 .546-1.388 3.25-3.085 6.008-2.67 4.337-3.52 5.015-6.296 5.015-3.04 0-3.545-.587-9.519-11.062z" fill="#ea7c1a"/></svg>
\ No newline at end of file
diff --git a/static/images/integrations/pivotal/001.png b/static/images/integrations/pivotal/001.png
deleted file mode 100644
index ae24737d4b5..00000000000
Binary files a/static/images/integrations/pivotal/001.png and /dev/null differ
diff --git a/tools/lib/capitalization.py b/tools/lib/capitalization.py
index f42d50031bb..1b77517c50f 100644
--- a/tools/lib/capitalization.py
+++ b/tools/lib/capitalization.py
@@ -36,7 +36,6 @@ IGNORED_PHRASES = [
r"Markdown",
r"OAuth",
r"OTP",
- r"Pivotal",
r"Recent conversations",
r"DM",
r"DMs",
diff --git a/zerver/lib/integrations.py b/zerver/lib/integrations.py
index bc1faf05bd4..0a4a19f0fca 100644
--- a/zerver/lib/integrations.py
+++ b/zerver/lib/integrations.py
@@ -825,12 +825,6 @@ INCOMING_WEBHOOK_INTEGRATIONS: list[IncomingWebhookIntegration] = [
IncomingWebhookIntegration(
"pingdom", ["monitoring"], [WebhookScreenshotConfig("http_up_to_down.json")]
),
- IncomingWebhookIntegration(
- "pivotal",
- ["project-management"],
- [WebhookScreenshotConfig("v5_type_changed.json")],
- display_name="Pivotal Tracker",
- ),
IncomingWebhookIntegration(
"radarr", ["entertainment"], [WebhookScreenshotConfig("radarr_movie_grabbed.json")]
),
diff --git a/zerver/webhooks/pivotal/__init__.py b/zerver/webhooks/pivotal/__init__.py
deleted file mode 100644
index e69de29bb2d..00000000000
diff --git a/zerver/webhooks/pivotal/doc.md b/zerver/webhooks/pivotal/doc.md
deleted file mode 100644
index 3ef78feb65f..00000000000
--- a/zerver/webhooks/pivotal/doc.md
+++ /dev/null
@@ -1,31 +0,0 @@
-# Zulip Pivotal integration
-
-Get Zulip notifications for the stories in your Pivotal Tracker project!
-
-{start_tabs}
-
-1. {!create-an-incoming-webhook.md!}
-
-1. {!generate-webhook-url-basic.md!}
-
-1. From your Pivotal project's **Settings** page, click on **Webhooks**.
-
-1. Under **Activity Web Hook**, provide the URL generated above.
- Choose version 5 (`v5`) of the API. Click **Add**.
-
- !!! warn ""
-
- **Note:** Zulip supports both version 3 and version 5, but version
- 5 contains more information and allows Zulip to format more useful messages.
-
-{end_tabs}
-
-{!congrats.md!}
-
-![](/static/images/integrations/pivotal/001.png)
-
-{!event-filtering-additional-feature.md!}
-
-### Related documentation
-
-{!webhooks-url-specification.md!}
diff --git a/zerver/webhooks/pivotal/fixtures/accepted.xml b/zerver/webhooks/pivotal/fixtures/accepted.xml
deleted file mode 100644
index 77f958df52c..00000000000
--- a/zerver/webhooks/pivotal/fixtures/accepted.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<activity>
- <id type="integer">346167313</id>
- <version type="integer">11</version>
- <event_type>story_update</event_type>
- <occurred_at type="datetime">2013/04/17 20:18:54 UTC</occurred_at>
- <author>Leo Franchi</author>
- <project_id type="integer">807213</project_id>
- <description>Leo Franchi accepted &quot;My new Feature story&quot;</description>
- <stories type="array">
- <story>
- <id type="integer">48276573</id>
- <url>http://www.pivotaltracker.com/services/v3/projects/807213/stories/48276573</url>
- <story_type>bug</story_type>
- <accepted_at type="datetime">2013/04/17 20:18:54 UTC</accepted_at>
- <labels>website</labels>
- <current_state>accepted</current_state>
- <owned_by>Leo Franchi</owned_by>
- </story>
- </stories>
-</activity>
diff --git a/zerver/webhooks/pivotal/fixtures/bad_accepted.xml b/zerver/webhooks/pivotal/fixtures/bad_accepted.xml
deleted file mode 100644
index ff5d1f939bb..00000000000
--- a/zerver/webhooks/pivotal/fixtures/bad_accepted.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<activity>
- <id type="integer">346167313</id>
- <version type="integer">11</version>
- <event_type>story_update</event_type>
- <occurred_at type="datetime">2013/04/17 20:18:54 UTC</occurred_at>
- <author>Leo Franchi</author>
- <project_id type="integer">807213</project_id>
- <description>Leo Franchi accepted My new Feature story</description>
- <stories type="array">
- <story>
- <id type="integer">48276573</id>
- <url>http://www.pivotaltracker.com/services/v3/projects/807213/stories/48276573</url>
- <story_type>bug</story_type>
- <accepted_at type="datetime">2013/04/17 20:18:54 UTC</accepted_at>
- <labels>website</labels>
- <current_state>accepted</current_state>
- <owned_by>Leo Franchi</owned_by>
- </story>
- </stories>
-</activity>
diff --git a/zerver/webhooks/pivotal/fixtures/commented.xml b/zerver/webhooks/pivotal/fixtures/commented.xml
deleted file mode 100644
index 52766051fce..00000000000
--- a/zerver/webhooks/pivotal/fixtures/commented.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<activity>
- <id type="integer">346163343</id>
- <version type="integer">5</version>
- <event_type>note_create</event_type>
- <occurred_at type="datetime">2013/04/17 20:12:12 UTC</occurred_at>
- <author>Leo Franchi</author>
- <project_id type="integer">807213</project_id>
- <description>Leo Franchi added comment: &quot;FIX THIS NOW&quot;</description>
- <stories type="array">
- <story>
- <id type="integer">48276573</id>
- <url>http://www.pivotaltracker.com/services/v3/projects/807213/stories/48276573</url>
- <notes type="array">
- <note>
- <id type="integer">41169355</id>
- <text>FIX THIS NOW</text>
- </note>
- </notes>
- </story>
- </stories>
-</activity>
diff --git a/zerver/webhooks/pivotal/fixtures/created.xml b/zerver/webhooks/pivotal/fixtures/created.xml
deleted file mode 100644
index 269c283dc0f..00000000000
--- a/zerver/webhooks/pivotal/fixtures/created.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<activity>
- <id type="integer">346161339</id>
- <version type="integer">2</version>
- <event_type>story_create</event_type>
- <occurred_at type="datetime">2013/04/17 20:09:17 UTC</occurred_at>
- <author>Leo Franchi</author>
- <project_id type="integer">807213</project_id>
- <description>Leo Franchi added &quot;My new Feature story&quot;</description>
- <stories type="array">
- <story>
- <id type="integer">48276573</id>
- <url>http://www.pivotaltracker.com/services/v3/projects/807213/stories/48276573</url>
- <name>My new Feature story</name>
- <story_type>feature</story_type>
- <description>This is my long description</description>
- <current_state>unscheduled</current_state>
- <requested_by>Leo Franchi</requested_by>
- </story>
- </stories>
-</activity>
diff --git a/zerver/webhooks/pivotal/fixtures/created_estimate.xml b/zerver/webhooks/pivotal/fixtures/created_estimate.xml
deleted file mode 100644
index e71b7c67c31..00000000000
--- a/zerver/webhooks/pivotal/fixtures/created_estimate.xml
+++ /dev/null
@@ -1,22 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<activity>
- <id type="integer">346174097</id>
- <version type="integer">16</version>
- <event_type>story_create</event_type>
- <occurred_at type="datetime">2013/04/17 20:28:52 UTC</occurred_at>
- <author>Leo Franchi</author>
- <project_id type="integer">807213</project_id>
- <description>Leo Franchi added &quot;Another new story&quot;</description>
- <stories type="array">
- <story>
- <id type="integer">48278289</id>
- <url>http://www.pivotaltracker.com/services/v3/projects/807213/stories/48278289</url>
- <name>Another new story</name>
- <story_type>feature</story_type>
- <description>Some loong description</description>
- <estimate type="integer">2</estimate>
- <current_state>unscheduled</current_state>
- <requested_by>Leo Franchi</requested_by>
- </story>
- </stories>
-</activity>
diff --git a/zerver/webhooks/pivotal/fixtures/delivered.xml b/zerver/webhooks/pivotal/fixtures/delivered.xml
deleted file mode 100644
index da69f89341e..00000000000
--- a/zerver/webhooks/pivotal/fixtures/delivered.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<activity>
- <id type="integer">346177011</id>
- <version type="integer">22</version>
- <event_type>story_update</event_type>
- <occurred_at type="datetime">2013/04/17 20:32:51 UTC</occurred_at>
- <author>Leo Franchi</author>
- <project_id type="integer">807213</project_id>
- <description>Leo Franchi delivered &quot;Another new story&quot;</description>
- <stories type="array">
- <story>
- <id type="integer">48278289</id>
- <url>http://www.pivotaltracker.com/services/v3/projects/807213/stories/48278289</url>
- <current_state>delivered</current_state>
- </story>
- </stories>
-</activity>
diff --git a/zerver/webhooks/pivotal/fixtures/finished.xml b/zerver/webhooks/pivotal/fixtures/finished.xml
deleted file mode 100644
index ba40b1b49de..00000000000
--- a/zerver/webhooks/pivotal/fixtures/finished.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<activity>
- <id type="integer">346176787</id>
- <version type="integer">21</version>
- <event_type>story_update</event_type>
- <occurred_at type="datetime">2013/04/17 20:32:31 UTC</occurred_at>
- <author>Leo Franchi</author>
- <project_id type="integer">807213</project_id>
- <description>Leo Franchi finished &quot;Another new story&quot;</description>
- <stories type="array">
- <story>
- <id type="integer">48278289</id>
- <url>http://www.pivotaltracker.com/services/v3/projects/807213/stories/48278289</url>
- <current_state>finished</current_state>
- </story>
- </stories>
-</activity>
diff --git a/zerver/webhooks/pivotal/fixtures/moved.xml b/zerver/webhooks/pivotal/fixtures/moved.xml
deleted file mode 100644
index 049a6b24e87..00000000000
--- a/zerver/webhooks/pivotal/fixtures/moved.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<activity>
- <id type="integer">346162723</id>
- <version type="integer">3</version>
- <event_type>story_update</event_type>
- <occurred_at type="datetime">2013/04/17 20:11:18 UTC</occurred_at>
- <author>Leo Franchi</author>
- <project_id type="integer">807213</project_id>
- <description>Leo Franchi edited &quot;My new Feature story&quot;</description>
- <stories type="array">
- <story>
- <id type="integer">48276573</id>
- <url>http://www.pivotaltracker.com/services/v3/projects/807213/stories/48276573</url>
- <current_state>unstarted</current_state>
- </story>
- </stories>
-</activity>
diff --git a/zerver/webhooks/pivotal/fixtures/rejected.xml b/zerver/webhooks/pivotal/fixtures/rejected.xml
deleted file mode 100644
index f6dacc78e4e..00000000000
--- a/zerver/webhooks/pivotal/fixtures/rejected.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<activity>
- <id type="integer">346177291</id>
- <version type="integer">23</version>
- <event_type>story_update</event_type>
- <occurred_at type="datetime">2013/04/17 20:33:16 UTC</occurred_at>
- <author>Leo Franchi</author>
- <project_id type="integer">807213</project_id>
- <description>Leo Franchi rejected &quot;Another new story&quot; with comments: &quot;Not good enough, sorry&quot;</description>
- <stories type="array">
- <story>
- <id type="integer">48278289</id>
- <url>http://www.pivotaltracker.com/services/v3/projects/807213/stories/48278289</url>
- <current_state>rejected</current_state>
- </story>
- </stories>
-</activity>
diff --git a/zerver/webhooks/pivotal/fixtures/started.xml b/zerver/webhooks/pivotal/fixtures/started.xml
deleted file mode 100644
index 2f3de06f865..00000000000
--- a/zerver/webhooks/pivotal/fixtures/started.xml
+++ /dev/null
@@ -1,18 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<activity>
- <id type="integer">346176439</id>
- <version type="integer">20</version>
- <event_type>story_update</event_type>
- <occurred_at type="datetime">2013/04/17 20:32:03 UTC</occurred_at>
- <author>Leo Franchi</author>
- <project_id type="integer">807213</project_id>
- <description>Leo Franchi started &quot;Another new story&quot;</description>
- <stories type="array">
- <story>
- <id type="integer">48278289</id>
- <url>http://www.pivotaltracker.com/services/v3/projects/807213/stories/48278289</url>
- <current_state>started</current_state>
- <owned_by>Leo Franchi</owned_by>
- </story>
- </stories>
-</activity>
diff --git a/zerver/webhooks/pivotal/fixtures/type_changed.xml b/zerver/webhooks/pivotal/fixtures/type_changed.xml
deleted file mode 100644
index 7c39cb9a2f6..00000000000
--- a/zerver/webhooks/pivotal/fixtures/type_changed.xml
+++ /dev/null
@@ -1,17 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<activity>
- <id type="integer">346170371</id>
- <version type="integer">14</version>
- <event_type>story_update</event_type>
- <occurred_at type="datetime">2013/04/17 20:23:23 UTC</occurred_at>
- <author>Leo Franchi</author>
- <project_id type="integer">807213</project_id>
- <description>Leo Franchi edited &quot;My new Feature story&quot;</description>
- <stories type="array">
- <story>
- <id type="integer">48276573</id>
- <url>http://www.pivotaltracker.com/services/v3/projects/807213/stories/48276573</url>
- <story_type>chore</story_type>
- </story>
- </stories>
-</activity>
diff --git a/zerver/webhooks/pivotal/fixtures/v5_accepted.json b/zerver/webhooks/pivotal/fixtures/v5_accepted.json
deleted file mode 100644
index 51d8af0b500..00000000000
--- a/zerver/webhooks/pivotal/fixtures/v5_accepted.json
+++ /dev/null
@@ -1,47 +0,0 @@
-{
- "occurred_at": 1389218398000,
- "kind": "story_update_activity",
- "project": {
- "name": "Hard Code",
- "kind": "project",
- "id": 807213
- },
- "changes": [
- {
- "name": "Story of the Year",
- "story_type": "feature",
- "change_type": "update",
- "kind": "story",
- "new_values": {
- "current_state": "accepted",
- "updated_at": 1389218398000,
- "accepted_at": 1389218397000
- },
- "id": 63486316,
- "original_values": {
- "current_state": "unstarted",
- "updated_at": 1389215951000,
- "accepted_at": null
- }
- }
- ],
- "highlight": "accepted",
- "project_version": 60,
- "guid": "807213_60",
- "primary_resources": [
- {
- "name": "Story of the Year",
- "story_type": "feature",
- "kind": "story",
- "id": 63486316,
- "url": "http://www.pivotaltracker.com/story/show/63486316"
- }
- ],
- "performed_by": {
- "name": "Leo Franchi",
- "initials": "LF",
- "kind": "person",
- "id": 981905
- },
- "message": "Leo Franchi accepted this feature"
-}
diff --git a/zerver/webhooks/pivotal/fixtures/v5_bad_kind.json b/zerver/webhooks/pivotal/fixtures/v5_bad_kind.json
deleted file mode 100644
index deab206cc70..00000000000
--- a/zerver/webhooks/pivotal/fixtures/v5_bad_kind.json
+++ /dev/null
@@ -1,47 +0,0 @@
-{
- "occurred_at": 1389218398000,
- "kind": "unknown_kind",
- "project": {
- "name": "Hard Code",
- "kind": "project",
- "id": 807213
- },
- "changes": [
- {
- "name": "Story of the Year",
- "story_type": "feature",
- "change_type": "update",
- "kind": "story",
- "new_values": {
- "current_state": "accepted",
- "updated_at": 1389218398000,
- "accepted_at": 1389218397000
- },
- "id": 63486316,
- "original_values": {
- "current_state": "unstarted",
- "updated_at": 1389215951000,
- "accepted_at": null
- }
- }
- ],
- "highlight": "accepted",
- "project_version": 60,
- "guid": "807213_60",
- "primary_resources": [
- {
- "name": "Story of the Year",
- "story_type": "feature",
- "kind": "story",
- "id": 63486316,
- "url": "http://www.pivotaltracker.com/story/show/63486316"
- }
- ],
- "performed_by": {
- "name": "Leo Franchi",
- "initials": "LF",
- "kind": "person",
- "id": 981905
- },
- "message": "Leo Franchi accepted this feature"
-}
diff --git a/zerver/webhooks/pivotal/fixtures/v5_bad_request.json b/zerver/webhooks/pivotal/fixtures/v5_bad_request.json
deleted file mode 100644
index ea33ef01148..00000000000
--- a/zerver/webhooks/pivotal/fixtures/v5_bad_request.json
+++ /dev/null
@@ -1,16 +0,0 @@
-{
- "occurred_at": 1389218398000,
- "kind": "epic_update_activity",
- "project": {
- "name": "",
- "id": ""
- },
- "primary_resources": [
- {
- "url": "",
- "id": 0,
- "name": ""
- }
- ],
- "msg": "foo"
-}
diff --git a/zerver/webhooks/pivotal/fixtures/v5_commented.json b/zerver/webhooks/pivotal/fixtures/v5_commented.json
deleted file mode 100644
index 0a29bb8555e..00000000000
--- a/zerver/webhooks/pivotal/fixtures/v5_commented.json
+++ /dev/null
@@ -1,68 +0,0 @@
-{
- "message": "Leo Franchi added comment: \"A comment on the story\"",
- "primary_resources": [
- {
- "url": "http://www.pivotaltracker.com/story/show/63486316",
- "kind": "story",
- "story_type": "feature",
- "id": 63486316,
- "name": "Story of the Year"
- }
- ],
- "guid": "807213_61",
- "kind": "comment_create_activity",
- "project": {
- "kind": "project",
- "id": 807213,
- "name": "Hard Code"
- },
- "occurred_at": 1389218474000,
- "performed_by": {
- "initials": "LF",
- "kind": "person",
- "id": 981905,
- "name": "Leo Franchi"
- },
- "changes": [
- {
- "kind": "comment",
- "id": 59124096,
- "change_type": "create",
- "new_values": {
- "story_id": 63486316,
- "file_attachment_ids": [
-
- ],
- "google_attachment_ids": [
-
- ],
- "updated_at": 1389218474000,
- "created_at": 1389218474000,
- "google_attachments": [
-
- ],
- "file_attachments": [
-
- ],
- "text": "A comment on the story",
- "id": 59124096,
- "person_id": 981905
- }
- },
- {
- "kind": "story",
- "story_type": "feature",
- "change_type": "update",
- "id": 63486316,
- "original_values": {
- "updated_at": 1389218398000
- },
- "new_values": {
- "updated_at": 1389218474000
- },
- "name": "Story of the Year"
- }
- ],
- "project_version": 61,
- "highlight": "added comment:"
-}
diff --git a/zerver/webhooks/pivotal/fixtures/v5_created.json b/zerver/webhooks/pivotal/fixtures/v5_created.json
deleted file mode 100644
index 3a1f51022d1..00000000000
--- a/zerver/webhooks/pivotal/fixtures/v5_created.json
+++ /dev/null
@@ -1,59 +0,0 @@
-{
- "project": {
- "id": 807213,
- "name": "Hard Code",
- "kind": "project"
- },
- "guid": "807213_62",
- "project_version": 62,
- "highlight": "added",
- "occurred_at": 1389218525000,
- "performed_by": {
- "id": 981905,
- "name": "Leo Franchi",
- "initials": "LF",
- "kind": "person"
- },
- "primary_resources": [
- {
- "id": 63495662,
- "story_type": "bug",
- "url": "http://www.pivotaltracker.com/story/show/63495662",
- "name": "Story that I created",
- "kind": "story"
- }
- ],
- "message": "Leo Franchi added this bug",
- "changes": [
- {
- "id": 63495662,
- "story_type": "bug",
- "name": "Story that I created",
- "new_values": {
- "current_state": "unscheduled",
- "after_id": 63486316,
- "id": 63495662,
- "requested_by_id": 981905,
- "follower_ids": [
-
- ],
- "story_type": "bug",
- "name": "Story that I created",
- "project_id": 807213,
- "description": "What a description",
- "labels": [
-
- ],
- "created_at": 1389218525000,
- "updated_at": 1389218525000,
- "label_ids": [
-
- ],
- "before_id": 48420109
- },
- "change_type": "create",
- "kind": "story"
- }
- ],
- "kind": "story_create_activity"
-}
diff --git a/zerver/webhooks/pivotal/fixtures/v5_created_estimate.json b/zerver/webhooks/pivotal/fixtures/v5_created_estimate.json
deleted file mode 100644
index 182d7d5aaeb..00000000000
--- a/zerver/webhooks/pivotal/fixtures/v5_created_estimate.json
+++ /dev/null
@@ -1,45 +0,0 @@
-{
- "occurred_at": 1389218976000,
- "kind": "story_update_activity",
- "project": {
- "name": "Hard Code",
- "kind": "project",
- "id": 807213
- },
- "changes": [
- {
- "name": "Pivotal Test",
- "story_type": "feature",
- "change_type": "update",
- "kind": "story",
- "new_values": {
- "estimate": 3,
- "updated_at": 1389218976000
- },
- "id": 63496066,
- "original_values": {
- "estimate": null,
- "updated_at": 1389218941000
- }
- }
- ],
- "highlight": "estimated",
- "project_version": 81,
- "guid": "807213_81",
- "primary_resources": [
- {
- "name": "Pivotal Test",
- "story_type": "feature",
- "kind": "story",
- "id": 63496066,
- "url": "http://www.pivotaltracker.com/story/show/63496066"
- }
- ],
- "performed_by": {
- "name": "Leo Franchi",
- "initials": "LF",
- "kind": "person",
- "id": 981905
- },
- "message": "Leo Franchi estimated this feature as 3 points"
-}
diff --git a/zerver/webhooks/pivotal/fixtures/v5_delivered.json b/zerver/webhooks/pivotal/fixtures/v5_delivered.json
deleted file mode 100644
index 8d99b576764..00000000000
--- a/zerver/webhooks/pivotal/fixtures/v5_delivered.json
+++ /dev/null
@@ -1,47 +0,0 @@
-{
- "message": "Leo Franchi delivered this feature",
- "primary_resources": [
- {
- "url": "http://www.pivotaltracker.com/story/show/63486316",
- "kind": "story",
- "story_type": "feature",
- "id": 63486316,
- "name": "Story of the Year"
- }
- ],
- "guid": "807213_64",
- "kind": "story_update_activity",
- "project": {
- "kind": "project",
- "id": 807213,
- "name": "Hard Code"
- },
- "occurred_at": 1389218691000,
- "performed_by": {
- "initials": "LF",
- "kind": "person",
- "id": 981905,
- "name": "Leo Franchi"
- },
- "changes": [
- {
- "kind": "story",
- "story_type": "feature",
- "change_type": "update",
- "id": 63486316,
- "original_values": {
- "current_state": "accepted",
- "accepted_at": 1389218632000,
- "updated_at": 1389218645000
- },
- "new_values": {
- "current_state": "delivered",
- "accepted_at": null,
- "updated_at": 1389218691000
- },
- "name": "Story of the Year"
- }
- ],
- "project_version": 64,
- "highlight": "delivered"
-}
diff --git a/zerver/webhooks/pivotal/fixtures/v5_finished.json b/zerver/webhooks/pivotal/fixtures/v5_finished.json
deleted file mode 100644
index cd7ae925d2b..00000000000
--- a/zerver/webhooks/pivotal/fixtures/v5_finished.json
+++ /dev/null
@@ -1,47 +0,0 @@
-{
- "performed_by": {
- "name": "Leo Franchi",
- "id": 981905,
- "initials": "LF",
- "kind": "person"
- },
- "changes": [
- {
- "new_values": {
- "updated_at": 1389218709000,
- "accepted_at": 1389218708000,
- "current_state": "accepted"
- },
- "story_type": "feature",
- "name": "Story of the Year",
- "id": 63486316,
- "kind": "story",
- "change_type": "update",
- "original_values": {
- "updated_at": 1389218691000,
- "accepted_at": null,
- "current_state": "delivered"
- }
- }
- ],
- "project": {
- "name": "Hard Code",
- "id": 807213,
- "kind": "project"
- },
- "primary_resources": [
- {
- "story_type": "feature",
- "url": "http://www.pivotaltracker.com/story/show/63486316",
- "id": 63486316,
- "name": "Story of the Year",
- "kind": "story"
- }
- ],
- "highlight": "accepted",
- "project_version": 65,
- "message": "Leo Franchi accepted this feature",
- "occurred_at": 1389218709000,
- "guid": "807213_65",
- "kind": "story_update_activity"
-}
diff --git a/zerver/webhooks/pivotal/fixtures/v5_moved.json b/zerver/webhooks/pivotal/fixtures/v5_moved.json
deleted file mode 100644
index c4e6e3904ff..00000000000
--- a/zerver/webhooks/pivotal/fixtures/v5_moved.json
+++ /dev/null
@@ -1,49 +0,0 @@
-{
- "project": {
- "id": 807213,
- "name": "Hard Code",
- "kind": "project"
- },
- "guid": "807213_84",
- "project_version": 84,
- "highlight": "moved",
- "occurred_at": 1389282538000,
- "performed_by": {
- "id": 981905,
- "name": "Leo Franchi",
- "initials": "LF",
- "kind": "person"
- },
- "primary_resources": [
- {
- "id": 63496066,
- "story_type": "bug",
- "url": "http://www.pivotaltracker.com/story/show/63496066",
- "name": "Pivotal Test",
- "kind": "story"
- }
- ],
- "message": "Leo Franchi moved this story after 'test story'",
- "changes": [
- {
- "id": 63496066,
- "story_type": "bug",
- "name": "Pivotal Test",
- "new_values": {
- "current_state": "unscheduled",
- "after_id": 48326435,
- "updated_at": 1389282537000,
- "before_id": null
- },
- "change_type": "update",
- "original_values": {
- "current_state": "unstarted",
- "after_id": 63495972,
- "updated_at": 1389282533000,
- "before_id": 63495662
- },
- "kind": "story"
- }
- ],
- "kind": "story_move_activity"
-}
diff --git a/zerver/webhooks/pivotal/fixtures/v5_rejected.json b/zerver/webhooks/pivotal/fixtures/v5_rejected.json
deleted file mode 100644
index d454165ae43..00000000000
--- a/zerver/webhooks/pivotal/fixtures/v5_rejected.json
+++ /dev/null
@@ -1,70 +0,0 @@
-{
- "primary_resources": [
- {
- "story_type": "feature",
- "kind": "story",
- "id": 63486316,
- "url": "http://www.pivotaltracker.com/story/show/63486316",
- "name": "Story of the Year"
- }
- ],
- "message": "Leo Franchi rejected this feature with comments: \"Try again next time\"",
- "guid": "807213_73",
- "kind": "story_update_activity",
- "performed_by": {
- "kind": "person",
- "id": 981905,
- "initials": "LF",
- "name": "Leo Franchi"
- },
- "project": {
- "kind": "project",
- "id": 807213,
- "name": "Hard Code"
- },
- "occurred_at": 1389218802000,
- "changes": [
- {
- "new_values": {
- "google_attachments": [
-
- ],
- "updated_at": 1389218802000,
- "file_attachment_ids": [
-
- ],
- "file_attachments": [
-
- ],
- "person_id": 981905,
- "id": 59124580,
- "story_id": 63486316,
- "google_attachment_ids": [
-
- ],
- "created_at": 1389218802000,
- "text": "Try again next time"
- },
- "kind": "comment",
- "id": 59124580,
- "change_type": "create"
- },
- {
- "original_values": {
- "updated_at": 1389218792000,
- "current_state": "delivered"
- },
- "new_values": {
- "updated_at": 1389218802000,
- "current_state": "rejected"
- },
- "story_type": "feature",
- "kind": "story",
- "id": 63486316,
- "name": "Story of the Year",
- "change_type": "update"
- }
- ],
- "project_version": 73,
- "highlight": "rejected"
-}
diff --git a/zerver/webhooks/pivotal/fixtures/v5_started.json b/zerver/webhooks/pivotal/fixtures/v5_started.json
deleted file mode 100644
index dae5dca3f43..00000000000
--- a/zerver/webhooks/pivotal/fixtures/v5_started.json
+++ /dev/null
@@ -1,47 +0,0 @@
-{
- "performed_by": {
- "name": "Leo Franchi",
- "id": 981905,
- "initials": "LF",
- "kind": "person"
- },
- "changes": [
- {
- "new_values": {
- "owned_by_id": 981905,
- "updated_at": 1389218898000,
- "current_state": "started"
- },
- "story_type": "feature",
- "name": "Fresh Story",
- "id": 63495972,
- "kind": "story",
- "change_type": "update",
- "original_values": {
- "owned_by_id": null,
- "updated_at": 1389218887000,
- "current_state": "unstarted"
- }
- }
- ],
- "project": {
- "name": "Hard Code",
- "id": 807213,
- "kind": "project"
- },
- "primary_resources": [
- {
- "story_type": "feature",
- "url": "http://www.pivotaltracker.com/story/show/63495972",
- "id": 63495972,
- "name": "Fresh Story",
- "kind": "story"
- }
- ],
- "highlight": "started",
- "project_version": 78,
- "message": "Leo Franchi started this feature",
- "occurred_at": 1389218898000,
- "guid": "807213_78",
- "kind": "story_update_activity"
-}
diff --git a/zerver/webhooks/pivotal/fixtures/v5_type_changed.json b/zerver/webhooks/pivotal/fixtures/v5_type_changed.json
deleted file mode 100644
index 85d81062ed0..00000000000
--- a/zerver/webhooks/pivotal/fixtures/v5_type_changed.json
+++ /dev/null
@@ -1,47 +0,0 @@
-{
- "message": "Leo Franchi edited this bug",
- "primary_resources": [
- {
- "url": "http://www.pivotaltracker.com/story/show/63496066",
- "kind": "story",
- "story_type": "bug",
- "id": 63496066,
- "name": "Pivotal Test"
- }
- ],
- "guid": "807213_82",
- "kind": "story_update_activity",
- "project": {
- "kind": "project",
- "id": 807213,
- "name": "Hard Code"
- },
- "occurred_at": 1389219010000,
- "performed_by": {
- "initials": "LF",
- "kind": "person",
- "id": 981905,
- "name": "Leo Franchi"
- },
- "changes": [
- {
- "kind": "story",
- "story_type": "bug",
- "change_type": "update",
- "id": 63496066,
- "original_values": {
- "estimate": 3,
- "updated_at": 1389218976000,
- "story_type": "feature"
- },
- "new_values": {
- "estimate": null,
- "updated_at": 1389219010000,
- "story_type": "bug"
- },
- "name": "Pivotal Test"
- }
- ],
- "project_version": 82,
- "highlight": "edited"
-}
diff --git a/zerver/webhooks/pivotal/fixtures/v5_unsupported.json b/zerver/webhooks/pivotal/fixtures/v5_unsupported.json
deleted file mode 100644
index ca2aa495fbd..00000000000
--- a/zerver/webhooks/pivotal/fixtures/v5_unsupported.json
+++ /dev/null
@@ -1,47 +0,0 @@
-{
- "occurred_at": 1389218398000,
- "kind": "epic_update_activity",
- "project": {
- "name": "Hard Code",
- "kind": "project",
- "id": 807213
- },
- "changes": [
- {
- "name": "Story of the Year",
- "story_type": "feature",
- "change_type": "update",
- "kind": "story",
- "new_values": {
- "current_state": "accepted",
- "updated_at": 1389218398000,
- "accepted_at": 1389218397000
- },
- "id": 63486316,
- "original_values": {
- "current_state": "unstarted",
- "updated_at": 1389215951000,
- "accepted_at": null
- }
- }
- ],
- "highlight": "accepted",
- "project_version": 60,
- "guid": "807213_60",
- "primary_resources": [
- {
- "name": "Story of the Year",
- "story_type": "feature",
- "kind": "story",
- "id": 63486316,
- "url": "http://www.pivotaltracker.com/story/show/63486316"
- }
- ],
- "performed_by": {
- "name": "Leo Franchi",
- "initials": "LF",
- "kind": "person",
- "id": 981905
- },
- "message": "Leo Franchi accepted this feature"
-}
diff --git a/zerver/webhooks/pivotal/tests.py b/zerver/webhooks/pivotal/tests.py
deleted file mode 100644
index 7a5605baa5e..00000000000
--- a/zerver/webhooks/pivotal/tests.py
+++ /dev/null
@@ -1,229 +0,0 @@
-from unittest import mock
-
-import orjson
-from typing_extensions import override
-
-from zerver.lib.exceptions import UnsupportedWebhookEventTypeError
-from zerver.lib.test_classes import WebhookTestCase
-from zerver.webhooks.pivotal.view import api_pivotal_webhook_v5
-
-
-class PivotalV3HookTests(WebhookTestCase):
- def test_accepted(self) -> None:
- expected_topic_name = "My new Feature story"
- expected_message = 'Leo Franchi accepted "My new Feature story" \
-[(view)](https://www.pivotaltracker.com/s/projects/807213/stories/48276573).'
- self.check_webhook(
- "accepted", expected_topic_name, expected_message, content_type="application/xml"
- )
-
- def test_bad_subject(self) -> None:
- expected_topic_name = "Story changed"
- expected_message = "Leo Franchi accepted My new Feature story \
-[(view)](https://www.pivotaltracker.com/s/projects/807213/stories/48276573)."
- self.check_webhook(
- "bad_accepted", expected_topic_name, expected_message, content_type="application/xml"
- )
-
- def test_commented(self) -> None:
- expected_topic_name = "Comment added"
- expected_message = 'Leo Franchi added comment: "FIX THIS NOW" \
-[(view)](https://www.pivotaltracker.com/s/projects/807213/stories/48276573).'
- self.check_webhook(
- "commented", expected_topic_name, expected_message, content_type="application/xml"
- )
-
- def test_created(self) -> None:
- expected_topic_name = "My new Feature story"
- expected_message = 'Leo Franchi added "My new Feature story" \
-(unscheduled feature):\n\n~~~ quote\nThis is my long description\n~~~\n\n \
-[(view)](https://www.pivotaltracker.com/s/projects/807213/stories/48276573).'
- self.check_webhook(
- "created", expected_topic_name, expected_message, content_type="application/xml"
- )
-
- def test_delivered(self) -> None:
- expected_topic_name = "Another new story"
- expected_message = 'Leo Franchi delivered "Another new story" \
-[(view)](https://www.pivotaltracker.com/s/projects/807213/stories/48278289).'
- self.check_webhook(
- "delivered", expected_topic_name, expected_message, content_type="application/xml"
- )
-
- def test_finished(self) -> None:
- expected_topic_name = "Another new story"
- expected_message = 'Leo Franchi finished "Another new story" \
-[(view)](https://www.pivotaltracker.com/s/projects/807213/stories/48278289).'
- self.check_webhook(
- "finished", expected_topic_name, expected_message, content_type="application/xml"
- )
-
- def test_moved(self) -> None:
- expected_topic_name = "My new Feature story"
- expected_message = 'Leo Franchi edited "My new Feature story" \
-[(view)](https://www.pivotaltracker.com/s/projects/807213/stories/48276573).'
- self.check_webhook(
- "moved", expected_topic_name, expected_message, content_type="application/xml"
- )
-
- def test_rejected(self) -> None:
- expected_topic_name = "Another new story"
- expected_message = 'Leo Franchi rejected "Another new story" with comments: \
-"Not good enough, sorry" [(view)](https://www.pivotaltracker.com/s/projects/807213/stories/48278289).'
- self.check_webhook(
- "rejected", expected_topic_name, expected_message, content_type="application/xml"
- )
-
- def test_started(self) -> None:
- expected_topic_name = "Another new story"
- expected_message = 'Leo Franchi started "Another new story" \
-[(view)](https://www.pivotaltracker.com/s/projects/807213/stories/48278289).'
- self.check_webhook(
- "started", expected_topic_name, expected_message, content_type="application/xml"
- )
-
- def test_created_estimate(self) -> None:
- expected_topic_name = "Another new story"
- expected_message = 'Leo Franchi added "Another new story" \
-(unscheduled feature worth 2 story points):\n\n~~~ quote\nSome loong description\n~~~\n\n \
-[(view)](https://www.pivotaltracker.com/s/projects/807213/stories/48278289).'
- self.check_webhook(
- "created_estimate",
- expected_topic_name,
- expected_message,
- content_type="application/xml",
- )
-
- def test_type_changed(self) -> None:
- expected_topic_name = "My new Feature story"
- expected_message = 'Leo Franchi edited "My new Feature story" \
-[(view)](https://www.pivotaltracker.com/s/projects/807213/stories/48276573).'
- self.check_webhook(
- "type_changed", expected_topic_name, expected_message, content_type="application/xml"
- )
-
- @override
- def get_body(self, fixture_name: str) -> str:
- return self.webhook_fixture_data("pivotal", fixture_name, file_type="xml")
-
-
-class PivotalV5HookTests(WebhookTestCase):
- def test_accepted(self) -> None:
- expected_topic_name = "#63486316: Story of the Year"
- expected_message = """Leo Franchi updated [Hard Code](https://www.pivotaltracker.com/s/projects/807213): [Story of the Year](http://www.pivotaltracker.com/story/show/63486316):
-* state changed from **unstarted** to **accepted**"""
- self.check_webhook(
- "accepted", expected_topic_name, expected_message, content_type="application/xml"
- )
-
- def test_commented(self) -> None:
- expected_topic_name = "#63486316: Story of the Year"
- expected_message = """Leo Franchi added a comment to [Hard Code](https://www.pivotaltracker.com/s/projects/807213): [Story of the Year](http://www.pivotaltracker.com/story/show/63486316):
-~~~quote
-A comment on the story
-~~~"""
- self.check_webhook(
- "commented", expected_topic_name, expected_message, content_type="application/xml"
- )
-
- def test_created(self) -> None:
- expected_topic_name = "#63495662: Story that I created"
- expected_message = """Leo Franchi created bug: [Hard Code](https://www.pivotaltracker.com/s/projects/807213): [Story that I created](http://www.pivotaltracker.com/story/show/63495662)
-* State is **unscheduled**
-* Description is
-
-> What a description"""
- self.check_webhook(
- "created", expected_topic_name, expected_message, content_type="application/xml"
- )
-
- def test_delivered(self) -> None:
- expected_topic_name = "#63486316: Story of the Year"
- expected_message = """Leo Franchi updated [Hard Code](https://www.pivotaltracker.com/s/projects/807213): [Story of the Year](http://www.pivotaltracker.com/story/show/63486316):
-* state changed from **accepted** to **delivered**"""
- self.check_webhook(
- "delivered", expected_topic_name, expected_message, content_type="application/xml"
- )
-
- def test_finished(self) -> None:
- expected_topic_name = "#63486316: Story of the Year"
- expected_message = """Leo Franchi updated [Hard Code](https://www.pivotaltracker.com/s/projects/807213): [Story of the Year](http://www.pivotaltracker.com/story/show/63486316):
-* state changed from **delivered** to **accepted**"""
- self.check_webhook(
- "finished", expected_topic_name, expected_message, content_type="application/xml"
- )
-
- def test_moved(self) -> None:
- expected_topic_name = "#63496066: Pivotal Test"
- expected_message = """Leo Franchi moved [Hard Code](https://www.pivotaltracker.com/s/projects/807213): [Pivotal Test](http://www.pivotaltracker.com/story/show/63496066) from **unstarted** to **unscheduled**."""
- self.check_webhook(
- "moved", expected_topic_name, expected_message, content_type="application/xml"
- )
-
- def test_rejected(self) -> None:
- expected_topic_name = "#63486316: Story of the Year"
- expected_message = """Leo Franchi updated [Hard Code](https://www.pivotaltracker.com/s/projects/807213): [Story of the Year](http://www.pivotaltracker.com/story/show/63486316):
-* Comment added:
-~~~quote
-Try again next time
-~~~
-* state changed from **delivered** to **rejected**"""
- self.check_webhook(
- "rejected", expected_topic_name, expected_message, content_type="application/xml"
- )
-
- def test_started(self) -> None:
- expected_topic_name = "#63495972: Fresh Story"
- expected_message = """Leo Franchi updated [Hard Code](https://www.pivotaltracker.com/s/projects/807213): [Fresh Story](http://www.pivotaltracker.com/story/show/63495972):
-* state changed from **unstarted** to **started**"""
- self.check_webhook(
- "started", expected_topic_name, expected_message, content_type="application/xml"
- )
-
- def test_created_estimate(self) -> None:
- expected_topic_name = "#63496066: Pivotal Test"
- expected_message = """Leo Franchi updated [Hard Code](https://www.pivotaltracker.com/s/projects/807213): [Pivotal Test](http://www.pivotaltracker.com/story/show/63496066):
-* estimate is now **3 points**"""
- self.check_webhook(
- "created_estimate",
- expected_topic_name,
- expected_message,
- content_type="application/xml",
- )
-
- def test_type_changed(self) -> None:
- expected_topic_name = "#63496066: Pivotal Test"
- expected_message = """Leo Franchi updated [Hard Code](https://www.pivotaltracker.com/s/projects/807213): [Pivotal Test](http://www.pivotaltracker.com/story/show/63496066):
-* estimate changed from 3 to **0 points**
-* type changed from **feature** to **bug**"""
- self.check_webhook(
- "type_changed", expected_topic_name, expected_message, content_type="application/xml"
- )
-
- def test_bad_payload(self) -> None:
- bad = ("foo", None, "bar")
- with (
- self.assertRaisesRegex(AssertionError, "Unable to handle Pivotal payload"),
- mock.patch("zerver.webhooks.pivotal.view.api_pivotal_webhook_v3", return_value=bad),
- ):
- self.check_webhook("accepted", expect_topic="foo")
-
- def test_bad_request(self) -> None:
- request = mock.MagicMock()
- hamlet = self.example_user("hamlet")
- bad = orjson.loads(self.get_body("bad_request"))
-
- with mock.patch("zerver.webhooks.pivotal.view.orjson.loads", return_value=bad):
- result = api_pivotal_webhook_v5(request, hamlet)
- self.assertEqual(result[0], "#0: ")
-
- bad = orjson.loads(self.get_body("bad_kind"))
- with (
- self.assertRaisesRegex(UnsupportedWebhookEventTypeError, "'unknown_kind'.* supported"),
- mock.patch("zerver.webhooks.pivotal.view.orjson.loads", return_value=bad),
- ):
- api_pivotal_webhook_v5(request, hamlet)
-
- @override
- def get_body(self, fixture_name: str) -> str:
- return self.webhook_fixture_data("pivotal", f"v5_{fixture_name}", file_type="json")
diff --git a/zerver/webhooks/pivotal/view.py b/zerver/webhooks/pivotal/view.py
deleted file mode 100644
index 414fadb80ba..00000000000
--- a/zerver/webhooks/pivotal/view.py
+++ /dev/null
@@ -1,196 +0,0 @@
-"""Webhooks for external integrations."""
-
-import re
-from typing import Any
-
-import orjson
-from defusedxml.ElementTree import fromstring as xml_fromstring
-from django.http import HttpRequest, HttpResponse
-from django.utils.translation import gettext as _
-
-from zerver.decorator import webhook_view
-from zerver.lib.exceptions import JsonableError, UnsupportedWebhookEventTypeError
-from zerver.lib.response import json_success
-from zerver.lib.typed_endpoint import typed_endpoint_without_parameters
-from zerver.lib.utils import assert_is_not_none
-from zerver.lib.webhooks.common import check_send_webhook_message
-from zerver.models import UserProfile
-
-
-def api_pivotal_webhook_v3(request: HttpRequest, user_profile: UserProfile) -> tuple[str, str, str]:
- payload = xml_fromstring(request.body)
-
- def get_text(attrs: list[str]) -> str:
- start = payload
- for attr in attrs:
- child = start.find(attr)
- if child is None:
- return ""
- start = child
- assert start.text is not None
- return start.text
-
- event_type = assert_is_not_none(payload.find("event_type")).text
- description = assert_is_not_none(payload.find("description")).text
- assert description is not None
- project_id = assert_is_not_none(payload.find("project_id")).text
- story_id = get_text(["stories", "story", "id"])
- # Ugh, the URL in the XML data is not a clickable URL that works for the user
- # so we try to build one that the user can actually click on
- url = f"https://www.pivotaltracker.com/s/projects/{project_id}/stories/{story_id}"
-
- # Pivotal doesn't tell us the name of the story, but it's usually in the
- # description in quotes as the first quoted string
- name_re = re.compile(r'[^"]+"([^"]+)".*')
- match = name_re.match(description)
- if match and len(match.groups()):
- name = match.group(1)
- else:
- name = "Story changed" # Failed for an unknown reason, show something
- more_info = f" [(view)]({url})."
-
- if event_type == "story_update":
- topic_name = name
- content = description + more_info
- elif event_type == "note_create":
- topic_name = "Comment added"
- content = description + more_info
- elif event_type == "story_create":
- issue_desc = get_text(["stories", "story", "description"])
- issue_type = get_text(["stories", "story", "story_type"])
- issue_status = get_text(["stories", "story", "current_state"])
- estimate = get_text(["stories", "story", "estimate"])
- if estimate != "":
- estimate = f" worth {estimate} story points"
- topic_name = name
- content = f"{description} ({issue_status} {issue_type}{estimate}):\n\n~~~ quote\n{issue_desc}\n~~~\n\n{more_info}"
- return topic_name, content, f"{event_type}_v3"
-
-
-UNSUPPORTED_EVENT_TYPES = [
- "task_create_activity",
- "comment_delete_activity",
- "task_delete_activity",
- "task_update_activity",
- "story_move_from_project_activity",
- "story_delete_activity",
- "story_move_into_project_activity",
- "epic_update_activity",
- "label_create_activity",
-]
-
-ALL_EVENT_TYPES = [
- "story_update_v3",
- "note_create_v3",
- "story_create_v3",
- "story_move_activity_v5",
- "story_create_activity_v5",
- "story_update_activity_v5",
- "comment_create_activity_v5",
-]
-
-
-def api_pivotal_webhook_v5(request: HttpRequest, user_profile: UserProfile) -> tuple[str, str, str]:
- payload = orjson.loads(request.body)
-
- event_type = payload["kind"]
-
- project_name = payload["project"]["name"]
- project_id = payload["project"]["id"]
-
- primary_resources = payload["primary_resources"][0]
- story_url = primary_resources["url"]
- story_type = primary_resources.get("story_type")
- story_id = primary_resources["id"]
- story_name = primary_resources["name"]
-
- performed_by = payload.get("performed_by", {}).get("name", "")
-
- story_info = f"[{project_name}](https://www.pivotaltracker.com/s/projects/{project_id}): [{story_name}]({story_url})"
-
- changes = payload.get("changes", [])
-
- content = ""
- topic_name = f"#{story_id}: {story_name}"
-
- def extract_comment(change: dict[str, Any]) -> str | None:
- if change.get("kind") == "comment":
- return change.get("new_values", {}).get("text", None)
- return None
-
- if event_type == "story_update_activity":
- # Find the changed valued and build a message
- content += f"{performed_by} updated {story_info}:\n"
- for change in changes:
- old_values = change.get("original_values", {})
- new_values = change["new_values"]
-
- if "current_state" in old_values and "current_state" in new_values:
- content += "* state changed from **{}** to **{}**\n".format(
- old_values["current_state"], new_values["current_state"]
- )
- if "estimate" in old_values and "estimate" in new_values:
- old_estimate = old_values.get("estimate", None)
- if old_estimate is None:
- estimate = "is now"
- else:
- estimate = f"changed from {old_estimate} to"
- new_estimate = new_values["estimate"] if new_values["estimate"] is not None else "0"
- content += f"* estimate {estimate} **{new_estimate} points**\n"
- if "story_type" in old_values and "story_type" in new_values:
- content += "* type changed from **{}** to **{}**\n".format(
- old_values["story_type"], new_values["story_type"]
- )
-
- comment = extract_comment(change)
- if comment is not None:
- content += f"* Comment added:\n~~~quote\n{comment}\n~~~\n"
-
- elif event_type == "comment_create_activity":
- for change in changes:
- comment = extract_comment(change)
- if comment is not None:
- content += (
- f"{performed_by} added a comment to {story_info}:\n~~~quote\n{comment}\n~~~"
- )
- elif event_type == "story_create_activity":
- content += f"{performed_by} created {story_type}: {story_info}\n"
- for change in changes:
- new_values = change.get("new_values", {})
- if "current_state" in new_values:
- content += "* State is **{}**\n".format(new_values["current_state"])
- if "description" in new_values:
- content += "* Description is\n\n> {}".format(new_values["description"])
- elif event_type == "story_move_activity":
- content = f"{performed_by} moved {story_info}"
- for change in changes:
- old_values = change.get("original_values", {})
- new_values = change["new_values"]
- if "current_state" in old_values and "current_state" in new_values:
- content += " from **{}** to **{}**.".format(
- old_values["current_state"], new_values["current_state"]
- )
- elif event_type in UNSUPPORTED_EVENT_TYPES:
- # Known but unsupported Pivotal event types
- pass
- else:
- raise UnsupportedWebhookEventTypeError(event_type)
-
- return topic_name, content, f"{event_type}_v5"
-
-
-@webhook_view("Pivotal", all_event_types=ALL_EVENT_TYPES)
-@typed_endpoint_without_parameters
-def api_pivotal_webhook(request: HttpRequest, user_profile: UserProfile) -> HttpResponse:
- topic_name = content = None
- try:
- topic_name, content, event_type = api_pivotal_webhook_v3(request, user_profile)
- except Exception:
- # Attempt to parse v5 JSON payload
- topic_name, content, event_type = api_pivotal_webhook_v5(request, user_profile)
-
- if not content:
- raise JsonableError(_("Unable to handle Pivotal payload"))
-
- check_send_webhook_message(request, user_profile, topic_name, content, event_type)
- return json_success(request)