MCPcopy Index your code
hub / github.com/saltstack/salt / get_github_token

Function get_github_token

tools/utils/gh.py:247–266  ·  view source on GitHub ↗

Get the GITHUB_TOKEN to be able to authenticate to the API.

(ctx: Context)

Source from the content-addressed store, hash-verified

245
246
247def 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
269def download_artifact(

Callers 2

download_artifactFunction · 0.85
discover_run_idFunction · 0.85

Calls 3

getMethod · 0.45
infoMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected