-
Notifications
You must be signed in to change notification settings - Fork 157
81 lines (71 loc) · 2.88 KB
/
Copy pathissue-pending-maintainer.yml
File metadata and controls
81 lines (71 loc) · 2.88 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
name: Issue pending-maintainer flip
on:
schedule:
- cron: '0 * * * *' # hourly safety net
issue_comment:
types: [created]
workflow_dispatch:
jobs:
check-pending:
if: >-
github.event_name == 'workflow_dispatch'
|| github.event_name == 'schedule'
|| (github.event_name == 'issue_comment' && !github.event.issue.pull_request)
runs-on: ubuntu-latest
permissions:
issues: write
steps:
- uses: actions/github-script@v7
with:
script: |
const MAINTAINER = 'pending-maintainer';
const CONTRIBUTOR = 'pending-contributor';
let issueNumbers = [];
if (context.eventName === 'workflow_dispatch' || context.eventName === 'schedule') {
const issues = await github.rest.issues.listForRepo({
...context.repo,
state: 'open',
per_page: 100
});
issueNumbers = issues.data
.filter(i => !i.pull_request)
.map(i => i.number);
} else if (context.eventName === 'issue_comment') {
issueNumbers = [context.payload.issue.number];
}
for (const issueNumber of issueNumbers) {
const { data: issue } = await github.rest.issues.get({
...context.repo,
issue_number: issueNumber
});
const labels = issue.labels.map(l => l.name);
// Skip if closing-soon or wontfix/not-planned
if (labels.includes('closing-soon')) continue;
if (labels.includes('wontfix') || labels.includes('not-planned')) continue;
// Check last human comment is from issue author
const { data: allComments } = await github.rest.issues.listComments({
...context.repo,
issue_number: issueNumber,
per_page: 100
});
const humanComments = allComments.filter(c => c.user.type !== 'Bot');
if (humanComments.length === 0) continue;
const lastCommenter = humanComments[humanComments.length - 1].user.login;
if (lastCommenter !== issue.user.login) continue;
// Flip: +pending-maintainer, -pending-contributor
if (!labels.includes(MAINTAINER)) {
await github.rest.issues.addLabels({
...context.repo,
issue_number: issueNumber,
labels: [MAINTAINER]
});
}
if (labels.includes(CONTRIBUTOR)) {
await github.rest.issues.removeLabel({
...context.repo,
issue_number: issueNumber,
name: CONTRIBUTOR
}).catch(() => {});
}
console.log(`#${issueNumber} — author replied, set ${MAINTAINER}`);
}