mirror of
https://github.com/Mr-xn/Penetration_Testing_POC.git
synced 2026-05-09 22:37:49 +08:00
feat: include new article titles in RSS update commit message
Co-authored-by: Mr-xn <18260135+Mr-xn@users.noreply.github.com>
This commit is contained in:
@@ -38,4 +38,11 @@ jobs:
|
|||||||
git config --global user.name "github-actions[bot]"
|
git config --global user.name "github-actions[bot]"
|
||||||
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
git config --global user.email "github-actions[bot]@users.noreply.github.com"
|
||||||
git add README.md
|
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
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ import requests # 引入 requests 库来处理网络请求
|
|||||||
# ================= 配置区域 =================
|
# ================= 配置区域 =================
|
||||||
RSS_URL = "https://mrxn.net/rss.php"
|
RSS_URL = "https://mrxn.net/rss.php"
|
||||||
README_PATH = "README.md"
|
README_PATH = "README.md"
|
||||||
|
COMMIT_MSG_FILE = ".commit_titles.txt"
|
||||||
|
MAX_TITLES_IN_MSG = 5
|
||||||
|
|
||||||
# 伪装 User-Agent,防止被服务器屏蔽 GitHub Actions 的 IP
|
# 伪装 User-Agent,防止被服务器屏蔽 GitHub Actions 的 IP
|
||||||
HEADERS = {
|
HEADERS = {
|
||||||
@@ -97,6 +99,7 @@ def update_readme():
|
|||||||
rss_data = fetch_rss_entries()
|
rss_data = fetch_rss_entries()
|
||||||
entries_to_add = []
|
entries_to_add = []
|
||||||
|
|
||||||
|
new_titles = []
|
||||||
print("--- Start Filtering ---")
|
print("--- Start Filtering ---")
|
||||||
for item in rss_data:
|
for item in rss_data:
|
||||||
title = item['title']
|
title = item['title']
|
||||||
@@ -113,10 +116,13 @@ def update_readme():
|
|||||||
|
|
||||||
print(f"Found NEW Entry: {title}")
|
print(f"Found NEW Entry: {title}")
|
||||||
entries_to_add.append(f"- [{title}]({link})")
|
entries_to_add.append(f"- [{title}]({link})")
|
||||||
|
new_titles.append(title)
|
||||||
print("--- End Filtering ---")
|
print("--- End Filtering ---")
|
||||||
|
|
||||||
if not entries_to_add:
|
if not entries_to_add:
|
||||||
print("Result: No new entries to write.")
|
print("Result: No new entries to write.")
|
||||||
|
if os.path.exists(COMMIT_MSG_FILE):
|
||||||
|
os.remove(COMMIT_MSG_FILE)
|
||||||
return
|
return
|
||||||
|
|
||||||
print(f"Action: Adding {len(entries_to_add)} new entries...")
|
print(f"Action: Adding {len(entries_to_add)} new entries...")
|
||||||
@@ -133,5 +139,16 @@ def update_readme():
|
|||||||
f.write("\n".join(lines))
|
f.write("\n".join(lines))
|
||||||
print("UPDATE SUCCESSFUL: README.md has been modified.")
|
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__":
|
if __name__ == "__main__":
|
||||||
update_readme()
|
update_readme()
|
||||||
|
|||||||
Reference in New Issue
Block a user