From 750c4ea928652b8f2dd9b2a2d01816ef059a9487 Mon Sep 17 00:00:00 2001 From: James Rich <2199651+jamesarich@users.noreply.github.com> Date: Thu, 9 Apr 2026 12:16:15 -0500 Subject: [PATCH] fix: use payload labels in pr_enforce_labels.yml to avoid rate limiting (#5018) --- .github/workflows/pr_enforce_labels.yml | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/.github/workflows/pr_enforce_labels.yml b/.github/workflows/pr_enforce_labels.yml index 05603796f..9911dd612 100644 --- a/.github/workflows/pr_enforce_labels.yml +++ b/.github/workflows/pr_enforce_labels.yml @@ -9,24 +9,18 @@ permissions: contents: read jobs: - check-label: + check-label: runs-on: ubuntu-24.04-arm steps: - name: Check for PR labels uses: actions/github-script@v8 with: script: | - // Always fetch the latest labels from the GitHub API to avoid stale context - const prNumber = context.payload.pull_request.number; - const { data: pr } = await github.rest.pulls.get({ - owner: context.repo.owner, - repo: context.repo.repo, - pull_number: prNumber, - }); - const latestLabels = pr.labels.map(label => label.name); - const requiredLabels = ['bugfix', 'enhancement', 'automation', 'dependencies', 'repo', 'release', 'refactor']; + // 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']; + console.log('Labels from payload:', latestLabels); const hasRequiredLabel = latestLabels.some(label => requiredLabels.includes(label)); - console.log('Latest labels:', latestLabels); if (!hasRequiredLabel) { core.setFailed(`PR must have at least one of the following labels before it can be merged: ${requiredLabels.join(', ')}.`); }