-
Notifications
You must be signed in to change notification settings - Fork 171
58 lines (48 loc) · 1.86 KB
/
milestone.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
name: Check PR milestone
on:
pull_request_target:
types: [milestoned, demilestoned, opened, reopened]
branches:
- main
jobs:
check_milestone:
if: ${{ github.event.issue.pull_request || github.event.pull_request }}
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: "Check for milestone on PR"
uses: actions/github-script@v7
with:
script: |
let milestone = context.payload.pull_request.milestone;
if(context.payload.action === 'opened' || context.payload.action === 'reopened') {
if(milestone !== null) {
core.notice(`Milestone is ${milestone.title}`);
} else {
const milestones = await github.rest.issues.listMilestones({
owner: context.repo.owner,
repo: context.repo.repo,
state: "open"
});
for (const default_milestone of milestones.data) {
if (default_milestone.title === "next") {
core.notice(`No milestone set, setting default milestone: ${default_milestone.title}`);
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
milestone: default_milestone.number
});
return;
}
}
core.warning("Could not find default milestone named 'next'");
}
}
else {
if(milestone !== null) {
core.notice(`Milestone is ${milestone.title}`);
} else {
core.setFailed("No milestone: Please add a version milestone");
}
}