in ghd-notifier.py [0:0]
def parse_thread_action(blob):
"""Parses a thread action (thread created/edited/deleted)"""
action = blob.get("action")
discussion = blob.get("discussion")
user = discussion.get("user").get("login")
title = discussion.get("title")
category = discussion.get("category").get("slug")
url = discussion.get("html_url")
body = discussion.get("body")
repository = blob.get("repository").get("name")
node_id = discussion.get("node_id")
if action in VALID_THREAD_ACTIONS:
recipient = get_recipient(repository)
if recipient:
# The templates contain templates for the subject (first part)
# and the content of the email (second part) ... split the template
# up.
subject, text = THREAD_ACTION.split("--", 1)
# Define the name of the template for this action.
action_name = "new_discussion"
if action == "created":
action_name = "new_discussion"
elif action == "edited":
action_name = "edit_discussion"
elif action == "closed":
action_name = "close_discussion"
elif action == "reopened":
action_name = "reopen_discussion"
# Note: the subjects are checked for validity in
# https://github.com/apache/infrastructure-p6/blob/production/modules/gitbox/files/asfgit/package/asfyaml.py
# See VALID_GITHUB_SUBJECT_VARIABLES and validate_github_subject()
# The variable names listed in VALID_GITHUB_SUBJECT_VARIABLES must be defined
# here as local variables
custom_subject_line = get_custom_subject(repository, action_name) # Custom subject line?
try:
# If a custom subject line was defined, use that ...
if custom_subject_line:
subject = custom_subject_line.format(**locals())
# Otherwise use the default one, which is located in the title of the template.
else:
subject = subject.format(**locals()).strip()
except (KeyError, ValueError) as e: # Template breakage can happen, ignore
print(e)
return
unsub = recipient.replace("@", "-unsubscribe@")
text = text.format(**locals()).strip()
msg_headers = {}
msgid = "<ghd-%s-%s@gitbox.apache.org>" % (node_id, str(uuid.uuid4()))
msgid_OP = "<ghd-%s@gitbox.apache.org>" % node_id
if action == "created":
msgid = (
msgid_OP # This is the first email, make a deterministic message id
)
else:
msg_headers = {
"In-Reply-To": msgid_OP
} # Thread from the actual discussion parent
asfpy.messaging.mail(
sender=f"\"{user} (via GitHub)\" <git@apache.org>", recipient=recipient, subject=subject, message=text, messageid=msgid, headers=msg_headers
)
return f"[send] {user} {action} {url}: {title}"
return f"[skip] {user} {action} {url}: {title}"