forked from Unidata/MetPy
-
Notifications
You must be signed in to change notification settings - Fork 0
69 lines (62 loc) · 2.74 KB
/
draft-release.yml
File metadata and controls
69 lines (62 loc) · 2.74 KB
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
# When we close a milestone, create a draft release
name: Draft Release
on:
milestone:
types: [closed]
permissions:
issues: read
pull-requests: read
contents: write
jobs:
sync:
name: Create Release
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v4.0.2
name: Run script
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const milestone = context.payload.milestone;
// Find issues and PRs for this milestone
github.paginate(github.issues.listForRepo, {
owner: context.repo.owner,
repo: context.repo.repo,
state: 'all',
milestone: milestone.number
})
.then((items) => {
// Get just the issues and format into a section for the release notes
const issues = items.filter(i => !i.pull_request);
const issue_text = '### Issues Closed\n' +
issues.map(i => `* [Issue ${i.number}](${i.html_url}) - ${i.title}\n`)
.join('') + `\n${issues.length} issues were closed in this release.`;
// Now do the same for the PRs
const prs = items.filter(i => !!i.pull_request);
const pr_text = '### Pull Requests Merged\n' +
prs.map(i => `* [PR ${i.number}](${i.html_url}) - ${i.title}, by @${i.user.login}\n`)
.join('') + `\n${prs.length} pull requests were closed in this release.`;
// Add the list of people who contributed PRs
const contrib_text = '### Contributors\n' +
Array.from(new Set(items.map(i => '@' + i.user.login))).join(', ') +
' contributed code to this release.';
// Assemble into the body of the release
const body = [milestone.description, contrib_text, issue_text, pr_text].join('\n');
// Allows us to optionally pass in a branch of if there's one specified in the
// text of the milestone
params = {
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: 'v' + milestone.title,
name: milestone.title,
draft: true,
body: body,
discussion_category_name: 'Announcements'
};
const match = milestone.description.match(/branch:\s*([^\s]+)/);
if (!!match) {
params.target_commitish = match[1];
console.log('Found target branch:', params.target_commitish);
}
github.repos.createRelease(params);
});