-
Notifications
You must be signed in to change notification settings - Fork 415
54 lines (50 loc) · 1.63 KB
/
assign-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
# If a PR doesn't have a milestone assigned when it's merged, assign it the
# one that's scheduled next.
name: Assign Latest Milestone
on:
pull_request_target:
types: [closed]
branches: [main]
permissions:
pull-requests: write
issues: write
jobs:
sync:
name: Assign Latest Milestone
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v7
name: Run script
with:
script: |
if (!context.payload.pull_request.merged) {
console.log('PR was not merged, skipping.');
return;
}
if (!!context.payload.pull_request.milestone) {
console.log('PR has existing milestone, skipping.');
return;
}
if (context.payload.pull_request.user.type === 'Bot') {
console.log('Ignoring Bot PR');
return;
}
milestones = await github.rest.issues.listMilestones({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open',
sort: 'due_on',
direction: 'asc'
})
if (milestones.data.length === 0) {
console.log('There are no milestones, skipping.');
return;
}
console.log(`Adding to milestone: ${milestones.data[0].number}`);
result = await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.number,
milestone: milestones.data[0].number
});
console.log(result);