-
Notifications
You must be signed in to change notification settings - Fork 4
53 lines (48 loc) · 1.87 KB
/
add-milestone-to-pull-requests.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
name: Add milestone to pull requests
on:
pull_request:
types: [closed]
jobs:
add_milestone:
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true && github.event.pull_request.milestone == null
steps:
- name: Checkout code
# Checks out the branch that the pull request is merged into
uses: actions/checkout@v3
with:
ref: ${{ github.event.pull_request.base.ref }}
- name: Get major version from gemspec
# Parse the gemspec and return the major version
id: version
run: |
echo "::set-output name=version::$(find . -name *.gemspec | ruby -ne 'puts Gem::Specification.load($_.chomp).version.to_s.split(".").first')"
- name: Get project milestones
id: milestones
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const milestones = await github.rest.issues.listMilestones({
owner: context.repo.owner,
repo: context.repo.repo,
state: 'open'
})
return milestones.data
- name: Update Pull Request
# Update the merged pull request with the milestone starts with the major version
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const milestones = ${{steps.milestones.outputs.result}}
const majorVersion = ${{steps.version.outputs.version}}
const milestone = milestones.find(m => m.title.startsWith(majorVersion))
if (milestone) {
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: ${{ github.event.pull_request.number }},
milestone: milestone.number
})
}