Open History to see the last commit
1name: Issue Vouch
2
3on:
4 issues:
5 types: [opened, reopened]
6 push:
7 branches:
8 - main
9 paths:
10 - .github/VOUCHED.td
11 - .github/workflows/issue-vouch.yml
12 workflow_dispatch:
13
14permissions:
15 contents: read
16
17concurrency:
18 group: issue-vouch-${{ github.event.issue.number || 'all' }}
19 cancel-in-progress: true
20
21jobs:
22 label:
23 name: Label issues by author trust
24 runs-on: ubuntu-24.04
25 permissions:
26 contents: read
27 issues: write
28 steps:
29 - uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0
30 with:
31 script: |
32 const { owner, repo } = context.repo;
33 // Only listed authors get a label; open issues number in the thousands,
34 // so unvouched is the default and stays unlabelled.
35 const labelByStatus = { vouched: "vouch:trusted", denounced: "vouch:denounced" };
36 const managedLabelNames = new Set(["vouch:trusted", "vouch:unvouched", "vouch:denounced"]);
37
38 const { data: file } = await github.rest.repos.getContent({
39 owner,
40 repo,
41 path: ".github/VOUCHED.td",
42 ref: context.payload.repository.default_branch,
43 });
44 const statusByUser = new Map();
45 const listedBothWays = new Set();
46 for (const raw of Buffer.from(file.content, "base64").toString("utf8").split("\n")) {
47 const match = /^(-?)github:(\S+)/.exec(raw.trim());
48 if (!match) continue;
49 const login = match[2].toLowerCase();
50 const status = match[1] ? "denounced" : "vouched";
51 if (statusByUser.has(login) && statusByUser.get(login) !== status) listedBothWays.add(login);
52 statusByUser.set(login, status);
53 }
54
55 const issues =
56 context.eventName === "issues"
57 ? [context.payload.issue]
58 : (
59 await github.paginate(github.rest.issues.listForRepo, {
60 owner,
61 repo,
62 state: "open",
63 per_page: 100,
64 })
65 ).filter((issue) => !issue.pull_request);
66
67 for (const issue of issues) {
68 const status = statusByUser.get(issue.user.login.toLowerCase());
69 const next = labelByStatus[status];
70 const current = issue.labels.map((label) => label.name).filter((name) => managedLabelNames.has(name));
71
72 for (const name of current) {
73 if (name === next) continue;
74 try {
75 await github.rest.issues.removeLabel({ owner, repo, issue_number: issue.number, name });
76 } catch (error) {
77 if (error.status !== 404) throw error;
78 }
79 }
80 if (next && !current.includes(next)) {
81 await github.rest.issues.addLabels({ owner, repo, issue_number: issue.number, labels: [next] });
82 core.info(`Issue #${issue.number} (${issue.user.login}): ${status} -> ${next}`);
83 }
84
85 // Only a newly opened issue is closed. One filed before its author was denounced
86 // may already have a fix on the way, so the sweep leaves those to maintainers.
87 // Someone else reopening it is a maintainer keeping it open.
88 const reopenedByOther =
89 context.payload.action === "reopened" &&
90 context.payload.sender.login.toLowerCase() !== issue.user.login.toLowerCase();
91 // The PR rules refuse a list that names a login both ways, so nothing closes for one here.
92 const trusted =
93 issue.user.type === "Bot" ||
94 ["OWNER", "MEMBER", "COLLABORATOR"].includes(issue.author_association) ||
95 listedBothWays.has(issue.user.login.toLowerCase());
96 if (status === "denounced" && context.eventName === "issues" && !reopenedByOther && !trusted) {
97 await github.rest.issues.createComment({
98 owner,
99 repo,
100 issue_number: issue.number,
101 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).`,
102 });
103 await github.rest.issues.update({
104 owner,
105 repo,
106 issue_number: issue.number,
107 state: "closed",
108 state_reason: "not_planned",
109 });
110 core.info(`Issue #${issue.number}: closed, ${issue.user.login} is denounced.`);
111 }
112 }