mirror of
https://github.com/pbakaus/impeccable.git
synced 2026-09-11 21:57:14 +03:00
Normalize sheriff exemption labels
AI-assisted: implemented and validated by Codex under maintainer direction.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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', () => {
|
||||
|
||||
Reference in New Issue
Block a user