Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 34 additions & 74 deletions scripts/zulip_emoji_merge_delegate.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,107 +68,67 @@
content = message['content']
# Check for emoji reactions
reactions = message['reactions']
has_peace_sign = any(reaction['emoji_name'] == 'peace_sign' for reaction in reactions)
has_bors = any(reaction['emoji_name'] == 'bors' for reaction in reactions)
has_merge = any(reaction['emoji_name'] == 'merge' for reaction in reactions)
has_awaiting_author = any(reaction['emoji_name'] == 'writing' for reaction in reactions)
has_maintainer_merge = any(reaction['emoji_name'] == 'hammer' for reaction in reactions)
has_closed = any(reaction['emoji_name'] == 'closed-pr' for reaction in reactions)
# Does this message have any reaction with an emoji |name|?
has_reaction = lambda name: any(reaction['emoji_name'] == name for reaction in reactions)

has_peace_sign = has_reaction('peace_sign')
has_bors = has_reaction('bors')
has_merge = has_reaction('merge')
has_awaiting_author = has_reaction('writing')
has_maintainer_merge = has_reaction('hammer')
has_closed = has_reaction('closed-pr')
first_in_thread = hashPR.search(message['subject']) and message['display_recipient'] == 'PR reviews' and message['subject'] not in first_by_subject
first_by_subject[message['subject']] = message['id']
match = urlPR.search(content) or first_in_thread
if match:
print(f"matched: '{message}'")

# removing previous emoji reactions
# if the emoji is a custom emoji, add the fields `emoji_code` and `reaction_type` as well
# If the emoji is a custom emoji, add the fields `emoji_code` and `reaction_type` as well.
print("Removing previous reactions, if present.")
if has_peace_sign:
print('Removing peace_sign')
def remove_reaction(name: str, emoji_name: str, **kwargs) -> None:
print(f'Removing {name}')
result = client.remove_reaction({
"message_id": message['id'],
"emoji_name": "peace_sign"
"emoji_name": emoji_name,
**kwargs
})
print(f"result: '{result}'")

if has_peace_sign:
remove_reaction('delegated', 'peace_sign')
if has_bors:
print('Removing bors')
result = client.remove_reaction({
"message_id": message['id'],
"emoji_name": "bors",
"emoji_code": "22134",
"reaction_type": "realm_emoji",
})
print(f"result: '{result}'")
remove_reaction("bors", "bors", emoji_code="22134", reaction_type="realm_emoji")
if has_merge:
print('Removing merge')
result = client.remove_reaction({
"message_id": message['id'],
"emoji_name": "merge"
})
print(f"result: '{result}'")
remove_reaction('merge', 'merge')
if has_maintainer_merge:
print('Removing maintainer-merge')
result = client.remove_reaction({
"message_id": message['id'],
"emoji_name": "hammer"
})
print(f"result: '{result}'")
remove_reaction('maintainer-merge', 'hammer')
if has_awaiting_author:
print('Removing awaiting-author')
result = client.remove_reaction({
"message_id": message['id'],
"emoji_name": "writing"
})
print(f"result: '{result}'")
remove_reaction('awaiting-author', 'writing')
if has_closed:
print('Removing closed-pr')
result = client.remove_reaction({
"message_id": message['id'],
"emoji_name": "closed-pr",
"emoji_code": "61293", # 61282 was the earlier version of the emoji
"reaction_type": "realm_emoji",
})
print(f"result: '{result}'")

# 61282 was the earlier version of the emoji
remove_reaction('closed-pr', 'closed-pr', emoji_code="61293", reaction_type="realm_emoji")

# applying appropriate emoji reaction
print("Applying reactions, as appropriate.")
if 'ready-to-merge' == LABEL:
print('adding ready-to-merge')
client.add_reaction({
def add_reaction(name: str, emoji_name: str) -> none:
print(f'adding {name}')
result = client.add_reaction({
"message_id": message['id'],
"emoji_name": "bors"
"emoji_name": emoji_name
})
if 'ready-to-merge' == LABEL:
add_reaction('ready-to-merge', 'bors')
elif 'delegated' == LABEL:
print('adding delegated')
client.add_reaction({
"message_id": message['id'],
"emoji_name": "peace_sign"
})
add_reaction('delegated', 'peace_sign')
elif 'maintainer-merge' == LABEL:
print('adding maintainer-merge')
client.add_reaction({
"message_id": message['id'],
"emoji_name": "hammer"
})
add_reaction('maintainer-merge', 'hammer')
elif LABEL == 'labeled':
print('adding awaiting-author')
client.add_reaction({
"message_id": message['id'],
"emoji_name": "writing"
})
add_reaction('awaiting-author', 'writing')
elif LABEL == 'closed':
print('adding closed-pr')
client.add_reaction({
"message_id": message['id'],
"emoji_name": "closed-pr"
})
add_reaction('closed-pr', 'closed-pr')
elif LABEL == 'unlabeled':
print('awaiting-author removed')
# the reaction was already removed.
elif LABEL.startswith("[Merged by Bors]"):
print('adding [Merged by Bors]')
client.add_reaction({
"message_id": message['id'],
"emoji_name": "merge"
})
add_reaction('[Merged by Bors]', 'merge')