advanced-security / gh-code-scanning

A GitHub CLI extension for GitHub Code-Scanning!
24 stars 6 forks source link

Feature request: gracefully handle repos without code scanning analysis #19

Open CallMeGreg opened 1 year ago

CallMeGreg commented 1 year ago

When running gh repo list callmegreg-demo-org --json nameWithOwner --jq '.[].nameWithOwner' | xargs gh code-scanning alerts against an org that has a repo with GHAS enabled, but no code scanning analysis, I receive the following error:

Traceback (most recent call last):
  File "/Users/gregmohler/.local/share/gh/extensions/gh-code-scanning/gh-code-scanning", line 138, in api
    process = subprocess.run(command, input=params, text=True, capture_output=True, check=True)
  File "/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.9/lib/python3.9/subprocess.py", line 528, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['/opt/homebrew/bin/gh', 'api', 'repos/callmegreg-demo-org/secret-repo/code-scanning/alerts', '--include', '--method=GET', '--paginate', '--field=per_page=100']' returned non-zero exit status 1.

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/Users/gregmohler/.local/share/gh/extensions/gh-code-scanning/gh-code-scanning", line 483, in <module>
    main()
  File "/Users/gregmohler/.local/share/gh/extensions/gh-code-scanning/gh-code-scanning", line 480, in main
    args.func(args)
  File "/Users/gregmohler/.local/share/gh/extensions/gh-code-scanning/gh-code-scanning", line 398, in do_alerts
    for alert in repo.alerts():
  File "/Users/gregmohler/.local/share/gh/extensions/gh-code-scanning/gh-code-scanning", line 212, in alerts
    alerts_json_raw = self.api(f'repos/{self.name_with_owner}/code-scanning/alerts', params={'per_page':100}, raw_output=True)
  File "/Users/gregmohler/.local/share/gh/extensions/gh-code-scanning/gh-code-scanning", line 177, in api
    raise GithubError(
__main__.GithubError: gh: no analysis found (HTTP 404)

Ideally, this repo is ignored by the command. Planning to investigate potential solutions on my end! 😃

mario-campos commented 1 year ago

Thanks for marking this issue! I'll take a look.