Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions scripts/upload-sarif-to-code-scanning.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ def is_code_scanning_disabled_error(status_code: int, response_body: str) -> boo
)


def handle_code_scanning_http_error(error: urllib.error.HTTPError) -> bool:
def handle_code_scanning_http_error(error: urllib.error.HTTPError) -> None:
response_body = error.read().decode("utf-8")
if is_code_scanning_disabled_error(error.code, response_body):
print("::warning::Code Security is not enabled; skipping SARIF upload.")
return True
return
sys.stderr.write(response_body)
raise error

Expand Down Expand Up @@ -166,8 +166,8 @@ def wait_for_sarif_processing(sarif_id: str) -> None:
with urllib.request.urlopen(request) as response:
status_body = json.loads(response.read().decode("utf-8"))
except urllib.error.HTTPError as error:
if handle_code_scanning_http_error(error):
return
handle_code_scanning_http_error(error)
return
processing_status = status_body.get("processing_status")
if processing_status == "complete":
print(json.dumps(status_body))
Expand Down Expand Up @@ -204,8 +204,8 @@ def main() -> int:
response_body = json.loads(response.read().decode("utf-8"))
print(json.dumps(response_body))
except urllib.error.HTTPError as error:
if handle_code_scanning_http_error(error):
return 0
handle_code_scanning_http_error(error)
return 0
sarif_id = response_body.get("id")
if sarif_id:
wait_for_sarif_processing(str(sarif_id))
Expand Down
2 changes: 1 addition & 1 deletion tests/test_upload_sarif_to_code_scanning.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def test_polling_http_error_can_skip_when_code_scanning_is_disabled(capsys):
io.BytesIO(b'{"message":"Code scanning is not enabled"}'),
)

assert module.handle_code_scanning_http_error(error)
assert module.handle_code_scanning_http_error(error) is None
assert "Code Security is not enabled" in capsys.readouterr().out


Expand Down
Loading