Repository navigation
110 lines (101 loc) · 4.65 KB
/
Copy pathissue-vouch.yml
File metadata and controls
110 lines (101 loc) · 4.65 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
name: Issue Vouch
on:
issues:
types: [opened, reopened]
push:
branches:
- main
paths:
- .github/VOUCHED.td
- .github/workflows/issue-vouch.yml
workflow_dispatch:
permissions:
contents: read
issues: write
concurrency:
group: issue-vouch-${{ github.event.issue.number || 'all' }}
cancel-in-progress: true
jobs:
label:
name: Label issues by author trust
runs-on: ubuntu-24.04
steps:
- uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
with:
script: |
const { owner, repo } = context.repo;
// Only listed authors get a label; open issues number in the thousands,
// so unvouched is the default and stays unlabelled.
const labelByStatus = { vouched: "vouch:trusted", denounced: "vouch:denounced" };
const managedLabelNames = new Set(["vouch:trusted", "vouch:unvouched", "vouch:denounced"]);
const { data: file } = await github.rest.repos.getContent({
owner,
repo,
path: ".github/VOUCHED.td",
ref: context.payload.repository.default_branch,
});
const statusByUser = new Map();
const listedBothWays = new Set();
for (const raw of Buffer.from(file.content, "base64").toString("utf8").split("\n")) {
const match = /^(-?)github:(\S+)/.exec(raw.trim());
if (!match) continue;
const login = match[2].toLowerCase();
const status = match[1] ? "denounced" : "vouched";
if (statusByUser.has(login) && statusByUser.get(login) !== status) listedBothWays.add(login);
statusByUser.set(login, status);
}
const issues =
context.eventName === "issues"
? [context.payload.issue]
: (
await github.paginate(github.rest.issues.listForRepo, {
owner,
repo,
state: "open",
per_page: 100,
})
).filter((issue) => !issue.pull_request);
for (const issue of issues) {
const status = statusByUser.get(issue.user.login.toLowerCase());
const next = labelByStatus[status];
const current = issue.labels.map((label) => label.name).filter((name) => managedLabelNames.has(name));
for (const name of current) {
if (name === next) continue;
try {
await github.rest.issues.removeLabel({ owner, repo, issue_number: issue.number, name });
} catch (error) {
if (error.status !== 404) throw error;
}
}
if (next && !current.includes(next)) {
await github.rest.issues.addLabels({ owner, repo, issue_number: issue.number, labels: [next] });
core.info(`Issue #${issue.number} (${issue.user.login}): ${status} -> ${next}`);
}
// Only a newly opened issue is closed. One filed before its author was denounced
// may already have a fix on the way, so the sweep leaves those to maintainers.
// Someone else reopening it is a maintainer keeping it open.
const reopenedByOther =
context.payload.action === "reopened" &&
context.payload.sender.login.toLowerCase() !== issue.user.login.toLowerCase();
// The PR rules refuse a list that names a login both ways, so nothing closes for one here.
const trusted =
issue.user.type === "Bot" ||
["OWNER", "MEMBER", "COLLABORATOR"].includes(issue.author_association) ||
listedBothWays.has(issue.user.login.toLowerCase());
if (status === "denounced" && context.eventName === "issues" && !reopenedByOther && !trusted) {
await github.rest.issues.createComment({
owner,
repo,
issue_number: issue.number,
body: `Closing: ${issue.user.login} is banned from contributing here, so this issue will not be triaged. See [bans](https://github.com/${owner}/${repo}/blob/main/CONTRIBUTING.md#bans).`,
});
await github.rest.issues.update({
owner,
repo,
issue_number: issue.number,
state: "closed",
state_reason: "not_planned",
});
core.info(`Issue #${issue.number}: closed, ${issue.user.login} is denounced.`);
}
}