-
Notifications
You must be signed in to change notification settings - Fork 417
57 lines (53 loc) · 1.77 KB
/
set-target-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
name: Add milestone to pull requests
on:
# Only run when a PR is closed
pull_request:
types:
- closed
jobs:
add_milestone_to_pr:
# Only run if the PR was closed due to a merge
if: github.event.pull_request.merged == true
name: Add milestone to merged pull requests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
# Include all history and tags
with:
fetch-depth: 0
- uses: actions/setup-python@v5
name: Install Python
with:
python-version: '3.8'
- name: Get target milestone
id: milestones
run: |
pip install -U pip
pip install packaging
scripts/get-target-milestone.py
- name: Update Pull Request
if: steps.milestones.outputs.milestone != null
uses: actions/[email protected]
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const title = "${{ steps.milestones.outputs.milestone }}";
const milestones = await github.rest.issues.listMilestones({
owner: context.repo.owner,
repo: context.repo.repo,
state: "open",
});
let milestone = milestones.data.find( (m) => m.title == title );
if (milestone === undefined) {
milestone = await github.rest.issues.createMilestone({
owner: context.repo.owner,
repo: context.repo.repo,
title: title,
});
}
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ github.event.pull_request.number }},
milestone: milestone.number,
});