-
Notifications
You must be signed in to change notification settings - Fork 0
163 lines (128 loc) · 4.79 KB
/
Copy pathsync-issue-to-csv.yml
File metadata and controls
163 lines (128 loc) · 4.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
name: Sync Issue to CSV
on:
issues:
types: [opened, edited, labeled]
issue_comment:
types: [created]
workflow_dispatch:
permissions:
issues: read
contents: read
jobs:
sync:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Sync Issue to CSV
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const owner = context.repo.owner;
const repo = context.repo.repo;
const csvPath = 'tasks.csv';
// ===== 确保 CSV 存在 =====
if (!fs.existsSync(csvPath)) {
console.log("⚠️ CSV not found, create new");
fs.writeFileSync(csvPath, "Project,Repo,Issue,Owner,PR,Status,Source\n");
}
let csv = fs.readFileSync(csvPath, 'utf8');
let lines = csv.split('\n').filter(line => line.trim() !== '');
const header = lines[0];
let rows = lines.slice(1);
console.log("📄 Existing rows:", rows.length);
// ===== 获取 issue =====
let issues = [];
if (context.payload.issue) {
// 正常触发(推荐)
issues = [context.payload.issue];
console.log("✅ Triggered by issue event");
} else {
// 手动触发
console.log("⚠️ Manual run detected → skip to avoid clearing CSV");
return;
}
let updated = false;
for (const issue of issues) {
const title = issue.title;
const body = issue.body || "";
const issueNumber = issue.number;
const issueUrl = `https://github.com/${owner}/${repo}/issues/${issueNumber}`;
console.log("🔍 Processing:", issueUrl);
// ===== Repo(增强匹配)=====
const repoMatch = body.match(/https:\/\/github\.com\/[^\s)\n]+/);
const repoUrl = repoMatch ? repoMatch[0] : null;
if (!repoUrl) {
console.log("❌ Skip (no repo):", issueUrl);
continue;
}
// ===== Owner =====
const ownerMatch = body.match(/Owner:\s*@([^\s]+)/);
const taskOwner = ownerMatch ? ownerMatch[1] : "";
// ===== PR =====
const prMatch = body.match(/PR:\s*(https:\/\/[^\s]+)/);
const prUrl = prMatch ? prMatch[1] : "";
// ===== Status =====
let status = prUrl ? "open" : "";
// ===== Source(支持 body + label)=====
let source = "official";
// body 优先
const sourceMatch = body.match(/Source:\s*(\w+)/i);
if (sourceMatch) {
source = sourceMatch[1].toLowerCase();
}
// label 覆盖
if (issue.labels.some(l => l.name.toLowerCase() === "proposal")) {
source = "community";
}
if (!["official", "community"].includes(source)) {
source = "official";
}
let found = false;
rows = rows.map(row => {
let parts = row.split(',');
while (parts.length < 7) parts.push('');
if (parts[2] === issueUrl || (parts[2] === "" && parts[1] === repoUrl)) {
parts[0] = title.replace("[Task]", "").trim();
parts[1] = repoUrl;
parts[2] = issueUrl;
parts[3] = taskOwner;
parts[4] = prUrl;
parts[5] = status;
parts[6] = source;
found = true;
updated = true;
}
return parts.join(',');
});
// ===== 新增 =====
if (!found) {
const newRow = [
title.replace("[Task]", "").trim(),
repoUrl,
issueUrl,
taskOwner,
prUrl,
status,
source
].join(',');
rows.push(newRow);
updated = true;
}
}
// ===== 防止清空 CSV =====
if (!updated) {
console.log("⚠️ No updates, skip writing CSV");
return;
}
const newCsv = [header, ...rows].join('\n');
fs.writeFileSync(csvPath, newCsv);
console.log("✅ CSV updated:", rows.length, "rows");
- name: Show CSV (debug)
run: cat tasks.csv
- name: Upload CSV Artifact
uses: actions/upload-artifact@v4
with:
name: tasks-csv
path: tasks.csv