@@ -2,15 +2,20 @@ name: Update PR Status
22
33on :
44 schedule :
5- - cron : " */30 * * * *" # 每30分钟执行一次
5+ - cron : " */30 * * * *"
66 workflow_dispatch :
77
8+ permissions :
9+ issues : write # ⚠️ 允许更新 issue(关闭、改 body、删 label)
10+ contents : read # 仍然不能写仓库
11+
812jobs :
913 update-status :
1014 runs-on : ubuntu-latest
1115
1216 steps :
13- - uses : actions/checkout@v4
17+ - name : Checkout repo
18+ uses : actions/checkout@v4
1419
1520 - name : Update PR Status
1621 uses : actions/github-script@v7
2126 const owner = context.repo.owner;
2227 const repo = context.repo.repo;
2328
24- let csv = fs.readFileSync('tasks.csv', 'utf8');
29+ let csv = fs.existsSync('tasks.csv')
30+ ? fs.readFileSync('tasks.csv', 'utf8')
31+ : "Project,Repo,Issue,Owner,PR,Status,Source\n";
32+
2533 let lines = csv.split('\n').filter(line => line.trim() !== '');
2634
2735 const header = lines[0];
@@ -32,20 +40,17 @@ jobs:
3240 for (let row of rows) {
3341 let parts = row.split(',');
3442
35- // 防御:补齐列
3643 while (parts.length < 7) parts.push('');
3744
3845 let issueUrl = parts[2];
3946 let prUrl = parts[4];
40- let status = parts[5];
4147
4248 if (!prUrl || !prUrl.includes('github.com')) {
4349 updatedRows.push(parts.join(','));
4450 continue;
4551 }
4652
4753 try {
48- // ===== 解析 PR =====
4954 const match = prUrl.match(/github\.com\/([^\/]+)\/([^\/]+)\/pull\/(\d+)/);
5055 if (!match) {
5156 updatedRows.push(parts.join(','));
6469
6570 let newStatus = "open";
6671
67- // ===== merged =====
6872 if (pr.merged_at) {
6973 newStatus = "merged";
7074
71- // 关闭 Issue
7275 const issueMatch = issueUrl.match(/issues\/(\d+)/);
7376 if (issueMatch) {
7477 const issue_number = parseInt(issueMatch[1]);
8184 });
8285 }
8386
84- // ===== closed(未合并)=====
8587 } else if (pr.state === "closed") {
8688 newStatus = "closed";
8789
9799
98100 let body = issueData.body || "";
99101
100- // 清空 Owner / PR / ClaimedAt
101102 body = body
102103 .replace(/Owner:.*/g, "")
103104 .replace(/PR:.*/g, "")
@@ -110,7 +111,6 @@ jobs:
110111 body
111112 });
112113
113- // 删除 label
114114 try {
115115 await github.rest.issues.removeLabel({
116116 owner,
@@ -121,7 +121,6 @@ jobs:
121121 } catch (e) {}
122122 }
123123
124- // ===== open =====
125124 } else {
126125 newStatus = "open";
127126 }
@@ -138,10 +137,14 @@ jobs:
138137 const newCsv = [header, ...updatedRows].join('\n');
139138 fs.writeFileSync('tasks.csv', newCsv);
140139
141- - name : Commit changes
142- run : |
143- git config user.name "bot"
144- git config user.email "bot@github.com"
145- git add tasks.csv
146- git commit -m "update PR status" || echo "no changes"
147- git push
140+ - name : Show CSV (Debug)
141+ run : cat tasks.csv
142+
143+ - name : Upload CSV artifact
144+ uses : actions/upload-artifact@v4
145+ with :
146+ name : tasks-csv-status
147+ path : tasks.csv
148+
149+ - name : Skip push
150+ run : echo "Read-only mode: CSV saved as artifact"
0 commit comments