Skip to content

Commit 6123f5d

Browse files
authored
repo: update label check so it doesn't need help (#2995)
1 parent c0dc9fd commit 6123f5d

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

.github/workflows/pr_enforce_labels.yml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,17 @@ jobs:
1616
uses: actions/github-script@v8
1717
with:
1818
script: |
19-
const labels = context.payload.pull_request.labels.map(label => label.name);
19+
// Always fetch the latest labels from the GitHub API to avoid stale context
20+
const prNumber = context.payload.pull_request.number;
21+
const { data: pr } = await github.rest.pulls.get({
22+
owner: context.repo.owner,
23+
repo: context.repo.repo,
24+
pull_number: prNumber,
25+
});
26+
const latestLabels = pr.labels.map(label => label.name);
2027
const requiredLabels = ['bugfix', 'enhancement', 'automation', 'dependencies', 'repo', 'release'];
21-
const hasRequiredLabel = labels.some(label => requiredLabels.includes(label));
22-
console.log(labels);
28+
const hasRequiredLabel = latestLabels.some(label => requiredLabels.includes(label));
29+
console.log('Latest labels:', latestLabels);
2330
if (!hasRequiredLabel) {
2431
core.setFailed(`PR must have at least one of the following labels before it can be merged: ${requiredLabels.join(', ')}.`);
2532
}

0 commit comments

Comments
 (0)