-
Notifications
You must be signed in to change notification settings - Fork 53
/
print-version-bump-info.ts
132 lines (123 loc) · 3.96 KB
/
print-version-bump-info.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import { Octokit } from "octokit";
import yargs from "yargs";
import { getCommitAndLabels } from "./github-utils";
async function printInfo(octokit: Octokit, previousVersion: string, nextVersion: string) {
const owners = {
"polkadot-sdk": "paritytech",
};
const prefixes = {
"polkadot-sdk": "polkadot-",
};
console.log(`# Description\n`);
console.log(`This ticket is automatically generated using\n`);
console.log("```");
console.log(`$ npm run print-version-bump-info -- --from ${previousVersion} --to ${nextVersion}`);
console.log("```");
const prInfoByLabels = {};
for (const repo of Object.keys(prefixes)) {
const previousTag = `${prefixes[repo]}${previousVersion}`;
const nextTag = `${prefixes[repo]}${nextVersion}`;
try {
const previousCommit = await octokit.rest.git.getCommit({
owner: owners[repo],
repo,
commit_sha: (
await octokit.rest.git.getTree({
owner: owners[repo],
repo,
tree_sha: previousTag,
})
).data.sha,
});
const nextCommit = await octokit.rest.git.getCommit({
owner: owners[repo],
repo,
commit_sha: (
await octokit.rest.git.getTree({
owner: owners[repo],
repo,
tree_sha: nextTag,
})
).data.sha,
});
console.log(
`\n## ${repo} (${previousCommit.data.author.date.slice(
0,
10
)} -> ${nextCommit.data.author.date.slice(0, 10)})\n`
);
const { commits, prByLabels } = await getCommitAndLabels(
octokit,
owners[repo],
repo,
previousTag,
nextTag
);
console.log(`https://github.com/${owners[repo]}/${repo}/compare/${previousTag}...${nextTag}`);
console.log("```");
console.log(` from: ${previousCommit.data.sha}`);
console.log(` to: ${nextCommit.data.sha}`);
console.log(` commits: ${commits.length}`);
console.log("```");
for (const label of Object.keys(prByLabels)) {
prInfoByLabels[label] = (prInfoByLabels[label] || []).concat(
prByLabels[label].map((pr) => {
return ` ${`(${owners[repo]}/${repo}#${pr.number}) ${pr.title}`}`;
})
);
}
} catch (e) {
console.trace(`Failing to query ${repo} [${previousTag}..${nextTag}]: ${e.toString()}`);
process.exit(1);
}
}
console.log(
`\n# Important commits by [label](https://paritytech.github.io/labels/doc_polkadot-sdk.html)\n`
);
const excludeRegs = [
/R0-/, // Silent Release
/I[0-9]-/, // Issue Category
/D[0-9]-/, // Difficulty
/C[0-9]-/, // Contribution
/A[0-9]-/, // Action
];
for (const labelName of Object.keys(prInfoByLabels).sort().reverse()) {
if (excludeRegs.some((f) => f.test(labelName))) {
continue;
}
console.log(`\n### ${labelName || "N/A"}\n`);
// Deduplicate PRs on same label
const deduplicatePrsOfLabel = prInfoByLabels[labelName].filter(function (elem, index, self) {
return index === self.indexOf(elem);
});
for (const prInfo of deduplicatePrsOfLabel) {
console.log(prInfo);
}
}
console.log(`\n## Review 'substrate-migrations' repo\n`);
console.log(`https://github.com/apopiak/substrate-migrations#frame-migrations`);
console.log(`\nThis repository contains a list of FRAME-related migrations which might be`);
console.log(`relevant to Moonbeam.`);
}
async function main() {
const argv = yargs(process.argv.slice(2))
.usage("Usage: npm run print-version-deps [args]")
.version("1.0.0")
.options({
from: {
type: "string",
describe: "commit-sha/tag of range start",
},
to: {
type: "string",
describe: "commit-sha/tag of range end",
},
})
.demandOption(["from", "to"])
.help().argv;
const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN || undefined,
});
printInfo(octokit, argv.from, argv.to);
}
main();