2020-01-13 15:06:32 +00:00
'use strict' ;
const chalk = require ( 'chalk' ) ;
const promptly = require ( 'promptly' ) ;
const { pkg } = require ( '../config' ) ;
const { make } = require ( '../common' ) ;
const { fetchAllPullRequests } = require ( './requests' ) ;
/* eslint no-console: 0 */
2020-01-28 13:47:26 +00:00
let ready = false ;
2020-01-13 15:06:32 +00:00
const makeChangeLog = async ( ) => {
2023-08-23 13:30:35 +00:00
if ( ! pkg . changelog . zhApiToken || ! pkg . changelog . githubToken ) {
2020-01-28 13:47:26 +00:00
const zenhubSet = pkg . changelog . zhApiToken
? chalk . green ( 'set' )
: chalk . red ( 'not set' ) ;
2023-08-23 13:30:35 +00:00
const githubSet = pkg . changelog . githubToken
2020-01-28 13:47:26 +00:00
? chalk . green ( 'set' )
: chalk . red ( 'not set' ) ;
console . log ( ` ${ chalk . yellow ( 'Zenhub Token:' ) } ${ zenhubSet } ` ) ;
2023-08-23 13:30:35 +00:00
console . log ( ` ${ chalk . yellow ( 'GitHub Token:' ) } ${ githubSet } ` ) ;
2020-01-28 13:47:26 +00:00
console . log ( '' ) ;
console . log (
chalk . yellow (
2023-08-23 13:30:35 +00:00
'This program requires an api token from GitHub and Zenhub.'
2020-01-28 13:47:26 +00:00
)
) ;
console . log (
chalk . yellow (
2023-08-23 13:30:35 +00:00
'You can create and get a GitHub token here: https://github.com/settings/tokens'
2020-01-28 13:47:26 +00:00
)
) ;
console . log (
chalk . yellow (
'You can create and get a Zenhub token here: https://app.zenhub.com/dashboard/tokens'
)
) ;
console . log ( '' ) ;
console . log (
chalk . yellow (
2023-08-23 13:30:35 +00:00
'Token scope for GitHub will require read permissions on public_repo, admin:org, and user.'
2020-01-28 13:47:26 +00:00
)
) ;
console . log ( '' ) ;
console . log (
chalk . yellow (
2023-08-23 13:30:35 +00:00
'Export the github token as variable called GITHUB_TOKEN and the Zenhub token as a variable called ZH_API_TOKEN from your bash profile.'
2020-01-28 13:47:26 +00:00
)
) ;
console . log ( '' ) ;
2020-01-13 15:06:32 +00:00
2020-01-28 13:47:26 +00:00
ready = await promptly . confirm ( 'Are you ready to continue? ' ) ;
} else {
console . log (
chalk . green (
2023-08-23 13:30:35 +00:00
'Detected that ZH_API_TOKEN and GITHUB_TOKEN values are set.'
2020-01-28 13:47:26 +00:00
)
) ;
ready = true ;
}
2020-01-13 15:06:32 +00:00
if ( ready ) {
console . log ( '' ) ;
console . log (
chalk . yellow (
'In order to generate the changelog, you will have to provide the Zenhub release ID to retrieve the PRs from. You can get that from `release` param value in the url of the release report page.'
)
) ;
console . log ( '' ) ;
const releaseId = await promptly . prompt ( 'Release Id: ' ) ;
console . log ( '' ) ;
console . log (
chalk . green (
'Here is the generated changelog. Be sure to remove entries ' +
` not intended for a ${ pkg . title } release. All entries with the ${ pkg . changelog . skipLabel } label have been skipped `
)
) ;
console . log ( '' ) ;
make ( fetchAllPullRequests , releaseId ) ;
} else {
console . log ( '' ) ;
console . log ( chalk . yellow ( 'Ok, see you soon.' ) ) ;
console . log ( '' ) ;
}
} ;
module . exports = {
makeChangeLog ,
} ;