fix: restrict unapproved pull requests to bug fixes

This commit is contained in:
Ogulcan Celik
2026-07-26 15:57:59 +03:00
parent e1a32e5865
commit 2debcec74c
4 changed files with 23 additions and 8 deletions
+17 -2
View File
@@ -2,7 +2,7 @@ name: PR Gate
on:
pull_request_target:
types: [opened, reopened, synchronize]
types: [opened, edited, reopened, synchronize]
jobs:
check-contributor:
@@ -48,6 +48,13 @@ jobs:
const prAuthor = pr.user.login;
const changedLines = pr.additions + pr.deletions;
const eventPullRequestState = context.payload.pull_request.state;
if (action === 'edited' &&
(eventPullRequestState !== 'open' || pr.state !== 'open')) {
core.info(`Ignoring edits to closed PR #${pullNumber}`);
return;
}
async function getPermission(username) {
try {
const { data } = await github.rest.repos.getCollaboratorPermissionLevel({
@@ -176,7 +183,7 @@ jobs:
const message = [
`Hi @${prAuthor}, thanks for your interest in contributing!`,
'',
`Herdr automatically admits unapproved pull requests when the patch changes no more than ${MAX_UNAPPROVED_CHANGED_FILES} files and ${MAX_UNAPPROVED_CHANGED_LINES.toLocaleString('en-US')} total added or deleted lines.`,
`Herdr automatically admits focused bug fixes from unapproved contributors when the title uses \`fix: ...\` or \`fix(scope): ...\` and the patch changes no more than ${MAX_UNAPPROVED_CHANGED_FILES} files and ${MAX_UNAPPROVED_CHANGED_LINES.toLocaleString('en-US')} total added or deleted lines.`,
'',
reason,
'',
@@ -238,6 +245,14 @@ jobs:
return;
}
const hasFixTitle = /^fix(?:\([^)]+\))?:\s+\S/.test(pr.title);
if (!hasFixTitle) {
await closePullRequest(
'Unapproved contributors may submit only focused bug fixes. If this pull request fixes a bug, rename it to use a conventional `fix: ...` or `fix(scope): ...` title, then tag a maintainer to review and reopen it.',
);
return;
}
const exceedsBudget = pr.changed_files > MAX_UNAPPROVED_CHANGED_FILES ||
changedLines > MAX_UNAPPROVED_CHANGED_LINES;
if (exceedsBudget) {