From 5255b25ba26f150b9d540b3b24bb08ba3b580bee Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 23 Feb 2026 14:00:42 +0000 Subject: [PATCH] feat: include new article titles in RSS update commit message Co-authored-by: Mr-xn <18260135+Mr-xn@users.noreply.github.com> --- .github/workflows/rss_update.yml | 9 ++++++++- scripts/update_readme.py | 17 +++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/.github/workflows/rss_update.yml b/.github/workflows/rss_update.yml index 19ab720..fdce4d2 100644 --- a/.github/workflows/rss_update.yml +++ b/.github/workflows/rss_update.yml @@ -38,4 +38,11 @@ jobs: git config --global user.name "github-actions[bot]" git config --global user.email "github-actions[bot]@users.noreply.github.com" git add README.md - git diff --quiet && git diff --staged --quiet || (git commit -m "docs: auto update RSS [skip ci]" && git push) + + # 如果脚本未生成 commit message 文件,则使用默认值 + if [ ! -f .commit_titles.txt ]; then + echo "docs: auto update RSS [skip ci]" > .commit_titles.txt + fi + + git diff --quiet && git diff --staged --quiet || (git commit -F .commit_titles.txt && git push) + rm -f .commit_titles.txt diff --git a/scripts/update_readme.py b/scripts/update_readme.py index ef7c750..7e14f11 100644 --- a/scripts/update_readme.py +++ b/scripts/update_readme.py @@ -6,6 +6,8 @@ import requests # 引入 requests 库来处理网络请求 # ================= 配置区域 ================= RSS_URL = "https://mrxn.net/rss.php" README_PATH = "README.md" +COMMIT_MSG_FILE = ".commit_titles.txt" +MAX_TITLES_IN_MSG = 5 # 伪装 User-Agent,防止被服务器屏蔽 GitHub Actions 的 IP HEADERS = { @@ -97,6 +99,7 @@ def update_readme(): rss_data = fetch_rss_entries() entries_to_add = [] + new_titles = [] print("--- Start Filtering ---") for item in rss_data: title = item['title'] @@ -113,10 +116,13 @@ def update_readme(): print(f"Found NEW Entry: {title}") entries_to_add.append(f"- [{title}]({link})") + new_titles.append(title) print("--- End Filtering ---") if not entries_to_add: print("Result: No new entries to write.") + if os.path.exists(COMMIT_MSG_FILE): + os.remove(COMMIT_MSG_FILE) return print(f"Action: Adding {len(entries_to_add)} new entries...") @@ -133,5 +139,16 @@ def update_readme(): f.write("\n".join(lines)) print("UPDATE SUCCESSFUL: README.md has been modified.") + # 生成 commit message 并写入临时文件 + n = len(new_titles) + displayed = new_titles[:MAX_TITLES_IN_MSG] + titles_str = " | ".join(displayed) + if n > MAX_TITLES_IN_MSG: + titles_str += f" ... 等共{n}篇" + commit_msg = f"docs: 更新 {n} 篇文章 - {titles_str} [skip ci]" + with open(COMMIT_MSG_FILE, 'w', encoding='utf-8') as f: + f.write(commit_msg) + print(f"Commit message written: {commit_msg}") + if __name__ == "__main__": update_readme()