Skip to content

Commit d73e913

Browse files
nim65sMic92
authored andcommitted
add GITHUB_TOKEN_CMD
This environment variable can be used to specify a command which should return the token. This can for example be globally defined to a public command which would ask a password manager to provide this secret, eg. `pass github-token` or `rbw get github-token`
1 parent 89ea73d commit d73e913

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,12 @@ for detailed instructions. For posting generated reports, ensure the token is
261261
granted the `public_repo` scope.
262262

263263
**Supplying the Token** You can provide your token to Nixpkgs-review using
264-
either the `GITHUB_TOKEN` environment variable or the `--token` parameter of the
265-
`pr` subcommand. Examples:
264+
either the `GITHUB_TOKEN` / `GITHUB_TOKEN_CMD` environment variable or the
265+
`--token` parameter of the `pr` subcommand. Examples:
266266

267267
```console
268268
$ GITHUB_TOKEN=ghp_WAI7vpi9wVHbxPOA185NwWvaMawDuCnMGc3E nixpkgs-review pr 37244 --post-result
269+
$ GITHUB_TOKEN_CMD="pass github-token" nixpkgs-review pr 37244 --post-result
269270
$ nixpkgs-review pr 37244 --token ghp_WAI7vpi9wVHbxPOA185NwWvaMawDuCnMGc3E --post-result
270271
```
271272

nixpkgs_review/cli/__init__.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,14 @@ def read_github_token() -> str | None:
144144
token = os.environ.get("GITHUB_OAUTH_TOKEN", os.environ.get("GITHUB_TOKEN"))
145145
if token:
146146
return token
147+
token_cmds = []
148+
if "GITHUB_TOKEN_CMD" in os.environ:
149+
token_cmds.append(os.environ.get("GITHUB_TOKEN_CMD").split())
147150
if which("gh"):
151+
token_cmds.append(["gh", "auth", "token"])
152+
for token_cmd in token_cmds:
148153
r = subprocess.run(
149-
["gh", "auth", "token"], stdout=subprocess.PIPE, text=True, check=False
154+
token_cmd, stdout=subprocess.PIPE, text=True, check=False
150155
)
151156
if r.returncode == 0:
152157
return r.stdout.strip()

0 commit comments

Comments
 (0)