Skip to content

Commit 2f1fb8f

Browse files
rojiCopilot
andcommitted
Create milestone if missing in label-and-milestone workflow
When the label-and-milestone-issues workflow sets a milestone on closed issues, create the milestone via the REST API if it doesn't already exist, instead of failing with 'milestone not found'. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 41d1ffd commit 2f1fb8f

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

.github/workflows/label-and-milestone-issues.yml

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,16 @@ jobs:
115115
}
116116
}
117117
`, { owner, repo, title: targetMilestoneName });
118-
const milestoneNode = milestoneResult.repository.milestones.nodes
118+
let milestoneNode = milestoneResult.repository.milestones.nodes
119119
.find(m => m.title === targetMilestoneName);
120120
if (!milestoneNode) {
121-
throw new Error(`Milestone '${targetMilestoneName}' not found`);
121+
console.log(`Milestone '${targetMilestoneName}' not found, creating it`);
122+
const { data: created } = await github.rest.issues.createMilestone({
123+
owner,
124+
repo,
125+
title: targetMilestoneName
126+
});
127+
milestoneNode = { number: created.number, title: created.title };
122128
}
123129
124130
// Set the milestone on closing issues, applying a "min" strategy:

0 commit comments

Comments
 (0)