Get the GITHUB_TOKEN to be able to authenticate to the API.
(ctx: Context)
| 245 | |
| 246 | |
| 247 | def get_github_token(ctx: Context) -> str | None: |
| 248 | """ |
| 249 | Get the GITHUB_TOKEN to be able to authenticate to the API. |
| 250 | """ |
| 251 | github_token = os.environ.get("GITHUB_TOKEN") |
| 252 | if github_token is not None: |
| 253 | ctx.info("$GITHUB_TOKEN was found on the environ") |
| 254 | return github_token |
| 255 | |
| 256 | gh = shutil.which("gh") |
| 257 | if gh is None: |
| 258 | ctx.info("The 'gh' CLI tool is not available. Can't get a token using it.") |
| 259 | return github_token |
| 260 | |
| 261 | ret = ctx.run(gh, "auth", "token", check=False, capture=True) |
| 262 | if ret.returncode == 0: |
| 263 | ctx.info("Got the GitHub token from the 'gh' CLI tool") |
| 264 | return ret.stdout.decode().strip() or None |
| 265 | ctx.info("Failed to get the GitHub token from the 'gh' CLI tool") |
| 266 | return github_token |
| 267 | |
| 268 | |
| 269 | def download_artifact( |
no test coverage detected