Skip to content

Commit 8c3afd6

Browse files
committed
update(changelog): aggregate label errors and handle missing tag
- return list of PRs with errors rather than the first - handle a missing tag and, in internal script BREAKING CHANGE, assume that when the tag is missing we are preparing the release notes for the next release
1 parent bb64c01 commit 8c3afd6

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

resources/gen-changelog.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -57,45 +57,59 @@ process.stdout.write(await genChangeLog());
5757

5858
async function genChangeLog(): Promise<string> {
5959
const { version } = packageJSON;
60-
60+
const releaseTag = `v${version}`;
6161
let tag: string | null = null;
62-
let commitsList = git().revList('--reverse', `v${version}..`);
63-
if (commitsList.length === 0) {
62+
let commitsList: Array<string>;
63+
try {
64+
commitsList = git().revList('--reverse', `${releaseTag}..`);
65+
} catch {
6466
const parentPackageJSON = git().catFile('blob', 'HEAD~1:package.json');
6567
const parentVersion = JSON.parse(parentPackageJSON).version;
6668
commitsList = git().revList('--reverse', `v${parentVersion}..HEAD~1`);
67-
tag = `v${version}`;
69+
tag = releaseTag;
6870
}
6971

7072
const allPRs = await getPRsInfo(commitsList);
7173
const date = git().log('-1', '--format=%cd', '--date=short');
7274

7375
const byLabel: { [label: string]: Array<PRInfo> } = {};
7476
const committersByLogin: { [login: string]: AuthorInfo } = {};
77+
const validationIssues: Array<string> = [];
7578

7679
for (const pr of allPRs) {
7780
const labels = pr.labels.nodes
7881
.map((label) => label.name)
7982
.filter((label) => label.startsWith('PR: '));
8083

8184
if (labels.length === 0) {
82-
throw new Error(`PR is missing label. See ${pr.url}`);
85+
validationIssues.push(`PR #${pr.number} is missing label. See ${pr.url}`);
86+
continue;
8387
}
88+
8489
if (labels.length > 1) {
85-
throw new Error(
86-
`PR has conflicting labels: ${labels.join('\n')}\nSee ${pr.url}`,
90+
validationIssues.push(
91+
`PR #${pr.number} has conflicting labels: ${labels.join(', ')}\nSee ${pr.url}`,
8792
);
93+
continue;
8894
}
8995

9096
const label = labels[0];
9197
if (labelsConfig[label] == null) {
92-
throw new Error(`Unknown label: ${label}. See ${pr.url}`);
98+
validationIssues.push(
99+
`PR #${pr.number} has unknown label: ${label}\nSee ${pr.url}`,
100+
);
101+
continue;
93102
}
103+
94104
byLabel[label] ??= [];
95105
byLabel[label].push(pr);
96106
committersByLogin[pr.author.login] = pr.author;
97107
}
98108

109+
if (validationIssues.length > 0) {
110+
throw new Error(validationIssues.join('\n\n'));
111+
}
112+
99113
let changelog = `## ${tag ?? 'Unreleased'} (${date})\n`;
100114
for (const [label, config] of Object.entries(labelsConfig)) {
101115
const prs = byLabel[label];

0 commit comments

Comments
 (0)