Skip to content

Commit

Permalink
fix: add GH_TOKEN, TOKEN_GITHUB and TOKEN_GH to the list possib…
Browse files Browse the repository at this point in the history
…le env vars for github token
  • Loading branch information
favna committed Apr 11, 2024
1 parent 207a5d6 commit 0ab906a
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,13 @@ Options:
You can pass the unique string "auto" to automatically set this value as {{org}}/{{name}} as provided from --org and --name
This should be in the format "owner/repo"
You can use the "GITHUB_REPO" environment variable to automatically set this value
--github-token A token to authenticate requests to the GitHub API. This is required when using the "--github-repo" option. You can also set the "GITHUB_TOKEN" environment variable.
--github-token A token to authenticate requests to the GitHub API. This is required when using the "--github-repo" option.
You can also set the one of the following environment variables.
- GITHUB_TOKEN
- GH_TOKEN
- TOKEN_GITHUB
- TOKEN_GH
The multiple options for the name of the environment are to aim to not conflict with other tooling that use similar tokens in case you want to use a unique token for release management.
-v, --verbose Whether to print verbose information (default: false)
-h, --help display help for command
```
Expand Down
2 changes: 1 addition & 1 deletion assets/cliff-jumper.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"type": "string"
},
"githubToken": {
"description": "A token to authenticate requests to the GitHub API. This is required when using the \"--github-repo\" option. You can also set the \"GITHUB_TOKEN\" environment variable.",
"description": "A token to authenticate requests to the GitHub API. This is required when using the \"--github-repo\" option.\nYou can also set the one of the following environment variables.\n- GITHUB_TOKEN\n- GH_TOKEN\n- TOKEN_GITHUB\n- TOKEN_GH",
"type": "string"
},
"install": {
Expand Down
10 changes: 9 additions & 1 deletion src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,15 @@ const command = new Command()
.option('--github-repo', githubRepoDescription)
.option(
'--github-token',
'A token to authenticate requests to the GitHub API. This is required when using the "--github-repo" option. You can also set the "GITHUB_TOKEN" environment variable.'
[
'A token to authenticate requests to the GitHub API. This is required when using the "--github-repo" option.',
'You can also set the one of the following environment variables.',
'- GITHUB_TOKEN',
'- GH_TOKEN',
'- TOKEN_GITHUB',
'- TOKEN_GH',
'The multiple options for the name of the environment are to aim to not conflict with other tooling that use similar tokens in case you want to use a unique token for release management.'
].join('\n')
)
.option('-v, --verbose', 'Whether to print verbose information', false);

Expand Down
7 changes: 5 additions & 2 deletions src/lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,14 @@ export function getGitHubRepo(options: Options): string | undefined {
*
* The order of precedence is:
* 1. Environment variable `GITHUB_TOKEN`
* 2. The `githubToken` property in the options object
* 2. Environment variable `GH_TOKEN`
* 3. Environment variable `TOKEN_GITHUB`
* 4. Environment variable `TOKEN_GH`
* 5. The `githubToken` property in the options object
*
* @param options The options object
* @returns The GitHub token or `undefined` if it was not found
*/
export function getGitHubToken(options: Options): string | undefined {
return process.env.GITHUB_TOKEN ?? options.githubToken ?? undefined;
return process.env.GITHUB_TOKEN ?? process.env.GH_TOKEN ?? process.env.TOKEN_GITHUB ?? process.env.TOKEN_GH ?? options.githubToken ?? undefined;
}

0 comments on commit 0ab906a

Please sign in to comment.