@@ -47,42 +47,47 @@ export async function generateChangelog(
47
47
currentVersion . substring ( 0 , currentVersion . length - 1 - 2 )
48
48
)
49
49
) {
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 ) ) {
58
51
lastReleaseVersion = release . version
59
52
break
60
53
}
61
54
}
62
55
}
63
56
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' )
85
59
}
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
+ )
86
91
}
87
92
88
93
// Returns the release branch from a version tag. A version like `v0.2022.04.11.09.09.stable_01` would
0 commit comments