Skip to content

Commit 84cc011

Browse files
committed
code review
1 parent 416a09a commit 84cc011

File tree

1 file changed

+34
-29
lines changed

1 file changed

+34
-29
lines changed

src/generate-changelog.ts

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -47,42 +47,47 @@ export async function generateChangelog(
4747
currentVersion.substring(0, currentVersion.length - 1 - 2)
4848
)
4949
) {
50-
// Check for a release where `release.version` is less then `currentVersion`, which means `localCompare` would return `1`.
51-
// This is by no means a perfect check, but should suffice because each version is of the exact same format and length.
52-
if (
53-
currentVersion.localeCompare(release.version, undefined /* locales */, {
54-
numeric: true,
55-
sensitivity: 'base'
56-
}) === 1
57-
) {
50+
if (isVersionGreater(currentVersion, release.version)) {
5851
lastReleaseVersion = release.version
5952
break
6053
}
6154
}
6255
}
6356

64-
if (lastReleaseVersion) {
65-
// Find all the commits in the branch for the current release that aren't in the branch for the last release.
66-
const currentBranch = branchFromVersion(currentVersion, channel)
67-
const previousBranch = branchFromVersion(lastReleaseVersion, channel)
68-
69-
// Find all the commits that are in `currentBranch` but not `previousBranch`.
70-
const command = shell.exec(
71-
`git --no-pager log ^${previousBranch} ${currentBranch} --pretty=format:%H`,
72-
{silent: true}
73-
)
74-
75-
const commits = command.stdout.trim().split('\n')
76-
const pullRequestMetadata = await fetchPullRequestBodyFromCommits(
77-
commits,
78-
graphqlWithAuth
79-
)
80-
return parseChangelogFromPrDescriptions(pullRequestMetadata)
81-
} else {
82-
return Promise.reject(
83-
Error('Unable to find last release prior to the given release')
84-
)
57+
if (!lastReleaseVersion) {
58+
throw new Error('Unable to find last release prior to the given release')
8559
}
60+
61+
// Find all the commits in the branch for the current release that aren't in the branch for the last release.
62+
const currentBranch = branchFromVersion(currentVersion, channel)
63+
const previousBranch = branchFromVersion(lastReleaseVersion, channel)
64+
65+
// Find all the commits that are in `currentBranch` but not `previousBranch`.
66+
const command = shell.exec(
67+
`git --no-pager log ^${previousBranch} ${currentBranch} --pretty=format:%H`,
68+
{silent: true}
69+
)
70+
71+
const commits = command.stdout.trim().split('\n')
72+
const pullRequestMetadata = await fetchPullRequestBodyFromCommits(
73+
commits,
74+
graphqlWithAuth
75+
)
76+
return parseChangelogFromPrDescriptions(pullRequestMetadata)
77+
}
78+
79+
// Check for a release where `currentVersion` is greater than `release.version`, which means `localCompare` would return `1`.
80+
// This is by no means a perfect check, but should suffice because each version is of the exact same format and length.
81+
function isVersionGreater(
82+
currentVersion: string,
83+
releaseVersion: string
84+
): boolean {
85+
return (
86+
currentVersion.localeCompare(releaseVersion, undefined /* locales */, {
87+
numeric: true,
88+
sensitivity: 'base'
89+
}) === 1
90+
)
8691
}
8792

8893
// Returns the release branch from a version tag. A version like `v0.2022.04.11.09.09.stable_01` would

0 commit comments

Comments
 (0)