Skip to content

Commit e48c1cc

Browse files
R44VC0RPopencode
authored andcommitted
chore(workflows): label vouched users and restrict vouch managers (anomalyco#15075)
1 parent 5e5823e commit e48c1cc

File tree

3 files changed

+78
-36
lines changed

3 files changed

+78
-36
lines changed

.github/workflows/vouch-check-issue.yml

Lines changed: 39 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,17 @@ jobs:
4242
throw error;
4343
}
4444
45-
// Parse the .td file for denounced users
45+
// Parse the .td file for vouched and denounced users
46+
const vouched = new Set();
4647
const denounced = new Map();
4748
for (const line of content.split('\n')) {
4849
const trimmed = line.trim();
4950
if (!trimmed || trimmed.startsWith('#')) continue;
50-
if (!trimmed.startsWith('-')) continue;
5151
52-
const rest = trimmed.slice(1).trim();
52+
const isDenounced = trimmed.startsWith('-');
53+
const rest = isDenounced ? trimmed.slice(1).trim() : trimmed;
5354
if (!rest) continue;
55+
5456
const spaceIdx = rest.indexOf(' ');
5557
const handle = spaceIdx === -1 ? rest : rest.slice(0, spaceIdx);
5658
const reason = spaceIdx === -1 ? null : rest.slice(spaceIdx + 1).trim();
@@ -65,32 +67,50 @@ jobs:
6567
const username = colonIdx === -1 ? handle : handle.slice(colonIdx + 1);
6668
if (!username) continue;
6769
68-
denounced.set(username.toLowerCase(), reason);
70+
if (isDenounced) {
71+
denounced.set(username.toLowerCase(), reason);
72+
continue;
73+
}
74+
75+
vouched.add(username.toLowerCase());
6976
}
7077
7178
// Check if the author is denounced
7279
const reason = denounced.get(author.toLowerCase());
73-
if (reason === undefined) {
74-
core.info(`User ${author} is not denounced. Allowing issue.`);
80+
if (reason !== undefined) {
81+
// Author is denounced — close the issue
82+
const body = 'This issue has been automatically closed.';
83+
84+
await github.rest.issues.createComment({
85+
owner: context.repo.owner,
86+
repo: context.repo.repo,
87+
issue_number: issueNumber,
88+
body,
89+
});
90+
91+
await github.rest.issues.update({
92+
owner: context.repo.owner,
93+
repo: context.repo.repo,
94+
issue_number: issueNumber,
95+
state: 'closed',
96+
state_reason: 'not_planned',
97+
});
98+
99+
core.info(`Closed issue #${issueNumber} from denounced user ${author}`);
75100
return;
76101
}
77102
78-
// Author is denounced — close the issue
79-
const body = 'This issue has been automatically closed.';
80-
81-
await github.rest.issues.createComment({
82-
owner: context.repo.owner,
83-
repo: context.repo.repo,
84-
issue_number: issueNumber,
85-
body,
86-
});
103+
// Author is positively vouched — add label
104+
if (!vouched.has(author.toLowerCase())) {
105+
core.info(`User ${author} is not denounced or vouched. Allowing issue.`);
106+
return;
107+
}
87108
88-
await github.rest.issues.update({
109+
await github.rest.issues.addLabels({
89110
owner: context.repo.owner,
90111
repo: context.repo.repo,
91112
issue_number: issueNumber,
92-
state: 'closed',
93-
state_reason: 'not_planned',
113+
labels: ['Vouched'],
94114
});
95115
96-
core.info(`Closed issue #${issueNumber} from denounced user ${author}`);
116+
core.info(`Added vouched label to issue #${issueNumber} from ${author}`);

.github/workflows/vouch-check-pr.yml

Lines changed: 38 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ on:
66

77
permissions:
88
contents: read
9+
issues: write
910
pull-requests: write
1011

1112
jobs:
@@ -42,15 +43,17 @@ jobs:
4243
throw error;
4344
}
4445
45-
// Parse the .td file for denounced users
46+
// Parse the .td file for vouched and denounced users
47+
const vouched = new Set();
4648
const denounced = new Map();
4749
for (const line of content.split('\n')) {
4850
const trimmed = line.trim();
4951
if (!trimmed || trimmed.startsWith('#')) continue;
50-
if (!trimmed.startsWith('-')) continue;
5152
52-
const rest = trimmed.slice(1).trim();
53+
const isDenounced = trimmed.startsWith('-');
54+
const rest = isDenounced ? trimmed.slice(1).trim() : trimmed;
5355
if (!rest) continue;
56+
5457
const spaceIdx = rest.indexOf(' ');
5558
const handle = spaceIdx === -1 ? rest : rest.slice(0, spaceIdx);
5659
const reason = spaceIdx === -1 ? null : rest.slice(spaceIdx + 1).trim();
@@ -65,29 +68,47 @@ jobs:
6568
const username = colonIdx === -1 ? handle : handle.slice(colonIdx + 1);
6669
if (!username) continue;
6770
68-
denounced.set(username.toLowerCase(), reason);
71+
if (isDenounced) {
72+
denounced.set(username.toLowerCase(), reason);
73+
continue;
74+
}
75+
76+
vouched.add(username.toLowerCase());
6977
}
7078
7179
// Check if the author is denounced
7280
const reason = denounced.get(author.toLowerCase());
73-
if (reason === undefined) {
74-
core.info(`User ${author} is not denounced. Allowing PR.`);
81+
if (reason !== undefined) {
82+
// Author is denounced — close the PR
83+
await github.rest.issues.createComment({
84+
owner: context.repo.owner,
85+
repo: context.repo.repo,
86+
issue_number: prNumber,
87+
body: 'This pull request has been automatically closed.',
88+
});
89+
90+
await github.rest.pulls.update({
91+
owner: context.repo.owner,
92+
repo: context.repo.repo,
93+
pull_number: prNumber,
94+
state: 'closed',
95+
});
96+
97+
core.info(`Closed PR #${prNumber} from denounced user ${author}`);
7598
return;
7699
}
77100
78-
// Author is denounced — close the PR
79-
await github.rest.issues.createComment({
80-
owner: context.repo.owner,
81-
repo: context.repo.repo,
82-
issue_number: prNumber,
83-
body: 'This pull request has been automatically closed.',
84-
});
101+
// Author is positively vouched — add label
102+
if (!vouched.has(author.toLowerCase())) {
103+
core.info(`User ${author} is not denounced or vouched. Allowing PR.`);
104+
return;
105+
}
85106
86-
await github.rest.pulls.update({
107+
await github.rest.issues.addLabels({
87108
owner: context.repo.owner,
88109
repo: context.repo.repo,
89-
pull_number: prNumber,
90-
state: 'closed',
110+
issue_number: prNumber,
111+
labels: ['Vouched'],
91112
});
92113
93-
core.info(`Closed PR #${prNumber} from denounced user ${author}`);
114+
core.info(`Added vouched label to PR #${prNumber} from ${author}`);

.github/workflows/vouch-manage-by-issue.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@ jobs:
3333
with:
3434
issue-id: ${{ github.event.issue.number }}
3535
comment-id: ${{ github.event.comment.id }}
36+
roles: admin,maintain
3637
env:
3738
GITHUB_TOKEN: ${{ steps.committer.outputs.token }}

0 commit comments

Comments
 (0)