Skip to content

Commit ee8f3ce

Browse files
committed
fix(ci): safely sync issue metadata to PR without overwriting labels
- Replaced `setLabels()` with `addLabels()` to prevent race conditions where concurrent label additions could be lost. - Labels from linked issues are now added without removing existing PR labels. - Milestones from linked issues continue to be synced. - Adds a comment to the PR summarizing synchronized metadata.
1 parent d639a87 commit ee8f3ce

File tree

1 file changed

+7
-15
lines changed

1 file changed

+7
-15
lines changed

.github/workflows/autolabel-pr-issue.yml

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
core.setOutput('issues', JSON.stringify(Array.from(issueNumbers)));
4848
core.setOutput('pr', prNumber.toString());
4949
50-
# Step 3: Sync issue metadata to PR
50+
# Step 3: Sync issue metadata to PR safely
5151
- name: Sync Issue Metadata to PR
5252
if: steps.extract-issues.outputs.issues != '' && steps.extract-issues.outputs.issues != '[]'
5353
uses: actions/github-script@v7
@@ -80,24 +80,16 @@ jobs:
8080
8181
console.log(`Syncing metadata from Issue #${issueNumber} to PR #${prNumber}`);
8282
83-
// --- Sync Labels ---
83+
// --- Sync Labels safely using addLabels ---
8484
const issueLabels = issue.labels.map(l => l.name);
85-
const { data: pr } = await github.rest.pulls.get({
86-
owner: context.repo.owner,
87-
repo: context.repo.repo,
88-
pull_number: prNumber
89-
});
90-
const currentPRLabels = pr.labels.map(l => l.name);
91-
const combinedLabels = Array.from(new Set([...currentPRLabels, ...issueLabels]));
92-
93-
if (combinedLabels.length > 0) {
94-
await github.rest.issues.setLabels({
85+
if (issueLabels.length > 0) {
86+
await github.rest.issues.addLabels({
9587
owner: context.repo.owner,
9688
repo: context.repo.repo,
9789
issue_number: prNumber,
98-
labels: combinedLabels
90+
labels: issueLabels
9991
});
100-
console.log(`Labels applied: ${combinedLabels.join(', ')}`);
92+
console.log(`Labels added from issue: ${issueLabels.join(', ')}`);
10193
}
10294
10395
// --- Sync Milestone ---
@@ -111,7 +103,7 @@ jobs:
111103
console.log(`Milestone synced: ${issue.milestone.title}`);
112104
}
113105
114-
// --- Optionally add comment on PR ---
106+
// --- Add comment on PR ---
115107
await github.rest.issues.createComment({
116108
owner: context.repo.owner,
117109
repo: context.repo.repo,

0 commit comments

Comments
 (0)