-
Notifications
You must be signed in to change notification settings - Fork 41
/
generate-latest-changelog.js
71 lines (49 loc) · 1.79 KB
/
generate-latest-changelog.js
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
import fs from 'fs';
import { Octokit } from '@octokit/core';
import * as dotenv from 'dotenv';
dotenv.config();
const changelogPath = './CHANGELOG.md';
const template = `<!-- ## [x.x.x] - YYYY-MM-DD -->
<!-- ## Unreleased -->
<!-- ### Added -->
<!-- ### Changed -->
<!-- ### Deprecated -->
<!-- ### Removed -->
<!-- ### Fixed -->`;
const run = async () => {
const version = process.argv[2];
if (!version) {
console.error('Version not defined. Run command as `npm run generate-changelog 2.9.0`');
return;
}
const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN,
})
const response = await octokit.request('GET /search/issues', {
q: `is:closed is:issue milestone:"TruBudget ${version}"`,
headers: {
'X-GitHub-Api-Version': '2022-11-28'
}
})
if (response.data.incomplete_results) {
console.log('INCOMPLETE RESULTS');
return;
}
const issues = response.data.items;
let changelogText = '';
issues.forEach(issue => {
changelogText += `- ${issue.title} [#${issue.number}](${issue.html_url})\n`;
});
const file = fs.readFileSync(changelogPath, 'utf-8');
const today = new Date();
const newReleaseChangelog = template.replace('<!-- ## [x.x.x] - YYYY-MM-DD -->',`
## [${version}] - ${today.toISOString().split('T')[0]}`).replace('<!-- ### Added -->',`### Added
${changelogText}`);
const newText = file.replace(template, `${template}
${newReleaseChangelog}`)
.replace(/\[unreleased\]: https:\/\/github\.com\/openkfw\/TruBudget\/compare\/v(\d+\.\d+\.\d+)\.\.\.main[\r\n]\[(\d+\.\d+\.\d+)\]/m,
`[unreleased]: https://github.com/openkfw/TruBudget/compare/v${version}...main\n[${version}]: https://github.com/openkfw/TruBudget/compare/v$1...v${version}\n[$1]`
);
fs.writeFileSync(changelogPath, newText, 'utf-8');
}
run();