-
Notifications
You must be signed in to change notification settings - Fork 0
151 lines (114 loc) · 4.09 KB
/
Copy pathupdate-pr-status.yml
File metadata and controls
151 lines (114 loc) · 4.09 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
name: Update PR Status
on:
schedule:
- cron: "*/30 * * * *"
workflow_dispatch:
permissions:
issues: write
contents: read
jobs:
update-status:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4
- name: Update PR Status
uses: actions/github-script@v7
with:
script: |
const fs = require('fs');
const owner = context.repo.owner;
const repo = context.repo.repo;
let csv = fs.existsSync('tasks.csv')
? fs.readFileSync('tasks.csv', 'utf8')
: "Project,Repo,Issue,Owner,PR,Status,Source\n";
let lines = csv.split('\n').filter(line => line.trim() !== '');
const header = lines[0];
let rows = lines.slice(1);
let updatedRows = [];
for (let row of rows) {
let parts = row.split(',');
while (parts.length < 7) parts.push('');
let issueUrl = parts[2];
let prUrl = parts[4];
if (!prUrl || !prUrl.includes('github.com')) {
updatedRows.push(parts.join(','));
continue;
}
try {
const match = prUrl.match(/github\.com\/([^\/]+)\/([^\/]+)\/pull\/(\d+)/);
if (!match) {
updatedRows.push(parts.join(','));
continue;
}
const prOwner = match[1];
const prRepo = match[2];
const pull_number = parseInt(match[3]);
const { data: pr } = await github.rest.pulls.get({
owner: prOwner,
repo: prRepo,
pull_number
});
let newStatus = "open";
if (pr.merged_at) {
newStatus = "merged";
const issueMatch = issueUrl.match(/issues\/(\d+)/);
if (issueMatch) {
const issue_number = parseInt(issueMatch[1]);
await github.rest.issues.update({
owner,
repo,
issue_number,
state: "closed"
});
}
} else if (pr.state === "closed") {
newStatus = "closed";
const issueMatch = issueUrl.match(/issues\/(\d+)/);
if (issueMatch) {
const issue_number = parseInt(issueMatch[1]);
const { data: issueData } = await github.rest.issues.get({
owner,
repo,
issue_number
});
let body = issueData.body || "";
body = body
.replace(/Owner:.*/g, "")
.replace(/PR:.*/g, "")
.replace(/ClaimedAt:.*/g, "");
await github.rest.issues.update({
owner,
repo,
issue_number,
body
});
try {
await github.rest.issues.removeLabel({
owner,
repo,
issue_number,
name: 'claimed'
});
} catch (e) {}
}
} else {
newStatus = "open";
}
parts[5] = newStatus;
} catch (e) {
console.log("Error processing PR:", prUrl);
}
updatedRows.push(parts.join(','));
}
const newCsv = [header, ...updatedRows].join('\n');
fs.writeFileSync('tasks.csv', newCsv);
- name: Show CSV
run: cat tasks.csv
- name: Upload CSV artifact
uses: actions/upload-artifact@v4
with:
name: tasks-csv-status
path: tasks.csv
- name: Done
run: echo "Read-only mode, CSV uploaded as artifact"