mirror of https://github.com/zulip/zulip.git
webhooks/gci: Improve message formatting.
* Use Student Name instead of Task Name in subject. * Use Task Instance URL instead of Task Definition URL (and workaround for a bug in the API).
This commit is contained in:
parent
2d7536bf05
commit
bea653fabc
|
@ -9,37 +9,37 @@ class GoogleCodeInTests(WebhookTestCase):
|
|||
FIXTURE_DIR_NAME = 'gci'
|
||||
|
||||
def test_abandon_event_message(self) -> None:
|
||||
expected_subject = u'Task: Sails unspread it stopped at kearney'
|
||||
expected_message = u'**student-yqqtag** abandoned the task [Sails unspread it stopped at kearney](https://0.0.0.0:8000/dashboard/tasks/6694926301528064/).'
|
||||
expected_subject = u'student-yqqtag'
|
||||
expected_message = u'**student-yqqtag** abandoned the task [Sails unspread it stopped at kearney](https://codein.withgoogle.com/dashboard/task-instances/6296903092273152/).'
|
||||
self.send_and_test_stream_message('task_abandoned_by_student',
|
||||
expected_subject, expected_message)
|
||||
|
||||
def test_comment_event_message(self) -> None:
|
||||
expected_subject = u'Task: Sails unspread it stopped at kearney'
|
||||
expected_message = u'**student-yqqtag** commented on the task [Sails unspread it stopped at kearney](https://0.0.0.0:8000/dashboard/tasks/6694926301528064/).'
|
||||
expected_subject = u'student-yqqtag'
|
||||
expected_message = u'**student-yqqtag** commented on the task [Sails unspread it stopped at kearney](https://codein.withgoogle.com/dashboard/task-instances/6296903092273152/).'
|
||||
self.send_and_test_stream_message('student_commented_on_task',
|
||||
expected_subject, expected_message)
|
||||
|
||||
def test_submit_event_message(self) -> None:
|
||||
expected_subject = u'Task: Sails unspread it stopped at kearney'
|
||||
expected_message = u'**student-yqqtag** submitted the task [Sails unspread it stopped at kearney](https://0.0.0.0:8000/dashboard/tasks/6694926301528064/).'
|
||||
expected_subject = u'student-yqqtag'
|
||||
expected_message = u'**student-yqqtag** submitted the task [Sails unspread it stopped at kearney](https://codein.withgoogle.com/dashboard/task-instances/6296903092273152/).'
|
||||
self.send_and_test_stream_message('task_submitted_by_student',
|
||||
expected_subject, expected_message)
|
||||
|
||||
def test_claim_event_message(self) -> None:
|
||||
expected_subject = u'Task: Sails unspread it stopped at kearney'
|
||||
expected_message = u'**student-yqqtag** claimed the task [Sails unspread it stopped at kearney](https://0.0.0.0:8000/dashboard/tasks/6694926301528064/).'
|
||||
expected_subject = u'student-yqqtag'
|
||||
expected_message = u'**student-yqqtag** claimed the task [Sails unspread it stopped at kearney](https://codein.withgoogle.com/dashboard/task-instances/6296903092273152/).'
|
||||
self.send_and_test_stream_message('task_claimed_by_student',
|
||||
expected_subject, expected_message)
|
||||
|
||||
def test_approve_event_message(self) -> None:
|
||||
expected_subject = u'Task: Sails unspread it stopped at kearney'
|
||||
expected_message = u'**eeshangarg** approved the task [Sails unspread it stopped at kearney](https://0.0.0.0:8000/dashboard/tasks/6694926301528064/).'
|
||||
expected_subject = u'student-yqqtag'
|
||||
expected_message = u'**eeshangarg** approved the task [Sails unspread it stopped at kearney](https://codein.withgoogle.com/dashboard/task-instances/6296903092273152/).'
|
||||
self.send_and_test_stream_message('task_approved_by_mentor',
|
||||
expected_subject, expected_message)
|
||||
|
||||
def test_needswork_event_message(self) -> 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.'
|
||||
expected_subject = u'student-yqqtag'
|
||||
expected_message = u'**eeshangarg** submitted the task [Sails unspread it stopped at kearney](https://codein.withgoogle.com/dashboard/task-instances/5136918324969472/) for more work.'
|
||||
self.send_and_test_stream_message('task_submitted_by_mentor_for_more_work',
|
||||
expected_subject, expected_message)
|
||||
|
|
|
@ -9,9 +9,12 @@ from zerver.lib.response import json_success
|
|||
from zerver.models import UserProfile
|
||||
|
||||
GCI_MESSAGE_TEMPLATE = u'**{actor}** {action} the task [{task_name}]({task_url}).'
|
||||
GCI_SUBJECT_TEMPLATE = u'Task: {task_name}'
|
||||
GCI_SUBJECT_TEMPLATE = u'{student_name}'
|
||||
|
||||
|
||||
def build_instance_url(instance_id):
|
||||
return "https://codein.withgoogle.com/dashboard/task-instances/{}/".format(instance_id)
|
||||
|
||||
class UnknownEventType(Exception):
|
||||
pass
|
||||
|
||||
|
@ -20,7 +23,7 @@ def get_abandon_event_body(payload: Dict[Text, Any]) -> Text:
|
|||
actor=payload['task_claimed_by'],
|
||||
action='{}ed'.format(payload['event_type']),
|
||||
task_name=payload['task_definition_name'],
|
||||
task_url=payload['task_definition_url'],
|
||||
task_url=build_instance_url(payload['task_instance']),
|
||||
)
|
||||
|
||||
def get_submit_event_body(payload: Dict[Text, Any]) -> Text:
|
||||
|
@ -28,7 +31,7 @@ def get_submit_event_body(payload: Dict[Text, Any]) -> Text:
|
|||
actor=payload['task_claimed_by'],
|
||||
action='{}ted'.format(payload['event_type']),
|
||||
task_name=payload['task_definition_name'],
|
||||
task_url=payload['task_definition_url'],
|
||||
task_url=build_instance_url(payload['task_instance']),
|
||||
)
|
||||
|
||||
def get_comment_event_body(payload: Dict[Text, Any]) -> Text:
|
||||
|
@ -36,7 +39,7 @@ def get_comment_event_body(payload: Dict[Text, Any]) -> Text:
|
|||
actor=payload['author'],
|
||||
action='{}ed on'.format(payload['event_type']),
|
||||
task_name=payload['task_definition_name'],
|
||||
task_url=payload['task_definition_url'],
|
||||
task_url=build_instance_url(payload['task_instance']),
|
||||
)
|
||||
|
||||
def get_claim_event_body(payload: Dict[Text, Any]) -> Text:
|
||||
|
@ -44,7 +47,7 @@ def get_claim_event_body(payload: Dict[Text, Any]) -> Text:
|
|||
actor=payload['task_claimed_by'],
|
||||
action='{}ed'.format(payload['event_type']),
|
||||
task_name=payload['task_definition_name'],
|
||||
task_url=payload['task_definition_url'],
|
||||
task_url=build_instance_url(payload['task_instance']),
|
||||
)
|
||||
|
||||
def get_approve_event_body(payload: Dict[Text, Any]) -> Text:
|
||||
|
@ -52,7 +55,7 @@ def get_approve_event_body(payload: Dict[Text, Any]) -> Text:
|
|||
actor=payload['author'],
|
||||
action='{}d'.format(payload['event_type']),
|
||||
task_name=payload['task_definition_name'],
|
||||
task_url=payload['task_definition_url'],
|
||||
task_url=build_instance_url(payload['task_instance']),
|
||||
)
|
||||
|
||||
def get_needswork_event_body(payload: Dict[Text, Any]) -> Text:
|
||||
|
@ -61,7 +64,7 @@ def get_needswork_event_body(payload: Dict[Text, Any]) -> Text:
|
|||
actor=payload['author'],
|
||||
action='submitted',
|
||||
task_name=payload['task_definition_name'],
|
||||
task_url=payload['task_definition_url'],
|
||||
task_url=build_instance_url(payload['task_instance']),
|
||||
)
|
||||
|
||||
@api_key_only_webhook_view("Google-Code-In")
|
||||
|
@ -73,7 +76,7 @@ def api_gci_webhook(request, user_profile, stream=REQ(default='gci'),
|
|||
if event is not None:
|
||||
body = get_body_based_on_event(event)(payload)
|
||||
subject = GCI_SUBJECT_TEMPLATE.format(
|
||||
task_name=payload['task_definition_name']
|
||||
student_name=payload['task_claimed_by']
|
||||
)
|
||||
check_send_stream_message(user_profile, request.client,
|
||||
stream, subject, body)
|
||||
|
|
Loading…
Reference in New Issue