@@ -11,18 +11,26 @@ const {prereleaseTags, checkIgnoreStrategy, getRegistryUrl, isExternalRegistry}
1111const version = require ( './version' ) ;
1212const prettyVersionDiff = require ( './pretty-version-diff' ) ;
1313
14- const printCommitLog = async ( repoUrl , registryUrl ) => {
15- const latest = await git . latestTagOrFirstCommit ( ) ;
16- const log = await git . commitLogFromRevision ( latest ) ;
14+ const printCommitLog = async ( repoUrl , registryUrl , fromLatestTag ) => {
15+ const revision = fromLatestTag ? await git . latestTagOrFirstCommit ( ) : await git . previousTagOrFirstCommit ( ) ;
16+ if ( ! revision ) {
17+ throw new Error ( 'The package has not been published yet.' ) ;
18+ }
19+
20+ const log = await git . commitLogFromRevision ( revision ) ;
1721
1822 if ( ! log ) {
1923 return {
2024 hasCommits : false ,
25+ hasUnreleasedCommits : false ,
2126 releaseNotes : ( ) => { }
2227 } ;
2328 }
2429
25- const commits = log . split ( '\n' )
30+ let hasUnreleasedCommits = false ;
31+ let commitRangeText = `${ revision } ...master` ;
32+
33+ let commits = log . split ( '\n' )
2634 . map ( commit => {
2735 const splitIndex = commit . lastIndexOf ( ' ' ) ;
2836 return {
@@ -31,6 +39,20 @@ const printCommitLog = async (repoUrl, registryUrl) => {
3139 } ;
3240 } ) ;
3341
42+ if ( ! fromLatestTag ) {
43+ const latestTag = await git . latestTag ( ) ;
44+ const versionBumpCommitName = latestTag . slice ( 1 ) ; // Name v1.0.1 becomes 1.0.1
45+ const versionBumpCommitIndex = commits . findIndex ( commit => commit . message === versionBumpCommitName ) ;
46+
47+ if ( versionBumpCommitIndex > 0 ) {
48+ commitRangeText = `${ revision } ...${ latestTag } ` ;
49+ hasUnreleasedCommits = true ;
50+ }
51+
52+ // Get rid of unreleased commits and of the version bump commit.
53+ commits = commits . slice ( versionBumpCommitIndex + 1 ) ;
54+ }
55+
3456 const history = commits . map ( commit => {
3557 const commitMessage = util . linkifyIssues ( repoUrl , commit . message ) ;
3658 const commitId = util . linkifyCommit ( repoUrl , commit . id ) ;
@@ -39,14 +61,15 @@ const printCommitLog = async (repoUrl, registryUrl) => {
3961
4062 const releaseNotes = nextTag => commits . map ( commit =>
4163 `- ${ htmlEscape ( commit . message ) } ${ commit . id } `
42- ) . join ( '\n' ) + `\n\n${ repoUrl } /compare/${ latest } ...${ nextTag } ` ;
64+ ) . join ( '\n' ) + `\n\n${ repoUrl } /compare/${ revision } ...${ nextTag } ` ;
4365
44- const commitRange = util . linkifyCommitRange ( repoUrl , ` ${ latest } ...master` ) ;
66+ const commitRange = util . linkifyCommitRange ( repoUrl , commitRangeText ) ;
4567
4668 console . log ( `${ chalk . bold ( 'Commits:' ) } \n${ history } \n\n${ chalk . bold ( 'Commit Range:' ) } \n${ commitRange } \n\n${ chalk . bold ( 'Registry:' ) } \n${ registryUrl } \n` ) ;
4769
4870 return {
4971 hasCommits : true ,
72+ hasUnreleasedCommits,
5073 releaseNotes
5174 } ;
5275} ;
@@ -92,7 +115,11 @@ module.exports = async (options, pkg) => {
92115 }
93116 }
94117
95- console . log ( `\nPublish a new version of ${ chalk . bold . magenta ( pkg . name ) } ${ chalk . dim ( `(current: ${ oldVersion } )` ) } \n` ) ;
118+ if ( options . releaseDraftOnly ) {
119+ console . log ( `\nCreate a release draft on GitHub for ${ chalk . bold . magenta ( pkg . name ) } ${ chalk . dim ( `(current: ${ oldVersion } )` ) } \n` ) ;
120+ } else {
121+ console . log ( `\nPublish a new version of ${ chalk . bold . magenta ( pkg . name ) } ${ chalk . dim ( `(current: ${ oldVersion } )` ) } \n` ) ;
122+ }
96123
97124 const prompts = [
98125 {
@@ -176,7 +203,24 @@ module.exports = async (options, pkg) => {
176203 }
177204 ] ;
178205
179- const { hasCommits, releaseNotes} = await printCommitLog ( repoUrl , registryUrl ) ;
206+ const useLatestTag = ! options . releaseDraftOnly ;
207+ const { hasCommits, hasUnreleasedCommits, releaseNotes} = await printCommitLog ( repoUrl , registryUrl , useLatestTag ) ;
208+
209+ if ( hasUnreleasedCommits && options . releaseDraftOnly ) {
210+ const answers = await inquirer . prompt ( [ {
211+ type : 'confirm' ,
212+ name : 'confirm' ,
213+ message : 'Unreleased commits found. They won\'t be included in the release draft. Continue?' ,
214+ default : false
215+ } ] ) ;
216+
217+ if ( ! answers . confirm ) {
218+ return {
219+ ...options ,
220+ ...answers
221+ } ;
222+ }
223+ }
180224
181225 if ( options . version ) {
182226 return {
0 commit comments