Normalize sheriff exemption labels

AI-assisted: implemented and validated by Codex under maintainer direction.
This commit is contained in:
Paul Bakaus
2026-08-31 16:43:21 -07:00
parent 4cc9578a3d
commit 405998ad51
2 changed files with 16 additions and 3 deletions
+9 -2
View File
@@ -50,6 +50,10 @@ const CONTRIBUTOR_POLICY_LABELS = new Set([
]);
const SHERIFF_WAIT_COMMAND = /^\/sheriff\s+wait\s*$/i;
function normalizeLabelName(label) {
return String(label || '').trim().toLowerCase();
}
const PR_QUERY = `
query($owner: String!, $name: String!, $after: String) {
repository(owner: $owner, name: $name) {
@@ -145,7 +149,9 @@ export function evaluatePullRequest(pr, options = {}) {
const closeDays = Number.isFinite(options.closeDays) ? options.closeDays : 14;
const maintainers = loginSet(options.maintainers || DEFAULT_MAINTAINERS);
const regularContributors = loginSet(options.regularContributors || DEFAULT_REGULAR_CONTRIBUTORS);
const exemptLabels = new Set(options.exemptLabels || DEFAULT_EXEMPT_LABELS);
const exemptLabels = new Set(
(options.exemptLabels || DEFAULT_EXEMPT_LABELS).map(normalizeLabelName),
);
const trustedMarkerAuthors = loginSet(options.trustedMarkerAuthors || DEFAULT_TRUSTED_MARKER_AUTHORS);
const autoCloseRegulars = options.autoCloseRegulars === true;
@@ -266,7 +272,8 @@ export function evaluatePullRequest(pr, options = {}) {
const warningAlreadyPosted = Boolean(warningPostedAt
&& (!contributorActionBlockerAt || !isAfter(contributorActionBlockerAt, warningPostedAt)));
const closeAlreadyPosted = hasMarker(pr.comments, CLOSE_MARKER, trustedMarkerAuthors);
const exemptFromClose = [...labels].some((label) => exemptLabels.has(label));
const exemptFromClose = [...labels]
.some((label) => exemptLabels.has(normalizeLabelName(label)));
const regularContributor = regularContributors.has(author);
const shouldWarn = staleEligible && !warningAlreadyPosted;
const shouldClose = contributorActionRequired
+7 -1
View File
@@ -691,13 +691,19 @@ describe('github sheriff', () => {
],
};
const closePlan = evaluatePullRequest(pr(source), { now: NOW, autoCloseRegulars: true });
const exemptPlan = evaluatePullRequest(pr({ ...source, labels: ['do not close'] }), {
const exemptPlan = evaluatePullRequest(pr({ ...source, labels: ['Do Not Close'] }), {
now: NOW,
autoCloseRegulars: true,
});
const customExemptPlan = evaluatePullRequest(pr({ ...source, labels: ['Keep Open'] }), {
now: NOW,
autoCloseRegulars: true,
exemptLabels: ['keep open'],
});
assert.equal(closePlan.shouldClose, true);
assert.equal(exemptPlan.shouldClose, false);
assert.equal(customExemptPlan.shouldClose, false);
});
it('keeps stale comments idempotent', () => {