openclaw/scripts/github/labeler-label-cap.mjs
Peter Steinberger 862c1f7c65
fix(ci): labeler no longer fails when a PR already has 100 labels (#138841)
* fix(ci): labeler no longer fails when a PR already has 100 labels

PR #137637 taught the size-label step to tolerate GitHub's HTTP 422
"Issues cannot have more than 100 labels", but every other label-adding
step still threw it. On the 2026.9.1 closeout PR #137506 the maintainer
author-role step failed that way and turned the cosmetic Labeler check red.

Move the cap handling into one owner, scripts/github/labeler-label-cap.mjs,
and route all eight addLabels sites across the label, label-issues, and
backfill-pr-labels jobs through it: warn naming the skipped label, succeed,
rethrow anything else. Each job checks out the trusted base commit
(ref: github.sha, persist-credentials: false) like auto-response.yml so the
github-script steps can import the module; no PR code runs. Delete the size
step's pre-count guard so the 422 is the single canonical cap path.

Rename test/scripts/labeler-size-label.test.ts to labeler-label-cap.test.ts;
it executes the real step scripts with the real helper and adds maintainer
step cap coverage plus a workflow-wide invariant that no script calls
issues.addLabels directly.

* test(ci): cover labeler cap helper return value and keep knip aware of it

The knip full-tree unused-file scan flagged scripts/github/labeler-label-cap.mjs
because only the workflow loads it dynamically. Import it from its owner test,
like every other scripts/github module, with a case for the boolean result the
backfill job's label bookkeeping depends on.
2026-09-04 22:56:18 -07:00

16 lines
737 B
JavaScript

// One owner for GitHub's 100-labels-per-issue cap. Labeler steps are cosmetic: hitting the cap
// is a visible warning naming the skipped label, never a red check. Unrelated errors still throw.
export async function addLabelsWithinCap({ github, core, owner, repo, issueNumber, labels }) {
try {
await github.rest.issues.addLabels({ owner, repo, issue_number: issueNumber, labels });
return true;
} catch (error) {
if (error?.status !== 422 || !/cannot have more than 100 labels/i.test(error.message ?? "")) {
throw error;
}
core.warning(
`Skipping label ${labels.map((label) => JSON.stringify(label)).join(", ")} on #${issueNumber}: GitHub caps issues at 100 labels.`,
);
return false;
}
}