forked from trinodb/trino
-
Notifications
You must be signed in to change notification settings - Fork 0
83 lines (76 loc) · 3.31 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
name: milestone
on:
push:
branches: [master]
defaults:
run:
shell: bash --noprofile --norc -euo pipefail {0}
jobs:
set-milestone:
if: github.repository_owner == 'trinodb'
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get milestone from pom.xml
run: |
.github/bin/retry ./mvnw -v
MILESTONE_NUMBER="$(./mvnw help:evaluate -Dexpression=project.version -q -DforceStdout | cut -d- -f1)"
echo "Setting PR milestone to ${MILESTONE_NUMBER}"
echo "MILESTONE_NUMBER=${MILESTONE_NUMBER}" >> $GITHUB_ENV
- name: Set milestone to PR
uses: actions/github-script@v6
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
// Get pull request number from commit sha
// 'listPullRequestsAssociatedWithCommit()' lists the merged pull request
// https://docs.github.com/en/rest/reference/repos#list-pull-requests-associated-with-a-commit
// and https://octokit.github.io/rest.js/v19#repos-list-pull-requests-associated-with-commit
const pr_response = await github.rest.repos.listPullRequestsAssociatedWithCommit({
owner: context.repo.owner,
repo: context.repo.repo,
commit_sha: context.sha
})
if (pr_response.data.length === 0) {
console.log('Pull request not found for commit', context.sha)
return
}
if (pr_response.data.length > 1) {
console.log(pr_response.data)
throw 'Expected 1 pull request but found: ' + pr_response.data.length
}
const pr_number = pr_response.data[0].number
console.log('Found pull request', pr_number, 'for commit', context.sha)
// Get milestone
const {
MILESTONE_NUMBER
} = process.env
console.log('Milestone number to set', MILESTONE_NUMBER)
// Find milestone with matching title
// See https://octokit.github.io/rest.js/v19#pagination
const milestones = await github.paginate(github.rest.issues.listMilestones, {
owner: context.repo.owner,
repo: context.repo.repo,
state: 'all'
})
let milestone = milestones.find(milestone => milestone.title === MILESTONE_NUMBER)
console.log('Found milestone with title', MILESTONE_NUMBER, milestone)
// Create new milestone if it doesn't exist
if (!milestone) {
const create_response = await github.rest.issues.createMilestone({
owner: context.repo.owner,
repo: context.repo.repo,
title: MILESTONE_NUMBER
})
milestone = create_response.data
console.log('Created new milestone with title', MILESTONE_NUMBER, milestone)
}
// Set milestone to PR
await github.rest.issues.update({
owner: context.repo.owner,
repo: context.repo.repo,
milestone: milestone.number,
issue_number: pr_number
})
console.log('Added PR', pr_number, 'to milestone', MILESTONE_NUMBER)