浏览代码

[bin] Strip slack url from top of message

Colin Powell 2 月之前
父节点
当前提交
e4137e0422
共有 1 个文件被更改,包括 17 次插入1 次删除
  1. 17 1
      bin/.bin/checkworkmail.py

+ 17 - 1
bin/.bin/checkworkmail.py

@@ -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