integrations: Remove Google Code-in integration.

The Google Code-in program ended in 2019/2020 so there is no need
to maintain this Webhook integration.
This commit is contained in:
Lauryn Menard 2024-07-02 15:39:27 +02:00 committed by Tim Abbott
parent ce9c9ddf12
commit 1140e8402b
16 changed files with 0 additions and 371 deletions

View File

@ -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")],

View File

@ -111,7 +111,6 @@ ZULIP_RESERVED_SUBDOMAINS = {
"intern",
"outreachy",
"gsoc",
"gci",
"externship",
# Things that sound like security
"auth",

View File

@ -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 `gci-support@google.com` asking them to enable webhooks
for your organization. They'll need the name of your organization, and
the URL constructed above.
{!congrats.md!}
![](/static/images/integrations/gci/001.png)

View File

@ -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/"
}

View File

@ -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/"
}

View File

@ -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/"
}

View File

@ -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/"
}

View File

@ -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/"
}

View File

@ -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/"
}

View File

@ -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/"
}

View File

@ -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
}

View File

@ -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
}

View File

@ -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/"
}

View File

@ -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)

View File

@ -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]