Skip to content

Commit b1f5e40

Browse files
authored
Update sync-issue-to-csv.yml
1 parent cfede4a commit b1f5e40

1 file changed

Lines changed: 12 additions & 13 deletions

File tree

.github/workflows/sync-issue-to-csv.yml

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ jobs:
1818
runs-on: ubuntu-latest
1919

2020
steps:
21-
- uses: actions/checkout@v4
21+
- name: Checkout repo
22+
uses: actions/checkout@v4
2223

2324
- name: Sync Issue to CSV
2425
uses: actions/github-script@v7
@@ -29,7 +30,7 @@ jobs:
2930
const repo = context.repo.repo;
3031
3132
// ===== 读取 CSV =====
32-
let csv = fs.readFileSync('tasks.csv', 'utf8');
33+
let csv = fs.existsSync('tasks.csv') ? fs.readFileSync('tasks.csv', 'utf8') : "Project,Repo,Issue,Owner,PR,Status,Source\n";
3334
let lines = csv.split('\n').filter(line => line.trim() !== '');
3435
const header = lines[0];
3536
let rows = lines.slice(1);
@@ -52,7 +53,7 @@ jobs:
5253
// ===== Repo =====
5354
const repoMatch = body.match(/https:\/\/github\.com\/[^\s]+/);
5455
const repoUrl = repoMatch ? repoMatch[0] : "";
55-
if (!repoUrl) continue; // 必须有 repo
56+
if (!repoUrl) continue;
5657
5758
// ===== Owner =====
5859
const ownerMatch = body.match(/Owner:\s*@([^\s]+)/);
@@ -65,32 +66,24 @@ jobs:
6566
// ===== Status =====
6667
let status = "";
6768
if (prUrl) {
68-
// 默认 open,如果 merged/closed 信息在 body 可解析,这里简单占位
6969
const mergedMatch = body.match(/Status:\s*(merged|closed|open)/i);
7070
status = mergedMatch ? mergedMatch[1].toLowerCase() : "open";
71-
} else {
72-
status = "";
7371
}
7472
7573
let found = false;
76-
7774
rows = rows.map(row => {
7875
let parts = row.split(',');
7976
while (parts.length < 7) parts.push('');
80-
81-
// Project,Repo,Issue,Owner,PR,Status,Source
8277
if (parts[2] === issueUrl || (parts[2] === "" && parts[1] === repoUrl)) {
8378
parts[2] = issueUrl;
8479
parts[3] = taskOwner;
8580
parts[4] = prUrl;
8681
parts[5] = status;
8782
found = true;
8883
}
89-
9084
return parts.join(',');
9185
});
9286
93-
// ===== 不存在就新增 =====
9487
if (!found) {
9588
const project = title.replace("[Task]", "").trim();
9689
const newRow = [
@@ -106,12 +99,18 @@ jobs:
10699
}
107100
}
108101
109-
// ===== 写回 CSV(临时环境) =====
102+
// ===== 写回 CSV =====
110103
const newCsv = [header, ...rows].join('\n');
111104
fs.writeFileSync('tasks.csv', newCsv);
112105
113106
- name: Show CSV (Debug)
114107
run: cat tasks.csv
115108

116-
- name: Skip push
109+
- name: Upload CSV artifact
110+
uses: actions/upload-artifact@v3
111+
with:
112+
name: tasks-csv
113+
path: tasks.csv
114+
115+
- name: Skip push (Read-only)
117116
run: echo "No write permission, CSV changes are local to runner"

0 commit comments

Comments
 (0)