fix(scripts): add timeout and status handling to GitHub workflow cancellation script#6
Open
outwrit wants to merge 1 commit into
Open
fix(scripts): add timeout and status handling to GitHub workflow cancellation script#6outwrit wants to merge 1 commit into
outwrit wants to merge 1 commit into
Conversation
…ellation script - Add REQUEST_TIMEOUT (30s) to every GitHub API call - Call raise_for_status() before consuming response body - Handle empty response bodies (e.g., 202 from cancel endpoint) - Surface Timeout and HTTPError as ClickException with clear messages - Handle non-JSON error responses gracefully - Remove noqa: S113 (no longer needed with explicit timeout) - Add focused unit tests for the request() helper Fixes #2 Co-Authored-By: bot_apk <apk@cognition.ai>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
SUMMARY
Fixes #2
The
request()helper inscripts/cancel_github_workflows.pycalledrequests.request()without a timeout and assumed every response body was valid JSON. This could hang indefinitely in CI/local usage or produce confusingJSONDecodeErrortracebacks when the API returned non-2xx with a non-JSON body.Changes to
request():REQUEST_TIMEOUT = 30(seconds) to every API callresp.raise_for_status()before consuming the bodyrequests.exceptions.Timeout→ClickException("… request timed out …")requests.exceptions.HTTPError→ extract GitHubmessagefrom JSON when available, fall back toresp.text{}ClickException("… invalid JSON …")# noqa: S113(no longer needed)Existing Click CLI behavior and error style are preserved.
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A — script-only change
TESTING INSTRUCTIONS
Validation results:
py_compile: passedpytest: 7/7 passedruff check+ruff format --check: passedmypy(script only): passedpre-commit run(all hooks except mypy): all passedADDITIONAL INFORMATION