-
Notifications
You must be signed in to change notification settings - Fork 320
/
generate-release-body.ts
82 lines (70 loc) · 2.04 KB
/
generate-release-body.ts
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
import { Octokit } from "octokit";
import yargs from "yargs";
import { getCommitAndLabels, getCompareLink } from "./github-utils";
const BINARY_CHANGES_LABEL = "B5-clientnoteworthy";
const BREAKING_CHANGES_LABEL = "breaking";
function capitalize(s) {
return s[0].toUpperCase() + s.slice(1);
}
async function main() {
const argv = yargs(process.argv.slice(2))
.usage("Usage: npm run ts-node github/generate-release-body.ts [args]")
.version("1.0.0")
.options({
from: {
type: "string",
describe: "previous tag to retrieve commits from",
required: true,
},
to: {
type: "string",
describe: "current tag being drafted",
required: true,
},
owner: {
type: "string",
describe: "Repository owner (Ex: PureStake)",
required: true,
},
repo: {
type: "string",
describe: "Repository name (Ex: moonbeam)",
required: true,
},
})
.demandOption(["from", "to"])
.help().argv;
const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN || undefined,
});
const previousTag = argv.from;
const newTag = argv.to;
const moduleLinks = ["polkadot-sdk", "frontier", "moonkit"].map((repoName) => ({
name: repoName,
link: getCompareLink(repoName, previousTag, newTag),
}));
const { prByLabels } = await getCommitAndLabels(
octokit,
argv.owner,
argv.repo,
previousTag,
newTag
);
const filteredPr = prByLabels[BINARY_CHANGES_LABEL] || [];
const printPr = (pr) => {
if (pr.labels.includes(BREAKING_CHANGES_LABEL)) {
return "⚠️ " + pr.title + " (#" + pr.number + ")";
} else {
return pr.title + " (#" + pr.number + ")";
}
};
const template = `
## Changes
${filteredPr.map((pr) => `* ${printPr(pr)}`).join("\n")}
## Dependency changes
Moonbeam: https://github.com/${argv.owner}/${argv.repo}/compare/${previousTag}...${newTag}
${moduleLinks.map((modules) => `${capitalize(modules.name)}: ${modules.link}`).join("\n")}
`;
console.log(template);
}
main();