def parse_comment_action()

in ghd-notifier.py [0:0]


def parse_comment_action(blob):
    """Parses a comment action (comment created/edited/deleted)"""
    action = blob.get("action")
    discussion = blob.get("discussion")
    discussion_state = discussion.get("state")
    comment = blob.get("comment")
    user = comment.get("user").get("login")
    title = discussion.get("title")
    category = discussion.get("category").get("slug")
    url = comment.get("html_url")
    body = comment.get("body")
    repository = blob.get("repository").get("name")
    action_human = "???"
    node_id = discussion.get("node_id")
    # If the user closes a discussion with a comment, there is
    # currently no way to distinguish this from a user commenting
    # on a closed issue (if this is even possible). We're assuming
    # that this doesn't happen and if the discussion state is
    # "closed" that the user closed with a comment.
    if action == "created" and discussion_state == "closed":
        action_human = "closed the discussion with a comment:"
        action_name = "close_discussion_with_comment"
    elif action == "created":
        action_human = "added a comment to the discussion:"
        action_name = "new_comment_discussion"
    elif action == "edited":
        action_human = "edited a comment on the discussion:"
        action_name = "edit_comment_discussion"
    elif action == "deleted":
        action_human = "deleted a comment on the discussion:"
        action_name = "delete_comment_discussion"
    if action in VALID_COMMENT_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 = COMMENT_ACTION.split("--", 1)

            # 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

            msgid = "<ghd-%s-%s@gitbox.apache.org>" % (node_id, str(uuid.uuid4()))
            msgid_OP = "<ghd-%s@gitbox.apache.org>" % node_id
            unsub = recipient.replace("@", "-unsubscribe@")
            text = text.format(**locals()).strip()
            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] [comment] {user} {action} {url}: {title}"
    return f"[skip] [comment] {user} {action} {url}: {title}"