fix: scope labeler trigger to reduce rate limiting and fix bugfix typo (#5020)

This commit is contained in:
James Rich 2026-04-09 12:25:51 -05:00 committed by GitHub
parent 750c4ea928
commit 2ce110dffe
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 49 additions and 40 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

@ -18,7 +18,7 @@ jobs:
script: |
// Extract labels from the payload directly to avoid extra API calls
const latestLabels = context.payload.pull_request.labels.map(label => label.name);
const requiredLabels = ['bugpost', 'enhancement', 'automation', 'dependencies', 'repo', 'release', 'refactor'];
const requiredLabels = ['bugfix', 'enhancement', 'automation', 'dependencies', 'repo', 'release', 'refactor'];
console.log('Labels from payload:', latestLabels);
const hasRequiredLabel = latestLabels.some(label => requiredLabels.includes(label));
if (!hasRequiredLabel) {

View file

@ -1,7 +1,8 @@
name: "Pull Request Labeler"
on:
- pull_request_target
# Do not execute arbitary code on this workflow.
pull_request_target:
types: [opened, synchronize]
# Do not execute arbitrary code on this workflow.
# See warnings at https://docs.github.com/en/actions/reference/workflows-and-actions/events-that-trigger-workflows#pull_request_target
jobs:
@ -11,5 +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:
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.');
}