[bin] Strip slack url from top of message

This commit is contained in:
2025-07-24 03:03:08 -04:00
parent bafdbd5486
commit e4137e0422

View File

@ -78,6 +78,22 @@ def clean_slack_body(body):
)
return cleaned.strip()
def clean_and_relocate_slack_footer(body):
# Match the "View in the archives" block
archive_pattern = re.compile(
r"(@\w+)?\s*View in the archives: (https://.*?\.slack\.com/\S+)", re.IGNORECASE
)
match = archive_pattern.search(body)
if match:
slack_url = match.group(2).strip()
cleaned_body = archive_pattern.sub("", body).strip()
# Format the link cleanly at the bottom
footer = f"🔗 View in Slack: {slack_url}"
return f"{cleaned_body}\n\n---\n{footer}"
else:
return body.strip()
def extract_github_link(subject, body):
pr_match = re.search(r'\(PR\s+#(\d+)\)', subject)
@ -157,7 +173,7 @@ def check_notifications():
elif is_slack_email(from_email, subject):
source = "Slack"
link = ""
body = clean_slack_body(body)
body = clean_and_relocate_slack_footer(clean_slack_body(body))
else:
print(f"Skipping non-matching email: {subject}")
continue