forked from Pedro-Pathing/Quickstart
-
Notifications
You must be signed in to change notification settings - Fork 1
84 lines (71 loc) · 2.58 KB
/
reopen-once.yml
File metadata and controls
84 lines (71 loc) · 2.58 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
name: Reopen mistake PR once
on:
issue_comment:
types: [created]
permissions:
issues: write
pull-requests: write
jobs:
reopen:
runs-on: ubuntu-latest
steps:
- name: Handle /not-a-mistake
uses: actions/github-script@v7
with:
script: |
const comment = context.payload.comment;
const issue = context.payload.issue;
if (!issue.pull_request) return;
if (comment.body.trim() !== '/not-a-mistake') return;
const pr = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: issue.number
});
const labels = pr.data.labels.map(l => l.name);
// Only PR author may use this
if (comment.user.login !== pr.data.user.login) {
return;
}
// Must be closed and labeled mistake-pr
if (pr.data.state !== 'closed') return;
if (!labels.includes('mistake-pr')) return;
// Auto-reopen already disabled
if (labels.includes('reopen-used') || labels.includes('reopen-locked')) {
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body:
"Automatic reopening is disabled for this PR.\n\n" +
"A maintainer may still reopen it manually if needed."
});
return;
}
// Mark reopen as used FIRST (prevents race)
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
labels: ['reopen-used']
});
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
name: 'mistake-pr'
});
await github.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: issue.number,
state: 'open'
});
await github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue.number,
body:
"PR reopened.\n\n" +
"If this PR is closed again, automatic reopening will be disabled."
});