diff --git a/scripts/upload-sarif-to-code-scanning.py b/scripts/upload-sarif-to-code-scanning.py index 81ad5db..13c7985 100644 --- a/scripts/upload-sarif-to-code-scanning.py +++ b/scripts/upload-sarif-to-code-scanning.py @@ -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 @@ -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)) @@ -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)) diff --git a/tests/test_upload_sarif_to_code_scanning.py b/tests/test_upload_sarif_to_code_scanning.py index dcbbb86..fe55d8b 100644 --- a/tests/test_upload_sarif_to_code_scanning.py +++ b/tests/test_upload_sarif_to_code_scanning.py @@ -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