fix: replace actions/labeler with inline script to eliminate rate limiting

actions/labeler@v6 fetches the PR via API on every run, which silently
fails with 'Could not find pull request' when the installation rate
limit is exhausted. Replace it with an inline github-script that reads
the branch name directly from the event payload (zero API calls for
branch-name rules). The .github file-change check for the 'repo' label
is the only rule that needs an API call, and it's skipped when the
branch name already matches.

Also removes .github/labeler.yml which is no longer needed.
This commit is contained in:
James Rich 2026-04-09 12:21:23 -05:00
parent 93e711e0f2
commit 9a3daa9e26
2 changed files with 44 additions and 38 deletions

35
.github/labeler.yml vendored
View file

@ -1,35 +0,0 @@
# Auto Labeler rulse using https://github.com/actions/labeler
#
# 'fix' in title/branch -> bug
# 'feat' in title/branch -> enhancement
# 'repo' in title/branch OR changes to ~/.github/ -> repo
# 'bug_fallthrough' for everything else except auto
#
# - [ ] need to look at title. waiting on https://github.com/actions/labeler/pull/866
# Add 'enhancement' label to any PR where the head branch name contains `feat`
enhancement:
- head-branch: [feat, Feat, FEAT]
# Add 'repo' label to any PR where the head branch name contains `repo`
# or files in the .github dir
repo:
- any:
- head-branch: [repo, Repo, REPO, ci, CI]
- changed-files:
- any-glob-to-any-file: .github
# Add 'bug' label to any PR where the head branch name contains `fix` or `bug` as the prefix.
bugfix:
- head-branch: [^fix, ^bug, ^Fix, ^FIX, ^Bug, ^BUG]
# Add `refactor` label to any PR where the head branch name contains `refactor` or `Refactor` as the prefix.
refactor:
- head-branch: [^refactor, ^Refactor]
# our fallback - bug except repo, feat, or automated pipelines
# bug_fallthrough:
# - all:
# - head-branch: ['^((?!feat).)*$', '^((?!repo).)*$', '^((?!renovate).)*$', '^((?!scheduled).)*$']

View file

@ -12,7 +12,48 @@ jobs:
pull-requests: write
runs-on: ubuntu-24.04-arm
steps:
- id: label-the-PR
uses: actions/labeler@v6
- name: Auto-label PR
uses: actions/github-script@v8
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const branch = context.payload.pull_request.head.ref;
const labels = new Set();
// enhancement: branch contains feat
if (/feat/i.test(branch)) labels.add('enhancement');
// bugfix: branch starts with fix or bug
if (/^(fix|bug)/i.test(branch)) labels.add('bugfix');
// refactor: branch starts with refactor
if (/^refactor/i.test(branch)) labels.add('refactor');
// repo: branch contains repo or ci
if (/repo|ci/i.test(branch)) {
labels.add('repo');
} else {
// Also label 'repo' if .github files were changed (needs one API call)
try {
const files = await github.paginate(
github.rest.pulls.listFiles,
{ owner: context.repo.owner, repo: context.repo.repo, pull_number: context.payload.pull_request.number, per_page: 100 },
(res) => res.data.map(f => f.filename)
);
if (files.some(f => f.startsWith('.github/'))) labels.add('repo');
} catch (e) {
core.warning(`Could not list PR files (rate limited?): ${e.message}`);
}
}
if (labels.size > 0) {
const labelArray = [...labels];
core.info(`Applying labels: ${labelArray.join(', ')}`);
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
labels: labelArray,
});
} else {
core.info('No labels matched for this PR.');
}