@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 03:37 UTC

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