Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
integrations: Remove Google Code-in integration.
Lauryn Menard1140e8402bfb
diff --git a/zerver/lib/integrations.py b/zerver/lib/integrations.pyindex 85c9f9466bb..2b4d394e3c2 100644--- a/zerver/lib/integrations.py+++ b/zerver/lib/integrations.py@@ -491,7 +491,6 @@ WEBHOOK_INTEGRATIONS: List[WebhookIntegration] = [WebhookIntegration("zapier", ["meta-integration"]),WebhookIntegration("zendesk", ["customer-support"]),WebhookIntegration("zabbix", ["monitoring"], display_name="Zabbix"),- WebhookIntegration("gci", ["misc"], display_name="Google Code-in", stream_name="gci"),]INTEGRATIONS: Dict[str, Integration] = {@@ -750,7 +749,6 @@ DOC_SCREENSHOT_CONFIG: Dict[str, List[BaseScreenshotConfig]] = {"freshping": [ScreenshotConfig("freshping_check_unreachable.json")],"freshstatus": [ScreenshotConfig("freshstatus_incident_open.json")],"front": [ScreenshotConfig("inbound_message.json")],- "gci": [ScreenshotConfig("task_abandoned_by_student.json")],"gitea": [ScreenshotConfig("pull_request__merged.json")],"github": [ScreenshotConfig("push__1_commit.json")],"githubsponsors": [ScreenshotConfig("created.json")],diff --git a/zerver/lib/name_restrictions.py b/zerver/lib/name_restrictions.pyindex 3a1d47543fa..c83bc47b896 100644--- a/zerver/lib/name_restrictions.py+++ b/zerver/lib/name_restrictions.py@@ -111,7 +111,6 @@ ZULIP_RESERVED_SUBDOMAINS = {"intern","outreachy","gsoc",- "gci","externship",# Things that sound like security"auth",diff --git a/zerver/webhooks/gci/__init__.py b/zerver/webhooks/gci/__init__.pydeleted file mode 100644index e69de29bb2d..00000000000diff --git a/zerver/webhooks/gci/doc.md b/zerver/webhooks/gci/doc.mddeleted file mode 100644index 2e2014c73d3..00000000000--- a/zerver/webhooks/gci/doc.md+++ /dev/null@@ -1,18 +0,0 @@-If you are a participating organization with-[Google Code-in](https://developers.google.com/open-source/gci/),-you can now get Task notifications in Zulip!--1. {!create-channel.md!}--1. {!create-an-incoming-webhook.md!}--1. {!generate-integration-url.md!}--1. Send an email to `[email protected]` asking them to enable webhooks- for your organization. They'll need the name of your organization, and- the URL constructed above.---{!congrats.md!}--diff --git a/zerver/webhooks/gci/fixtures/student_commented_on_task.json b/zerver/webhooks/gci/fixtures/student_commented_on_task.jsondeleted file mode 100644index 5906aa612ac..00000000000--- a/zerver/webhooks/gci/fixtures/student_commented_on_task.json+++ /dev/null@@ -1,12 +0,0 @@-{- "author_is_student": true,- "task_definition_name": "Sails unspread it stopped at kearney",- "event_type": "comment",- "task_instance": 6296903092273152,- "task_claimed_by": "student-yqqtag",- "time": 1506475323.256627,- "id": "1f4bab4d1820400f9b50ed8bf2bb03b3",- "author": "student-yqqtag",- "task_instance_url": "https://0.0.0.0:8000/dashboard/task-instances/6694926301528064/",- "task_definition_url": "https://0.0.0.0:8000/dashboard/tasks/6694926301528064/"-}diff --git a/zerver/webhooks/gci/fixtures/student_unassigned_by_mentor.json b/zerver/webhooks/gci/fixtures/student_unassigned_by_mentor.jsondeleted file mode 100644index 12efc2898be..00000000000--- a/zerver/webhooks/gci/fixtures/student_unassigned_by_mentor.json+++ /dev/null@@ -1,12 +0,0 @@-{- "author_is_student": false,- "task_definition_name": "Sails unspread it stopped at kearney",- "event_type": "unassign",- "task_instance": 6296903092273152,- "task_claimed_by": "student-yqqtag",- "time": 1506475323.256627,- "id": "1f4bab4d1820400f9b50ed8bf2bb03b3",- "author": "eeshangarg",- "task_instance_url": "https://0.0.0.0:8000/dashboard/task-instances/6694926301528064/",- "task_definition_url": "https://0.0.0.0:8000/dashboard/tasks/6694926301528064/"-}diff --git a/zerver/webhooks/gci/fixtures/task_abandoned_by_student.json b/zerver/webhooks/gci/fixtures/task_abandoned_by_student.jsondeleted file mode 100644index fe4d32e7119..00000000000--- a/zerver/webhooks/gci/fixtures/task_abandoned_by_student.json+++ /dev/null@@ -1,12 +0,0 @@-{- "author_is_student": true,- "task_definition_name": "Sails unspread it stopped at kearney",- "event_type": "abandon",- "task_instance": 6296903092273152,- "task_claimed_by": "student-yqqtag",- "time": 1506475323.256627,- "id": "1f4bab4d1820400f9b50ed8bf2bb03b3",- "author": "student-yqqtag",- "task_instance_url": "https://0.0.0.0:8000/dashboard/task-instances/6694926301528064/",- "task_definition_url": "https://0.0.0.0:8000/dashboard/tasks/6694926301528064/"-}diff --git a/zerver/webhooks/gci/fixtures/task_approved_by_mentor.json b/zerver/webhooks/gci/fixtures/task_approved_by_mentor.jsondeleted file mode 100644index e288b907ae8..00000000000--- a/zerver/webhooks/gci/fixtures/task_approved_by_mentor.json+++ /dev/null@@ -1,12 +0,0 @@-{- "author_is_student": false,- "task_definition_name": "Sails unspread it stopped at kearney",- "event_type": "approve",- "task_instance": 6296903092273152,- "task_claimed_by": "student-yqqtag",- "time": 1506475323.256627,- "id": "1f4bab4d1820400f9b50ed8bf2bb03b3",- "author": "eeshangarg",- "task_instance_url": "https://0.0.0.0:8000/dashboard/task-instances/6694926301528064/",- "task_definition_url": "https://0.0.0.0:8000/dashboard/tasks/6694926301528064/"-}diff --git a/zerver/webhooks/gci/fixtures/task_approved_by_mentor_pending_parental_consent.json b/zerver/webhooks/gci/fixtures/task_approved_by_mentor_pending_parental_consent.jsondeleted file mode 100644index b12507b8a37..00000000000--- a/zerver/webhooks/gci/fixtures/task_approved_by_mentor_pending_parental_consent.json+++ /dev/null@@ -1,12 +0,0 @@-{- "author_is_student": false,- "task_definition_name": "Sails unspread it stopped at kearney",- "event_type": "approve-pending-pc",- "task_instance": 6296903092273152,- "task_claimed_by": "student-yqqtag",- "time": 1506475323.256627,- "id": "1f4bab4d1820400f9b50ed8bf2bb03b3",- "author": "eeshangarg",- "task_instance_url": "https://0.0.0.0:8000/dashboard/task-instances/6694926301528064/",- "task_definition_url": "https://0.0.0.0:8000/dashboard/tasks/6694926301528064/"-}diff --git a/zerver/webhooks/gci/fixtures/task_claimed_by_student.json b/zerver/webhooks/gci/fixtures/task_claimed_by_student.jsondeleted file mode 100644index 774a4191373..00000000000--- a/zerver/webhooks/gci/fixtures/task_claimed_by_student.json+++ /dev/null@@ -1,12 +0,0 @@-{- "author_is_student": true,- "task_definition_name": "Sails unspread it stopped at kearney",- "event_type": "claim",- "task_instance": 6296903092273152,- "task_claimed_by": "student-yqqtag",- "time": 1506475323.256627,- "id": "1f4bab4d1820400f9b50ed8bf2bb03b3",- "author": "student-yqqtag",- "task_instance_url": "https://0.0.0.0:8000/dashboard/task-instances/6694926301528064/",- "task_definition_url": "https://0.0.0.0:8000/dashboard/tasks/6694926301528064/"-}diff --git a/zerver/webhooks/gci/fixtures/task_deadline_extended_by_mentor.json b/zerver/webhooks/gci/fixtures/task_deadline_extended_by_mentor.jsondeleted file mode 100644index 0f8b8585c67..00000000000--- a/zerver/webhooks/gci/fixtures/task_deadline_extended_by_mentor.json+++ /dev/null@@ -1,13 +0,0 @@-{- "author_is_student": false,- "task_definition_name": "Sails unspread it stopped at kearney",- "event_type": "extend",- "task_instance": 6296903092273152,- "task_claimed_by": "student-yqqtag",- "time": 1506475323.256627,- "id": "1f4bab4d1820400f9b50ed8bf2bb03b3",- "extension_days": 1.0,- "author": "eeshangarg",- "task_instance_url": "https://0.0.0.0:8000/dashboard/task-instances/6694926301528064/",- "task_definition_url": "https://0.0.0.0:8000/dashboard/tasks/6694926301528064/"-}diff --git a/zerver/webhooks/gci/fixtures/task_deadline_has_passed.json b/zerver/webhooks/gci/fixtures/task_deadline_has_passed.jsondeleted file mode 100644index d3e0d749d0c..00000000000--- a/zerver/webhooks/gci/fixtures/task_deadline_has_passed.json+++ /dev/null@@ -1,13 +0,0 @@-{- "task_definition_url": "https://0.0.0.0:8000/dashboard/tasks/6694926301528064/",- "event_type": "outoftime",- "task_definition_name": "Sails unspread it stopped at kearney",- "task_instance_url": "https://0.0.0.0:8000/dashboard/task-instances/6694926301528064/",- "id": "1f4bab4d1820400f9b50ed8bf2bb03b3",- "task_instance": 6694926301528064,- "author_is_student":false,- "organization": "Zulip",- "task_claimed_by": "student-yqqtag",- "author":"Google Code-in System",- "time":1516125627.2782099247-}diff --git a/zerver/webhooks/gci/fixtures/task_submitted_by_mentor_for_more_work.json b/zerver/webhooks/gci/fixtures/task_submitted_by_mentor_for_more_work.jsondeleted file mode 100644index 68ae527d65e..00000000000--- a/zerver/webhooks/gci/fixtures/task_submitted_by_mentor_for_more_work.json+++ /dev/null@@ -1,12 +0,0 @@-{- "task_definition_url":"http://localhost:8080/dashboard/tasks/6051711999279104/",- "task_claimed_by":"student-yqqtag",- "event_type":"needswork",- "author":"eeshangarg",- "task_instance_url":"http://localhost:8080/dashboard/task-instances/6051711999279104/",- "task_definition_name":"Sails unspread it stopped at kearney",- "time":1509576007.257213,- "id":"19f30988c86045bfbc6aacd789cd3a92",- "task_instance":5136918324969472,- "author_is_student":false-}diff --git a/zerver/webhooks/gci/fixtures/task_submitted_by_student.json b/zerver/webhooks/gci/fixtures/task_submitted_by_student.jsondeleted file mode 100644index 34608ff6216..00000000000--- a/zerver/webhooks/gci/fixtures/task_submitted_by_student.json+++ /dev/null@@ -1,12 +0,0 @@-{- "author_is_student": true,- "task_definition_name": "Sails unspread it stopped at kearney",- "event_type": "submit",- "task_instance": 6296903092273152,- "task_claimed_by": "student-yqqtag",- "time": 1506475323.256627,- "id": "1f4bab4d1820400f9b50ed8bf2bb03b3",- "author": "student-yqqtag",- "task_instance_url": "https://0.0.0.0:8000/dashboard/task-instances/6694926301528064/",- "task_definition_url": "https://0.0.0.0:8000/dashboard/tasks/6694926301528064/"-}diff --git a/zerver/webhooks/gci/tests.py b/zerver/webhooks/gci/tests.pydeleted file mode 100644index e7202ac9ca5..00000000000--- a/zerver/webhooks/gci/tests.py+++ /dev/null@@ -1,65 +0,0 @@-from zerver.lib.test_classes import WebhookTestCase---class GoogleCodeInTests(WebhookTestCase):- CHANNEL_NAME = "gci"- URL_TEMPLATE = "/api/v1/external/gci?&api_key={api_key}&stream={stream}"- WEBHOOK_DIR_NAME = "gci"-- def test_abandon_event_message(self) -> None:- expected_topic_name = "student-yqqtag"- expected_message = "**student-yqqtag** abandoned the task [Sails unspread it stopped at kearney](https://codein.withgoogle.com/dashboard/task-instances/6296903092273152/)."- self.check_webhook("task_abandoned_by_student", expected_topic_name, expected_message)-- def test_comment_event_message(self) -> None:- expected_topic_name = "student-yqqtag"- expected_message = "**student-yqqtag** commented on the task [Sails unspread it stopped at kearney](https://codein.withgoogle.com/dashboard/task-instances/6296903092273152/)."- self.check_webhook("student_commented_on_task", expected_topic_name, expected_message)-- def test_submit_event_message(self) -> None:- expected_topic_name = "student-yqqtag"- expected_message = "**student-yqqtag** submitted the task [Sails unspread it stopped at kearney](https://codein.withgoogle.com/dashboard/task-instances/6296903092273152/)."- self.check_webhook("task_submitted_by_student", expected_topic_name, expected_message)-- def test_claim_event_message(self) -> None:- expected_topic_name = "student-yqqtag"- expected_message = "**student-yqqtag** claimed the task [Sails unspread it stopped at kearney](https://codein.withgoogle.com/dashboard/task-instances/6296903092273152/)."- self.check_webhook("task_claimed_by_student", expected_topic_name, expected_message)-- def test_approve_event_message(self) -> None:- expected_topic_name = "student-yqqtag"- expected_message = "**eeshangarg** approved the task [Sails unspread it stopped at kearney](https://codein.withgoogle.com/dashboard/task-instances/6296903092273152/)."- self.check_webhook("task_approved_by_mentor", expected_topic_name, expected_message)-- def test_approve_pending_pc_event_message(self) -> None:- expected_topic_name = "student-yqqtag"- expected_message = "**eeshangarg** approved the task [Sails unspread it stopped at kearney](https://codein.withgoogle.com/dashboard/task-instances/6296903092273152/) (pending parental consent)."- self.check_webhook(- "task_approved_by_mentor_pending_parental_consent",- expected_topic_name,- expected_message,- )-- def test_needswork_event_message(self) -> None:- expected_topic_name = "student-yqqtag"- expected_message = "**eeshangarg** submitted the task [Sails unspread it stopped at kearney](https://codein.withgoogle.com/dashboard/task-instances/5136918324969472/) for more work."- self.check_webhook(- "task_submitted_by_mentor_for_more_work", expected_topic_name, expected_message- )-- def test_extend_event_message(self) -> None:- expected_topic_name = "student-yqqtag"- expected_message = "**eeshangarg** extended the deadline for the task [Sails unspread it stopped at kearney](https://codein.withgoogle.com/dashboard/task-instances/6296903092273152/) by 1.0 day(s)."- self.check_webhook(- "task_deadline_extended_by_mentor", expected_topic_name, expected_message- )-- def test_unassign_event_message(self) -> None:- expected_topic_name = "student-yqqtag"- expected_message = "**eeshangarg** unassigned **student-yqqtag** from the task [Sails unspread it stopped at kearney](https://codein.withgoogle.com/dashboard/task-instances/6296903092273152/)."- self.check_webhook("student_unassigned_by_mentor", expected_topic_name, expected_message)-- def test_outoftime_event_message(self) -> None:- expected_topic_name = "student-yqqtag"- expected_message = "The deadline for the task [Sails unspread it stopped at kearney](https://codein.withgoogle.com/dashboard/task-instances/6694926301528064/) has passed."- self.check_webhook("task_deadline_has_passed", expected_topic_name, expected_message)diff --git a/zerver/webhooks/gci/view.py b/zerver/webhooks/gci/view.pydeleted file mode 100644index 5c5a80a621e..00000000000--- a/zerver/webhooks/gci/view.py+++ /dev/null@@ -1,163 +0,0 @@-from typing import Callable, Optional--from django.http import HttpRequest, HttpResponse--from zerver.decorator import webhook_view-from zerver.lib.response import json_success-from zerver.lib.typed_endpoint import JsonBodyPayload, typed_endpoint-from zerver.lib.validator import WildValue, check_float, check_int, check_string-from zerver.lib.webhooks.common import check_send_webhook_message-from zerver.models import UserProfile--GCI_MESSAGE_TEMPLATE = "**{actor}** {action} the task [{task_name}]({task_url})."-GCI_TOPIC_TEMPLATE = "{student_name}"---def build_instance_url(instance_id: int) -> str:- return f"https://codein.withgoogle.com/dashboard/task-instances/{instance_id}/"---class UnknownEventTypeError(Exception):- pass---def get_abandon_event_body(payload: WildValue) -> str:- return GCI_MESSAGE_TEMPLATE.format(- actor=payload["task_claimed_by"].tame(check_string),- action="{}ed".format(payload["event_type"].tame(check_string)),- task_name=payload["task_definition_name"].tame(check_string),- task_url=build_instance_url(payload["task_instance"].tame(check_int)),- )---def get_submit_event_body(payload: WildValue) -> str:- return GCI_MESSAGE_TEMPLATE.format(- actor=payload["task_claimed_by"].tame(check_string),- action="{}ted".format(payload["event_type"].tame(check_string)),- task_name=payload["task_definition_name"].tame(check_string),- task_url=build_instance_url(payload["task_instance"].tame(check_int)),- )---def get_comment_event_body(payload: WildValue) -> str:- return GCI_MESSAGE_TEMPLATE.format(- actor=payload["author"].tame(check_string),- action="{}ed on".format(payload["event_type"].tame(check_string)),- task_name=payload["task_definition_name"].tame(check_string),- task_url=build_instance_url(payload["task_instance"].tame(check_int)),- )---def get_claim_event_body(payload: WildValue) -> str:- return GCI_MESSAGE_TEMPLATE.format(- actor=payload["task_claimed_by"].tame(check_string),- action="{}ed".format(payload["event_type"].tame(check_string)),- task_name=payload["task_definition_name"].tame(check_string),- task_url=build_instance_url(payload["task_instance"].tame(check_int)),- )---def get_approve_event_body(payload: WildValue) -> str:- return GCI_MESSAGE_TEMPLATE.format(- actor=payload["author"].tame(check_string),- action="{}d".format(payload["event_type"].tame(check_string)),- task_name=payload["task_definition_name"].tame(check_string),- task_url=build_instance_url(payload["task_instance"].tame(check_int)),- )---def get_approve_pending_pc_event_body(payload: WildValue) -> str:- template = "{} (pending parental consent).".format(GCI_MESSAGE_TEMPLATE.rstrip("."))- return template.format(- actor=payload["author"].tame(check_string),- action="approved",- task_name=payload["task_definition_name"].tame(check_string),- task_url=build_instance_url(payload["task_instance"].tame(check_int)),- )---def get_needswork_event_body(payload: WildValue) -> str:- template = "{} for more work.".format(GCI_MESSAGE_TEMPLATE.rstrip("."))- return template.format(- actor=payload["author"].tame(check_string),- action="submitted",- task_name=payload["task_definition_name"].tame(check_string),- task_url=build_instance_url(payload["task_instance"].tame(check_int)),- )---def get_extend_event_body(payload: WildValue) -> str:- template = "{} by {days} day(s).".format(- GCI_MESSAGE_TEMPLATE.rstrip("."), days=payload["extension_days"].tame(check_float)- )- return template.format(- actor=payload["author"].tame(check_string),- action="extended the deadline for",- task_name=payload["task_definition_name"].tame(check_string),- task_url=build_instance_url(payload["task_instance"].tame(check_int)),- )---def get_unassign_event_body(payload: WildValue) -> str:- return GCI_MESSAGE_TEMPLATE.format(- actor=payload["author"].tame(check_string),- action="unassigned **{student}** from".format(- student=payload["task_claimed_by"].tame(check_string)- ),- task_name=payload["task_definition_name"].tame(check_string),- task_url=build_instance_url(payload["task_instance"].tame(check_int)),- )---def get_outoftime_event_body(payload: WildValue) -> str:- return "The deadline for the task [{task_name}]({task_url}) has passed.".format(- task_name=payload["task_definition_name"].tame(check_string),- task_url=build_instance_url(payload["task_instance"].tame(check_int)),- )---EVENTS_FUNCTION_MAPPER = {- "abandon": get_abandon_event_body,- "approve": get_approve_event_body,- "approve-pending-pc": get_approve_pending_pc_event_body,- "claim": get_claim_event_body,- "comment": get_comment_event_body,- "extend": get_extend_event_body,- "needswork": get_needswork_event_body,- "outoftime": get_outoftime_event_body,- "submit": get_submit_event_body,- "unassign": get_unassign_event_body,-}--ALL_EVENT_TYPES = list(EVENTS_FUNCTION_MAPPER.keys())---@webhook_view("GoogleCodeIn", all_event_types=ALL_EVENT_TYPES)-@typed_endpoint-def api_gci_webhook(- request: HttpRequest,- user_profile: UserProfile,- *,- payload: JsonBodyPayload[WildValue],-) -> HttpResponse:- event = get_event(payload)- if event is not None:- body = get_body_based_on_event(event)(payload)- topic_name = GCI_TOPIC_TEMPLATE.format(- student_name=payload["task_claimed_by"].tame(check_string),- )- check_send_webhook_message(request, user_profile, topic_name, body, event)-- return json_success(request)---def get_event(payload: WildValue) -> Optional[str]:- event = payload["event_type"].tame(check_string)- if event in EVENTS_FUNCTION_MAPPER:- return event-- raise UnknownEventTypeError(f"Event '{event}' is unknown and cannot be handled") # nocoverage---def get_body_based_on_event(event: str) -> Callable[[WildValue], str]:- return EVENTS_FUNCTION_MAPPER[event]