Use GITHUB_TOKEN as the env variable for the changelog script (https://github.com/woocommerce/woocommerce-blocks/pull/10697)

This commit is contained in:
Sam Seay 2023-08-23 21:30:35 +08:00 committed by GitHub
parent 69bcc49585
commit 1dd1cfadf4
5 changed files with 22 additions and 22 deletions

View File

@ -1,6 +1,6 @@
# Changelog Script
This folder contains the logic for a changelog script that can be used for generating changelog entries from either pull requests added to a Github milestone, or pull requests that are part of a Zenhub release.
This folder contains the logic for a changelog script that can be used for generating changelog entries from either pull requests added to a GitHub milestone, or pull requests that are part of a Zenhub release.
## Usage
@ -37,16 +37,16 @@ The 'variable' in the following table can be used in `package.json` or as a cli
| defaultPrefix | When there is no label with the `labelPrefix` on a pull, this is the default type that will be used for the changelog entry (defaults to `dev`). |
| changelogSrcType | Either "MILESTONE" (default) or "ZENHUB_RELEASE". This determines what will serve as the source for the changelog entries. |
| devNoteLabel | If a pull has this label then `[DN]` will be appended to the end of the changelog. It's a good way to indicate what entries have (or will have) dev notes. |
| repo | This is the namespace for the github repository used as the source for pulls used in the changelog entries. Example: `'woocommerce/woocommerce-gutenberg-products-block'` |
| ghApiToken | You can pass your github api token to the script. NOTE: Strongly recommend you use environment variable for this. |
| zhApiKey | You can pass your zenhub api key to the script using this config. NOTE: Strongly recommend you use environment variable for this. |
| repo | This is the namespace for the GitHub repository used as the source for pulls used in the changelog entries. Example: `'woocommerce/woocommerce-gutenberg-products-block'` |
| githubToken | You can pass your GitHub API token to the script. NOTE: Strongly recommend you use environment variable for this (`GITHUB_TOKEN`). |
| zhApiKey | You can pass your Zenhub api key to the script using this config. NOTE: Strongly recommend you use environment variable for this. |
The two environment variables you can use are:
| Environment Variable | Description |
| -------------------- | ------------------------------------------------------------- |
| GH_API_TOKEN | Github API token for authorizing on the github API. |
| ZH_API_TOKEN | Zenhub api token used for authorizing against the zenhub API. |
| GITHUB_TOKEN | GitHub API token for authorizing on the GitHub API. |
| ZH_API_TOKEN | Zenhub API token used for authorizing against the Zenhub API. |
### Examples
@ -66,11 +66,11 @@ The two environment variables you can use are:
#### Environment Variable
```bash
GH_API_TOKEN="1343ASDFQWER13241REASD" node ./bin/changelog
GITHUB_TOKEN="1343ASDFQWER13241REASD" node ./bin/changelog
```
#### Command Line
```bash
node ./bin/changelog --labelPrefix="type:" --skipLabel="skip-changelog" --defaultPrefix="dev" --repo="woocommerce/woocommerce-gutenberg-products-block" --ghApiToken="1343ASDFQWER13241REASD"
node ./bin/changelog --labelPrefix="type:" --skipLabel="skip-changelog" --defaultPrefix="dev" --repo="woocommerce/woocommerce-gutenberg-products-block" --githubToken="1343ASDFQWER13241REASD"
```

View File

@ -7,7 +7,7 @@ const { pkg, REPO } = require( '../config' );
/* eslint no-console: 0 */
const headers = {
authorization: `token ${ pkg.changelog.ghApiToken }`,
authorization: `token ${ pkg.changelog.githubToken }`,
'user-agent': 'changelog-tool',
};

View File

@ -17,14 +17,14 @@ const DEFAULTS = {
changelogSrcType: changelogSrcTypes.MILESTONE,
devNoteLabel: 'dev-note',
repo: '',
ghApiToken: '',
githubToken: '',
zhApiToken: '',
};
pkg.changelog = pkg.changelog || DEFAULTS;
config.merge( { ...DEFAULTS, ...pkg.changelog } );
config.env( [ 'GH_API_TOKEN', 'ZH_API_TOKEN' ] );
config.env( [ 'GITHUB_TOKEN', 'ZH_API_TOKEN' ] );
config.argv( Object.keys( DEFAULTS ) );
const REPO = config.get( 'repo' );

View File

@ -9,7 +9,7 @@ const { fetchAllPullRequests } = require( './requests' );
let ready = false;
const makeChangeLog = async () => {
if ( ! pkg.changelog.ghApiToken ) {
if ( ! pkg.changelog.githubToken ) {
console.log(
chalk.yellow(
'This program requires an api token. You can create one here: '
@ -24,14 +24,14 @@ const makeChangeLog = async () => {
console.log( '' );
console.log(
chalk.yellow(
'Export the token as variable called GH_API_TOKEN from your bash profile.'
'Export the token as variable called GITHUB_TOKEN from your bash profile.'
)
);
console.log( '' );
ready = await promptly.confirm( 'Are you ready to continue? ' );
} else {
console.log( chalk.green( 'Detected GH_API_TOKEN is set.' ) );
console.log( chalk.green( 'Detected GITHUB_TOKEN is set.' ) );
ready = true;
}

View File

@ -9,24 +9,24 @@ const { fetchAllPullRequests } = require( './requests' );
let ready = false;
const makeChangeLog = async () => {
if ( ! pkg.changelog.zhApiToken || ! pkg.changelog.ghApiToken ) {
if ( ! pkg.changelog.zhApiToken || ! pkg.changelog.githubToken ) {
const zenhubSet = pkg.changelog.zhApiToken
? chalk.green( 'set' )
: chalk.red( 'not set' );
const githubSet = pkg.changelog.ghApiToken
const githubSet = pkg.changelog.githubToken
? chalk.green( 'set' )
: chalk.red( 'not set' );
console.log( `${ chalk.yellow( 'Zenhub Token:' ) } ${ zenhubSet }` );
console.log( `${ chalk.yellow( 'Github Token:' ) } ${ githubSet }` );
console.log( `${ chalk.yellow( 'GitHub Token:' ) } ${ githubSet }` );
console.log( '' );
console.log(
chalk.yellow(
'This program requires an api token from Github and Zenhub.'
'This program requires an api token from GitHub and Zenhub.'
)
);
console.log(
chalk.yellow(
'You can create and get a Github token here: https://github.com/settings/tokens'
'You can create and get a GitHub token here: https://github.com/settings/tokens'
)
);
console.log(
@ -37,13 +37,13 @@ const makeChangeLog = async () => {
console.log( '' );
console.log(
chalk.yellow(
'Token scope for Github will require read permissions on public_repo, admin:org, and user.'
'Token scope for GitHub will require read permissions on public_repo, admin:org, and user.'
)
);
console.log( '' );
console.log(
chalk.yellow(
'Export the github token as variable called GH_API_TOKEN and the Zenhub token as a variable called ZH_API_TOKEN from your bash profile.'
'Export the github token as variable called GITHUB_TOKEN and the Zenhub token as a variable called ZH_API_TOKEN from your bash profile.'
)
);
console.log( '' );
@ -52,7 +52,7 @@ const makeChangeLog = async () => {
} else {
console.log(
chalk.green(
'Detected that ZH_API_TOKEN and GH_API_TOKEN values are set.'
'Detected that ZH_API_TOKEN and GITHUB_TOKEN values are set.'
)
);
ready = true;