From 20f3e9b7798a3207ccb2e5ea0f1cc7669913e66f Mon Sep 17 00:00:00 2001 From: Eeshan Garg Date: Thu, 2 Nov 2017 16:46:11 -0230 Subject: [PATCH] webhooks/gci: Support 'needswork' event_type. This commit adds support for payloads that are generated when a mentor submits a task for more work. --- .../task_submitted_by_mentor_for_more_work.json | 12 ++++++++++++ zerver/webhooks/gci/tests.py | 7 +++++++ zerver/webhooks/gci/view.py | 16 +++++++++++++--- 3 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 zerver/webhooks/gci/fixtures/task_submitted_by_mentor_for_more_work.json 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.json new file mode 100644 index 0000000000..68ae527d65 --- /dev/null +++ b/zerver/webhooks/gci/fixtures/task_submitted_by_mentor_for_more_work.json @@ -0,0 +1,12 @@ +{ + "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/tests.py b/zerver/webhooks/gci/tests.py index c24c56f6ff..ded4847dec 100644 --- a/zerver/webhooks/gci/tests.py +++ b/zerver/webhooks/gci/tests.py @@ -43,3 +43,10 @@ class GoogleCodeInTests(WebhookTestCase): expected_message = u'**eeshangarg** approved the task [Sails unspread it stopped at kearney](https://0.0.0.0:8000/dashboard/tasks/6694926301528064/).' self.send_and_test_stream_message('task_approved_by_mentor', expected_subject, expected_message) + + def test_needswork_event_message(self): + # type: () -> None + expected_subject = u'Task: Sails unspread it stopped at kearney' + expected_message = u'**eeshangarg** submitted the task [Sails unspread it stopped at kearney](http://localhost:8080/dashboard/tasks/6051711999279104/) for more work.' + self.send_and_test_stream_message('task_submitted_by_mentor_for_more_work', + expected_subject, expected_message) diff --git a/zerver/webhooks/gci/view.py b/zerver/webhooks/gci/view.py index 9c7909b737..27b65a36e6 100644 --- a/zerver/webhooks/gci/view.py +++ b/zerver/webhooks/gci/view.py @@ -59,6 +59,15 @@ def get_approve_event_body(payload): task_url=payload['task_definition_url'], ) +def get_needswork_event_body(payload): + # type: (Dict[Text, Any]) -> Text + template = "{} for more work.".format(GCI_MESSAGE_TEMPLATE.rstrip('.')) + return template.format( + actor=payload['author'], + action='submitted', + task_name=payload['task_definition_name'], + task_url=payload['task_definition_url'], + ) @api_key_only_webhook_view("Google-Code-In") @has_request_variables @@ -78,10 +87,11 @@ def api_gci_webhook(request, user_profile, stream=REQ(default='gci'), EVENTS_FUNCTION_MAPPER = { 'abandon': get_abandon_event_body, - 'comment': get_comment_event_body, - 'submit': get_submit_event_body, - 'claim': get_claim_event_body, 'approve': get_approve_event_body, + 'claim': get_claim_event_body, + 'comment': get_comment_event_body, + 'needswork': get_needswork_event_body, + 'submit': get_submit_event_body, } def get_event(payload):