mirror of
https://github.com/VibedByKaKi/t3-code-android-nightly.git
synced 2026-12-05 11:59:03 +01:00
112 lines
4.7 KiB
YAML
112 lines
4.7 KiB
YAML
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
|
|
|
|
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
|
|
permissions:
|
|
contents: read
|
|
issues: write
|
|
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.`);
|
|
}
|
|
}
|