Skip to content

Commit 4e5f601

Browse files
feat(label-pr-review-state): tag PRs with conflicts (#269)
Co-authored-by: Elliott de Launay <edelauna@gmail.com>
1 parent 7fa008c commit 4e5f601

1 file changed

Lines changed: 17 additions & 1 deletion

File tree

.github/workflows/label-pr-review-state.yml

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
with:
2727
script: |
2828
const { owner, repo } = context.repo;
29-
const stateLabels = ['awaiting-author', 'awaiting-review'];
29+
const stateLabels = ['awaiting-author', 'awaiting-review', 'has-conflicts'];
3030
3131
// When triggered by a single PR event, only reconcile that PR.
3232
// The hourly schedule and workflow_dispatch reconcile all open PRs.
@@ -125,6 +125,22 @@ jobs:
125125
continue;
126126
}
127127
128+
// `mergeable`/`mergeable_state` are only returned by the single-PR GET
129+
// endpoint, and are computed asynchronously by GitHub — a PR fetched via
130+
// pulls.list (schedule/workflow_dispatch runs) never has them, and even a
131+
// single-PR fetch can return `null`/"unknown" if the merge check hasn't
132+
// finished yet. Re-fetch the single PR to get a fresh value, and treat
133+
// "unknown" as not-yet-computed rather than as conflicting.
134+
const prDetail = prNumber
135+
? pr
136+
: (await github.rest.pulls.get({ owner, repo, pull_number: pr.number })).data;
137+
138+
if (prDetail.mergeable === false && prDetail.mergeable_state === 'dirty') {
139+
core.info(`PR #${pr.number}: has merge conflicts — labeling has-conflicts`);
140+
await reconcileLabels(pr, 'has-conflicts');
141+
continue;
142+
}
143+
128144
// Check CI status for required checks on the PR's head commit only.
129145
// Scoping to required checks avoids advisory checks (e.g. codecov/patch)
130146
// incorrectly blocking label assignment on otherwise-ready PRs.

0 commit comments

Comments
 (0)