@@ -27,6 +27,8 @@ const { spawnSync } = require("child_process"),
2727const gitRawCommits = require ( "git-raw-commits" ) ,
2828 semver = require ( "semver" ) ,
2929 getStream = require ( "get-stream" ) ,
30+ externalEditor = require ( "external-editor" ) ,
31+ open = require ( "open" ) ,
3032 _ = require ( "colors" )
3133;
3234
@@ -78,35 +80,10 @@ async function main() {
7880 //
7981
8082 console . log ( `Updating ${ CHANGELOG_PATH } and ${ GO_VERSION_PATH } ` . blue ) ;
81- // Generate changelog lines by section
82- const changelogLines = { feat : [ ] , fix : [ ] } ;
83- commits . forEach ( commit => {
84- const result = COMMIT_REGEX . exec ( commit ) ;
85- if ( ! result || ! ( result . groups . type in changelogLines ) ) {
86- console . warn ( `WARNING: Ignoring commit ${ commit } ` . yellow ) ;
87- return ;
88- }
89- const stdCommit = result . groups ;
90-
91- let line = [ `*` , stdCommit . scope ? `**${ stdCommit . scope } **:` : "" , stdCommit . message , stdCommit . mr ? `([#${ stdCommit . mr } ](https://github.com/scaleway/scaleway-sdk-go/pull/${ stdCommit . mr } ))` : "" ]
92- . map ( s => s . trim ( ) )
93- . filter ( v => v )
94- . join ( " " ) ;
95- changelogLines [ stdCommit . type ] . push ( line ) ;
96- } ) ;
97-
98- const changelogHeader = `## v${ newVersion } (${ new Date ( ) . toISOString ( ) . substring ( 0 , 10 ) } )` ;
99- const changelogSections = [ ] ;
100- if ( changelogLines . feat ) {
101- changelogSections . push ( "### Features\n\n" + changelogLines . feat . join ( "\n" ) ) ;
102- }
103- if ( changelogLines . fix ) {
104- changelogSections . push ( "### Fixes\n\n" + changelogLines . fix . join ( "\n" ) ) ;
105- }
106- const changelogBody = changelogSections . join ( "\n\n" ) ;
107- const changelog = `${ changelogHeader } \n\n${ changelogBody } ` ;
83+ const changelog = buildChangelog ( newVersion , commits ) ;
84+ changelog . body = externalEditor . edit ( changelog . body ) ;
10885
109- replaceInFile ( CHANGELOG_PATH , "# Changelog" , " # Changelog\n\n" + changelog + "\n" ) ;
86+ replaceInFile ( CHANGELOG_PATH , "# Changelog" , ` # Changelog\n\n${ changelog . header } \n\n ${ changelog . body } \n` ) ;
11087 replaceInFile ( GO_VERSION_PATH , / c o n s t v e r s i o n [ ^ \n ] * \n / , `const version = "v${ newVersion } "\n` ) ;
11188 console . log ( ` Update success` . green ) ;
11289
@@ -117,13 +94,16 @@ async function main() {
11794 git ( "add" , CHANGELOG_PATH , GO_VERSION_PATH ) ;
11895 git ( "commit" , "-m" , `chore: release ${ newVersion } ` ) ;
11996 git ( "push" , "-f" , "--set-upstream" , TMP_REMOTE , TMP_BRANCH ) ;
120-
121- await prompt ( `Please create an PR here: https://github.com/scaleway/scaleway-sdk-go/pull/new/new-release . Hit enter when its merged .....` . magenta ) ;
122-
123- console . log ( "Time to create a github release with the following info\n" . blue ) ;
124- console . log ( `Title: v${ newVersion } \n\n` . gray ) ;
125- console . log ( `${ changelogBody } \n\n` . gray ) ;
126- await prompt ( `You should create a new github release here: https://github.com/scaleway/scaleway-sdk-go/releases/new/ . Hit enter when the new release is created .....` . magenta ) ;
97+ openBrowser ( "https://github.com/scaleway/scaleway-sdk-go/pull/new/new-release" ) ;
98+ await prompt ( `Hit enter when its merged .....` . magenta ) ;
99+
100+ console . log ( "Time to create a github release\n" . blue ) ;
101+ openBrowser ( "https://github.com/scaleway/scaleway-sdk-go/releases/new/" , {
102+ tag : `v${ newVersion } ` ,
103+ title : `v${ newVersion } ` ,
104+ body : changelog . body ,
105+ } ) ;
106+ await prompt ( `Hit enter when the new release is created .....` . magenta ) ;
127107
128108 //
129109 // Creating post release commit
@@ -138,11 +118,12 @@ async function main() {
138118 git ( "checkout" , "-b" , TMP_BRANCH ) ;
139119 replaceInFile ( GO_VERSION_PATH , / c o n s t v e r s i o n [ ^ \n ] * \n / , `const version = "v${ newVersion } +dev"\n` ) ;
140120 git ( "add" , GO_VERSION_PATH ) ;
141- git ( "commit" , "-m" , " chore: post release commit" ) ;
121+ git ( "commit" , "-m" , ` chore: cleanup after v ${ newVersion } release` ) ;
142122 git ( "push" , "-f" , "--set-upstream" , TMP_REMOTE , TMP_BRANCH ) ;
143123 git ( "checkout" , "master" ) ;
144124 git ( "branch" , "-D" , TMP_BRANCH ) ;
145- await prompt ( `Please create an PR here: https://github.com/scaleway/scaleway-sdk-go/pull/new/new-release . Hit enter when its merged .....` . magenta ) ;
125+ openBrowser ( "https://github.com/scaleway/scaleway-sdk-go/pull/new/new-release" ) ;
126+ await prompt ( `Hit enter when its merged .....` . magenta ) ;
146127
147128 console . log ( "Make sure we pull the latest commit from master" . blue ) ;
148129 git ( "pull" , TMP_REMOTE , "master" ) ;
@@ -183,4 +164,58 @@ function prompt(prompt) {
183164 } ) ;
184165}
185166
167+ function openBrowser ( url , query = { } ) {
168+ const params = new URLSearchParams ( query ) ;
169+ url = `${ url } ?${ params . toString ( ) } ` ;
170+ console . log ( ` Opening ${ url } ` . grey ) ;
171+ open ( url ) ;
172+ }
173+
174+ function buildChangelog ( newVersion , commits ) {
175+ const changelogLines = { feat : [ ] , fix : [ ] , others : [ ] } ;
176+ commits . forEach ( commit => {
177+ const result = COMMIT_REGEX . exec ( commit ) ;
178+
179+ // If commit do not match a valid commit regex we add it in others section without formatting
180+ if ( ! result ) {
181+ console . warn ( `WARNING: Malformed commit ${ commit } ` . yellow ) ;
182+ changelogLines . others . push ( commit ) ;
183+ return ;
184+ }
185+ const stdCommit = result . groups ;
186+
187+ // If commit type is not one of [feat, fix] we add it in the other group. This will probably need further human edition.
188+ if ( ! ( stdCommit . type in changelogLines ) ) {
189+ stdCommit . scope = [ stdCommit . type , stdCommit . scope ] . filter ( str => str ) . join ( " - " ) ;
190+ stdCommit . type = "others" ;
191+ }
192+
193+ const line = [
194+ `*` ,
195+ stdCommit . scope ? `**${ stdCommit . scope } **:` : "" ,
196+ stdCommit . message ,
197+ stdCommit . mr ? `([#${ stdCommit . mr } ](https://github.com/scaleway/scaleway-sdk-go/pull/${ stdCommit . mr } ))` : ""
198+ ]
199+ . map ( s => s . trim ( ) )
200+ . filter ( v => v )
201+ . join ( " " ) ;
202+ changelogLines [ stdCommit . type ] . push ( line ) ;
203+ } ) ;
204+
205+ const changelogSections = [ ] ;
206+ if ( changelogLines . feat ) {
207+ changelogSections . push ( "### Features\n\n" + changelogLines . feat . sort ( ) . join ( "\n" ) ) ;
208+ }
209+ if ( changelogLines . fix ) {
210+ changelogSections . push ( "### Fixes\n\n" + changelogLines . fix . sort ( ) . join ( "\n" ) ) ;
211+ }
212+ if ( changelogLines . others ) {
213+ changelogSections . push ( "### Others\n\n" + changelogLines . others . sort ( ) . join ( "\n" ) ) ;
214+ }
215+ return {
216+ header : `## v${ newVersion } (${ new Date ( ) . toISOString ( ) . substring ( 0 , 10 ) } )` ,
217+ body : changelogSections . join ( "\n\n" ) ,
218+ }
219+ }
220+
186221main ( ) . catch ( console . error ) ;
0 commit comments