Repository navigation
Expand file tree
/
Copy pathexternal-plugin-rereview-command.yml
More file actions
322 lines (283 loc) · 12.9 KB
/
Copy pathexternal-plugin-rereview-command.yml
File metadata and controls
322 lines (283 loc) · 12.9 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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
name: External Plugin Re-review Command
on:
issue_comment:
types: [created]
concurrency:
group: external-plugin-rereview-${{ github.event.issue.number }}
cancel-in-progress: false
permissions:
contents: write
issues: write
pull-requests: write
jobs:
rereview-command:
runs-on: ubuntu-latest
if: >-
!github.event.issue.pull_request &&
contains(github.event.comment.body, '/re-review-')
steps:
- name: Checkout main branch
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4.3.1
with:
ref: main
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: 22
cache: npm
- name: Parse re-review command
id: parse
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0
with:
script: |
const path = require('path');
const { pathToFileURL } = require('url');
const rereview = await import(pathToFileURL(path.join(process.env.GITHUB_WORKSPACE, 'eng', 'external-plugin-rereview.mjs')).href);
const validation = await import(pathToFileURL(path.join(process.env.GITHUB_WORKSPACE, 'eng', 'external-plugin-validation.mjs')).href);
const command = rereview.parseRereviewCommand(context.payload.comment.body);
core.setOutput('should-run', 'false');
if (!command) {
core.info('No supported re-review command was found.');
return;
}
const permission = await github.rest.repos.getCollaboratorPermissionLevel({
owner: context.repo.owner,
repo: context.repo.repo,
username: context.payload.comment.user.login
});
const hasWriteAccess = ['admin', 'write', 'maintain'].includes(permission.data.permission);
if (!hasWriteAccess) {
core.info(`Ignoring ${command} because ${context.payload.comment.user.login} does not have write access.`);
return;
}
const labelNames = new Set((context.payload.issue.labels || []).map((label) => label.name));
if (!labelNames.has('external-plugin') || !labelNames.has('approved')) {
core.info('Ignoring command because the issue is not an approved external plugin submission.');
return;
}
const inRereviewQueue =
labelNames.has('re-review-due') ||
labelNames.has('re-review-follow-up');
if (!inRereviewQueue) {
core.info(`Ignoring ${command} because the issue is not currently in the six-month re-review queue.`);
return;
}
const reactionByCommand = {
keep: '+1',
'needs-changes': 'eyes',
remove: '-1'
};
await github.rest.reactions.createForIssueComment({
owner: context.repo.owner,
repo: context.repo.repo,
comment_id: context.payload.comment.id,
content: reactionByCommand[command] ?? 'eyes'
});
const { plugins, errors } = validation.readExternalPlugins({ policy: 'marketplace' });
if (errors.length > 0) {
core.setFailed(errors.join('\n'));
return;
}
const currentIssue = await github.rest.issues.get({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number
});
const match = rereview.matchExternalPluginForIssue(currentIssue.data, plugins);
const plugin = match.plugin;
const fallbackName = match.submission.pluginName ?? `issue-${context.issue.number}`;
core.setOutput('should-run', 'true');
core.setOutput('command', command);
core.setOutput('has-plugin', plugin ? 'true' : 'false');
core.setOutput('plugin-name', plugin?.name ?? fallbackName);
core.setOutput('plugin-slug', rereview.slugifyPluginName(plugin?.name ?? fallbackName));
core.setOutput('source-repo', plugin?.source?.repo ?? match.submission.sourceRepo ?? '');
- name: Renew six-month review window
if: steps.parse.outputs.should-run == 'true' && steps.parse.outputs.command == 'keep'
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0
env:
PLUGIN_NAME: ${{ steps.parse.outputs.plugin-name }}
HAS_PLUGIN: ${{ steps.parse.outputs.has-plugin }}
with:
script: |
const pluginName = process.env.PLUGIN_NAME;
const hasPlugin = process.env.HAS_PLUGIN === 'true';
async function removeLabel(name) {
try {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
name
});
} catch (error) {
if (error.status !== 404) {
throw error;
}
}
}
if (!hasPlugin) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `Could not find a current \`plugins/external.json\` entry for **${pluginName}**, so the six-month re-review window was not reset. Review the listing manually before retrying.`
});
return;
}
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
state: 'open'
});
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
state: 'closed'
});
await removeLabel('re-review-due');
await removeLabel('re-review-follow-up');
await removeLabel('removed');
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `Renewed **${pluginName}** for another six months by reopening and reclosing this approved submission issue.`
});
- name: Mark follow-up needed
if: steps.parse.outputs.should-run == 'true' && steps.parse.outputs.command == 'needs-changes'
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0
env:
PLUGIN_NAME: ${{ steps.parse.outputs.plugin-name }}
with:
script: |
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: ['re-review-due', 're-review-follow-up']
});
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: `Marked **${process.env.PLUGIN_NAME}** as needing follow-up. The plugin will stay in the six-month re-review queue until a maintainer comments \`/re-review-keep\` or \`/re-review-remove\`.`
});
- name: Install dependencies
if: steps.parse.outputs.should-run == 'true' && steps.parse.outputs.command == 'remove' && steps.parse.outputs.has-plugin == 'true'
run: npm ci
- name: Remove plugin and create PR
id: remove_pr
if: steps.parse.outputs.should-run == 'true' && steps.parse.outputs.command == 'remove' && steps.parse.outputs.has-plugin == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
plugin_name='${{ steps.parse.outputs.plugin-name }}'
plugin_slug='${{ steps.parse.outputs.plugin-slug }}'
source_repo='${{ steps.parse.outputs.source-repo }}'
issue_number='${{ github.event.issue.number }}'
branch="automation/external-plugin-rereview-remove-${issue_number}-${plugin_slug}"
node ./eng/external-plugin-rereview.mjs remove --plugin-name "$plugin_name" --source-repo "$source_repo" --file ./plugins/external.json
npm run build
bash eng/fix-line-endings.sh
if git diff --quiet; then
echo "changed=false" >> "$GITHUB_OUTPUT"
exit 0
fi
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git checkout -B "$branch"
git add -A
git commit -m "Remove external plugin ${plugin_name} after six-month re-review"
git push --force-with-lease origin "$branch"
pr_url=$(gh pr list --head "$branch" --base main --json url --jq '.[0].url')
if [ -z "$pr_url" ]; then
pr_body=$(printf '%s\n' \
'## Summary' \
'' \
"- remove \`${plugin_name}\` from \`plugins/external.json\`" \
'- regenerate marketplace outputs after the six-month re-review decision' \
"- closes #${issue_number} review follow-up for this listing")
pr_url=$(gh pr create \
--base main \
--head "$branch" \
--title "[external-plugin] Remove ${plugin_name} after re-review" \
--body "$pr_body")
fi
echo "changed=true" >> "$GITHUB_OUTPUT"
echo "pr-url=$pr_url" >> "$GITHUB_OUTPUT"
- name: Finalize removal
if: steps.parse.outputs.should-run == 'true' && steps.parse.outputs.command == 'remove'
uses: actions/github-script@f28e40c7f34bde8b3046d885e986cb6290c5673b # v7.1.0
env:
CHANGED: ${{ steps.remove_pr.outputs.changed }}
PR_URL: ${{ steps.remove_pr.outputs.pr-url }}
PLUGIN_NAME: ${{ steps.parse.outputs.plugin-name }}
HAS_PLUGIN: ${{ steps.parse.outputs.has-plugin }}
with:
script: |
async function ensureLabel(name, color, description) {
try {
await github.rest.issues.createLabel({
owner: context.repo.owner,
repo: context.repo.repo,
name,
color,
description
});
} catch (error) {
if (error.status !== 422) {
throw error;
}
}
}
async function removeLabel(name) {
try {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
name
});
} catch (error) {
if (error.status !== 404) {
throw error;
}
}
}
const changed = process.env.CHANGED === 'true';
const prUrl = process.env.PR_URL;
const pluginName = process.env.PLUGIN_NAME;
const hasPlugin = process.env.HAS_PLUGIN === 'true';
let body;
if (!hasPlugin || !changed) {
await ensureLabel('removed', 'B60205', 'External plugin was removed from the marketplace after re-review');
await removeLabel('approved');
await removeLabel('re-review-due');
await removeLabel('re-review-follow-up');
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: ['removed']
});
body = `Marked **${pluginName}** as removed. No new PR was needed because the listing is already absent from \`plugins/external.json\`.`;
} else {
await ensureLabel('re-review-follow-up', 'D4C5F9', 'Six-month re-review needs maintainer follow-up before a final decision');
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: ['re-review-due', 're-review-follow-up']
});
body = `Opened the removal PR for **${pluginName}**: ${prUrl}. The issue remains approved and due for re-review until that removal lands in \`main\`.`;
}
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body
});