Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
CallMeGreg opened this issue Mar 14, 2023 · 1 comment

Comments

@CallMeGreg
Copy link
Contributor

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
Copy link
Collaborator

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants