Skip to content

Commit

Permalink
[update-changelog] Fix bug introduced in #158
Browse files Browse the repository at this point in the history
- `updateChangelog` returns results even if `isReleaseCandidate` is false
  • Loading branch information
MajorLift committed Dec 8, 2023
1 parent f65c16b commit a02b488
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions src/update-changelog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,12 @@ export async function updateChangelog({
projectRootDirectory,
tagPrefixes = ['v'],
formatter = undefined,
}: UpdateChangelogOptions): Promise<string | undefined> {
}: UpdateChangelogOptions): Promise<string | undefined | never> {
if (isReleaseCandidate && !currentVersion) {
throw new Error(
`A version must be specified if 'isReleaseCandidate' is set.`,
);
}
const changelog = parseChangelog({
changelogContent,
repoUrl,
Expand Down Expand Up @@ -233,14 +238,8 @@ export async function updateChangelog({
return undefined;
}

if (isReleaseCandidate) {
if (!currentVersion) {
throw new Error(
`A version must be specified if 'isReleaseCandidate' is set.`,
);
}

if (mostRecentTag === `${tagPrefixes[0]}${currentVersion ?? ''}`) {
if (isReleaseCandidate && currentVersion) {
if (mostRecentTag === `${tagPrefixes[0]}${currentVersion}`) {
throw new Error(
`Current version already has a tag ('${mostRecentTag}'), which is unexpected for a release candidate.`,
);
Expand All @@ -258,22 +257,22 @@ export async function updateChangelog({
if (hasUnreleasedChanges) {
changelog.migrateUnreleasedChangesToRelease(currentVersion);
}
}

const newChangeEntries = newCommits.map(({ prNumber, description }) => {
if (prNumber) {
const suffix = `([#${prNumber}](${repoUrl}/pull/${prNumber}))`;
return `${description} ${suffix}`;
}
return description;
});

for (const description of newChangeEntries.reverse()) {
changelog.addChange({
version: isReleaseCandidate ? currentVersion : undefined,
category: ChangeCategory.Uncategorized,
description,
});
const newChangeEntries = newCommits.map(({ prNumber, description }) => {
if (prNumber) {
const suffix = `([#${prNumber}](${repoUrl}/pull/${prNumber}))`;
return `${description} ${suffix}`;
}
return description;
});

for (const description of newChangeEntries.reverse()) {
changelog.addChange({
version: isReleaseCandidate ? currentVersion : undefined,
category: ChangeCategory.Uncategorized,
description,
});
}

return changelog.toString();
Expand Down

0 comments on commit a02b488

Please sign in to comment.