-
-
Notifications
You must be signed in to change notification settings - Fork 261
61 lines (51 loc) · 1.69 KB
/
repo-milestone.yaml
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
59
60
61
name: Repo / Auto-apply milestone
on:
pull_request_target:
types:
- opened
- reopened
jobs:
milestone:
name: Apply milestone
runs-on: ubuntu-24.04
if: ${{ contains(github.repository_owner, 'jellyfin') }}
steps:
- uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
github-token: ${{ secrets.JF_BOT_TOKEN }}
script: |
const owner = context.repo.owner;
const repo = context.repo.repo;
const pr_id = context.issue.number;
let response = await github.rest.issues.get({
owner,
repo,
issue_number: pr_id,
});
const pr = response.data;
if (pr.milestone !== null) {
return;
}
response = await github.rest.issues.listMilestones({
owner,
repo,
state: 'open',
});
const milestones = response.data;
// Find first open milestone
const milestone = milestones.reduce(
(prev, current) => prev?.number < current.number ? prev : current,
null,
);
if (milestone === null) {
console.warn('No suitable milestone found, aborting.');
return;
}
console.log(`Found milestone to apply: ${milestone.title}`);
await github.rest.issues.update({
owner,
repo,
issue_number: pr_id,
milestone: milestone.number,
});
console.log(`Successfully applied milestone ${milestone.title} to PR #${pr_id}`);