diff --git a/.github/workflows/telegram-notify.yml b/.github/workflows/telegram-notify.yml index 21c4be1..7a66de7 100644 --- a/.github/workflows/telegram-notify.yml +++ b/.github/workflows/telegram-notify.yml @@ -82,49 +82,29 @@ jobs: # 添加 PR 描述(如果有) if [ -n "$PR_BODY" ] && [ "$PR_BODY" != "null" ] && [ "$PR_BODY" != "" ]; then # 使用 Python 将 Markdown 转换为 HTML(更可靠) - # 创建临时 Python 脚本 - cat > /tmp/markdown_to_html.py << 'PYEOF' -import sys -import re - -text = sys.stdin.read() - -# 转义 HTML 特殊字符(先转义,避免破坏后续的转换) -text = text.replace('&', '&') -text = text.replace('<', '<') -text = text.replace('>', '>') - -# 代码块:```code``` →
code
-text = re.sub(r'```([^`]+)```', r'\1', text, flags=re.DOTALL)
-
-# 行内代码:`code` → code(不在代码块中)
-text = re.sub(r'`([^`]+)`', r'\1', text)
-
-# 粗体:**text** → text
-text = re.sub(r'\*\*([^*]+)\*\*', r'\1', text)
-
-# 斜体:*text* → text(不在粗体或代码中)
-text = re.sub(r'(?]*)\*([^*<>]+)\*(?![^<]*>)', r'\1', text)
-
-# 链接:[text](url) → text
-text = re.sub(r'\[([^\]]+)\]\(([^)]+)\)', r'\1', text)
-
-# 标题:# Heading → Heading
-text = re.sub(r'^### (.+)$', r'\1', text, flags=re.MULTILINE)
-text = re.sub(r'^## (.+)$', r'\1', text, flags=re.MULTILINE)
-text = re.sub(r'^# (.+)$', r'\1', text, flags=re.MULTILINE)
-
-# 列表项:- item → • item
-text = re.sub(r'^- (.+)$', r'• \1', text, flags=re.MULTILINE)
-text = re.sub(r'^ - (.+)$', r' • \1', text, flags=re.MULTILINE)
-text = re.sub(r'^ - (.+)$', r' • \1', text, flags=re.MULTILINE)
-
-# 限制长度
-if len(text) > 1000:
- text = text[:1000] + '...\n(内容已截断)'
-
-print(text, end='')
-PYEOF
+ # 使用 echo 创建临时 Python 脚本,避免 heredoc 导致的 YAML 解析问题
+ echo 'import sys' > /tmp/markdown_to_html.py
+ echo 'import re' >> /tmp/markdown_to_html.py
+ echo '' >> /tmp/markdown_to_html.py
+ echo 'text = sys.stdin.read()' >> /tmp/markdown_to_html.py
+ echo '' >> /tmp/markdown_to_html.py
+ echo 'text = text.replace("&", "&")' >> /tmp/markdown_to_html.py
+ echo 'text = text.replace("<", "<")' >> /tmp/markdown_to_html.py
+ echo 'text = text.replace(">", ">")' >> /tmp/markdown_to_html.py
+ echo 'text = re.sub(r"```([^`]+)```", r"\\1", text, flags=re.DOTALL)' >> /tmp/markdown_to_html.py
+ echo 'text = re.sub(r"`([^`]+)`", r"\\1", text)' >> /tmp/markdown_to_html.py
+ echo 'text = re.sub(r"\\*\\*([^*]+)\\*\\*", r"\\1", text)' >> /tmp/markdown_to_html.py
+ echo 'text = re.sub(r"(?]*)\\*([^*<>]+)\\*(?![^<]*>)", r"\\1", text)' >> /tmp/markdown_to_html.py
+ echo 'text = re.sub(r"\\[([^\\]]+)\\]\\(([^)]+)\\)", r"\\1", text)' >> /tmp/markdown_to_html.py
+ echo 'text = re.sub(r"^### (.+)$", r"\\1", text, flags=re.MULTILINE)' >> /tmp/markdown_to_html.py
+ echo 'text = re.sub(r"^## (.+)$", r"\\1", text, flags=re.MULTILINE)' >> /tmp/markdown_to_html.py
+ echo 'text = re.sub(r"^# (.+)$", r"\\1", text, flags=re.MULTILINE)' >> /tmp/markdown_to_html.py
+ echo 'text = re.sub(r"^- (.+)$", r"• \\1", text, flags=re.MULTILINE)' >> /tmp/markdown_to_html.py
+ echo 'text = re.sub(r"^ - (.+)$", r" • \\1", text, flags=re.MULTILINE)' >> /tmp/markdown_to_html.py
+ echo 'text = re.sub(r"^ - (.+)$", r" • \\1", text, flags=re.MULTILINE)' >> /tmp/markdown_to_html.py
+ echo 'if len(text) > 1000:' >> /tmp/markdown_to_html.py
+ echo ' text = text[:1000] + "...\\n(内容已截断)"' >> /tmp/markdown_to_html.py
+ echo 'print(text, end="")' >> /tmp/markdown_to_html.py
PR_BODY_HTML=$(echo "$PR_BODY" | python3 /tmp/markdown_to_html.py)
MESSAGE="${MESSAGE}"$'\n'$'\n'"📄 PR 描述:"$'\n'"${PR_BODY_HTML}"