Skip to content

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

@CallMeGreg

Description

@CallMeGreg

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! πŸ˜ƒ

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions