From 9a3daa9e26e3cba8ae3b5403e2b3c85d8b01d856 Mon Sep 17 00:00:00 2001 From: James Rich Date: Thu, 9 Apr 2026 12:21:23 -0500 Subject: [PATCH] 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. --- .github/labeler.yml | 35 ----------------- .github/workflows/pull-request-target.yml | 47 +++++++++++++++++++++-- 2 files changed, 44 insertions(+), 38 deletions(-) delete mode 100644 .github/labeler.yml diff --git a/.github/labeler.yml b/.github/labeler.yml deleted file mode 100644 index c3c2fa6cf..000000000 --- a/.github/labeler.yml +++ /dev/null @@ -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).)*$'] - diff --git a/.github/workflows/pull-request-target.yml b/.github/workflows/pull-request-target.yml index 2dffd87d1..e03f9eb25 100644 --- a/.github/workflows/pull-request-target.yml +++ b/.github/workflows/pull-request-target.yml @@ -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.'); + }