webhooks/trello: Support updateCheckItemStateOnCard events.

This commit is contained in:
Eeshan Garg 2019-02-21 19:30:06 -03:30 committed by Tim Abbott
parent 788dd48c93
commit 912931e1bc
4 changed files with 254 additions and 2 deletions

View File

@ -0,0 +1,115 @@
{
"model":{
"id":"597958d15c95392f2830e9f5",
"name":"Zulip",
"desc":"",
"descData":null,
"closed":false,
"idOrganization":null,
"pinned":false,
"url":"https://trello.com/b/l9NqJcCd/zulip",
"shortUrl":"https://trello.com/b/l9NqJcCd",
"prefs":{
"permissionLevel":"private",
"voting":"disabled",
"comments":"members",
"invitations":"members",
"selfJoin":false,
"cardCovers":true,
"cardAging":"regular",
"calendarFeedEnabled":false,
"background":"blue",
"backgroundImage":null,
"backgroundImageScaled":null,
"backgroundTile":false,
"backgroundBrightness":"dark",
"backgroundColor":"#0079BF",
"backgroundBottomColor":"#0079BF",
"backgroundTopColor":"#0079BF",
"canBePublic":true,
"canBeEnterprise":true,
"canBeOrg":true,
"canBePrivate":true,
"canInvite":true
},
"labelNames":{
"green":"",
"yellow":"",
"orange":"",
"red":"",
"purple":"",
"blue":"",
"sky":"",
"lime":"",
"pink":"",
"black":""
}
},
"action":{
"id":"5c6f1c2149a22f1567ea1bc1",
"idMemberCreator":"59780df0f985476615f5ea66",
"data":{
"checkItem":{
"state":"complete",
"name":"Tomatoes",
"id":"5c6f1a64af711461f2534921"
},
"checklist":{
"name":"Checklist",
"id":"5c6f1a58d61c527c91892ba1"
},
"card":{
"shortLink":"R2thJK3P",
"idShort":3,
"name":"Something something",
"id":"5abd0cc638506013c1ebb33f"
},
"board":{
"shortLink":"l9NqJcCd",
"name":"Zulip",
"id":"597958d15c95392f2830e9f5"
}
},
"type":"updateCheckItemStateOnCard",
"date":"2019-02-21T21:46:09.784Z",
"limits":{
},
"display":{
"translationKey":"action_completed_checkitem",
"entities":{
"checkitem":{
"type":"checkItem",
"nameHtml":"Tomatoes",
"id":"5c6f1a64af711461f2534921",
"state":"complete",
"text":"Tomatoes"
},
"card":{
"type":"card",
"id":"5abd0cc638506013c1ebb33f",
"shortLink":"R2thJK3P",
"text":"Something something"
},
"memberCreator":{
"type":"member",
"id":"59780df0f985476615f5ea66",
"username":"eeshangarg",
"text":"Eeshan Garg"
}
}
},
"memberCreator":{
"id":"59780df0f985476615f5ea66",
"avatarHash":null,
"avatarUrl":null,
"fullName":"Eeshan Garg",
"idMemberReferrer":null,
"initials":"EG",
"nonPublic":{
},
"username":"eeshangarg"
}
}
}

View File

@ -0,0 +1,115 @@
{
"model":{
"id":"597958d15c95392f2830e9f5",
"name":"Zulip",
"desc":"",
"descData":null,
"closed":false,
"idOrganization":null,
"pinned":false,
"url":"https://trello.com/b/l9NqJcCd/zulip",
"shortUrl":"https://trello.com/b/l9NqJcCd",
"prefs":{
"permissionLevel":"private",
"voting":"disabled",
"comments":"members",
"invitations":"members",
"selfJoin":false,
"cardCovers":true,
"cardAging":"regular",
"calendarFeedEnabled":false,
"background":"blue",
"backgroundImage":null,
"backgroundImageScaled":null,
"backgroundTile":false,
"backgroundBrightness":"dark",
"backgroundColor":"#0079BF",
"backgroundBottomColor":"#0079BF",
"backgroundTopColor":"#0079BF",
"canBePublic":true,
"canBeEnterprise":true,
"canBeOrg":true,
"canBePrivate":true,
"canInvite":true
},
"labelNames":{
"green":"",
"yellow":"",
"orange":"",
"red":"",
"purple":"",
"blue":"",
"sky":"",
"lime":"",
"pink":"",
"black":""
}
},
"action":{
"id":"5c6f28a04e959901fe61a6de",
"idMemberCreator":"59780df0f985476615f5ea66",
"data":{
"checkItem":{
"state":"incomplete",
"name":"Tomatoes",
"id":"5c6f1a64af711461f2534921"
},
"checklist":{
"name":"Checklist",
"id":"5c6f1a58d61c527c91892ba1"
},
"card":{
"shortLink":"R2thJK3P",
"idShort":3,
"name":"Something something",
"id":"5abd0cc638506013c1ebb33f"
},
"board":{
"shortLink":"l9NqJcCd",
"name":"Zulip",
"id":"597958d15c95392f2830e9f5"
}
},
"type":"updateCheckItemStateOnCard",
"date":"2019-02-21T22:39:28.225Z",
"limits":{
},
"display":{
"translationKey":"action_marked_checkitem_incomplete",
"entities":{
"checkitem":{
"type":"checkItem",
"nameHtml":"Tomatoes",
"id":"5c6f1a64af711461f2534921",
"state":"incomplete",
"text":"Tomatoes"
},
"card":{
"type":"card",
"id":"5abd0cc638506013c1ebb33f",
"shortLink":"R2thJK3P",
"text":"Something something"
},
"memberCreator":{
"type":"member",
"id":"59780df0f985476615f5ea66",
"username":"eeshangarg",
"text":"Eeshan Garg"
}
}
},
"memberCreator":{
"id":"59780df0f985476615f5ea66",
"avatarHash":null,
"avatarUrl":null,
"fullName":"Eeshan Garg",
"idMemberReferrer":null,
"initials":"EG",
"nonPublic":{
},
"username":"eeshangarg"
}
}
}

View File

@ -68,6 +68,14 @@ class TrelloHookTests(WebhookTestCase):
expected_message = u"TomaszKolek added the Checklist checklist to [New card](https://trello.com/c/xPKXoSTQ)."
self.send_and_test_stream_message('adding_checklist_to_card', u"Welcome Board", expected_message)
def test_trello_webhook_when_check_item_is_checked(self) -> None:
expected_message = u"Eeshan Garg checked **Tomatoes** in **Checklist** ([Something something](https://trello.com/c/R2thJK3P))."
self.send_and_test_stream_message('check_item_on_card_checklist', u"Zulip", expected_message)
def test_trello_webhook_when_check_item_is_unchecked(self) -> None:
expected_message = u"Eeshan Garg unchecked **Tomatoes** in **Checklist** ([Something something](https://trello.com/c/R2thJK3P))."
self.send_and_test_stream_message('uncheck_item_on_card_checklist', u"Zulip", expected_message)
def test_trello_webhook_when_member_was_removed_from_board(self) -> None:
expected_message = u"TomaszKolek removed Trello from [Welcome Board](https://trello.com/b/iqXXzYEj)."
self.send_and_test_stream_message('removing_member_from_board', u"Welcome Board", expected_message)

View File

@ -11,7 +11,8 @@ SUPPORTED_CARD_ACTIONS = [
u'removeMemberFromCard',
u'addAttachmentToCard',
u'addChecklistToCard',
u'commentCard'
u'commentCard',
u'updateCheckItemStateOnCard',
]
IGNORED_CARD_ACTIONS = [
@ -36,6 +37,7 @@ REMOVE_MEMBER = u'removeMemberFromCard'
ADD_ATTACHMENT = u'addAttachmentToCard'
ADD_CHECKLIST = u'addChecklistToCard'
COMMENT = u'commentCard'
UPDATE_CHECK_ITEM_STATE = u'updateCheckItemStateOnCard'
TRELLO_CARD_URL_TEMPLATE = u'[{card_name}]({card_url})'
@ -58,7 +60,8 @@ ACTIONS_TO_MESSAGE_MAPPER = {
REMOVE_MEMBER: u'removed {member_name} from {card_url_template}.',
ADD_ATTACHMENT: u'added [{attachment_name}]({attachment_url}) to {card_url_template}.',
ADD_CHECKLIST: u'added the {checklist_name} checklist to {card_url_template}.',
COMMENT: u'commented on {card_url_template}\n~~~ quote\n{text}\n~~~\n'
COMMENT: u'commented on {card_url_template}\n~~~ quote\n{text}\n~~~\n',
UPDATE_CHECK_ITEM_STATE: u'{action} **{item_name}** in **{checklist_name}** ({card_url_template}).'
}
def prettify_date(date_string: str) -> str:
@ -119,6 +122,16 @@ def get_added_checklist_body(payload: Mapping[str, Any], action_type: str) -> st
}
return fill_appropriate_message_content(payload, action_type, data)
def get_update_check_item_body(payload: Mapping[str, Any], action_type: str) -> str:
action = get_action_data(payload)
state = action['checkItem']['state']
data = {
'action': 'checked' if state == 'complete' else 'unchecked',
'checklist_name': action['checklist'].get('name'),
'item_name': action['checkItem'].get('name'),
}
return fill_appropriate_message_content(payload, action_type, data)
def get_added_attachment_body(payload: Mapping[str, Any], action_type: str) -> str:
data = {
'attachment_url': get_action_data(payload)['attachment'].get('url'),
@ -232,4 +245,5 @@ ACTIONS_TO_FILL_BODY_MAPPER = {
ADD_ATTACHMENT: get_added_attachment_body,
ADD_CHECKLIST: get_added_checklist_body,
COMMENT: get_comment_body,
UPDATE_CHECK_ITEM_STATE: get_update_check_item_body,
}