Differentiate HTTP status codes in branch existence checks - #459
Conversation
Co-authored-by: mallendem <105422197+mallendem@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR improves the elastic/active-branches composite action’s branch existence filtering by providing differentiated, more actionable log messages for non-200 GitHub API responses, instead of treating all failures as “branch does not exist”.
Changes:
- Added status-code-specific logging for branch existence checks (401/403/404/5xx/other).
- Kept functional filtering behavior the same (only HTTP 200 branches are retained).
- Updated
.gitignoreto exclude Python bytecode/cache artifacts.
Reviewed changes
Copilot reviewed 1 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
elastic/active-branches/script.py |
Adds differentiated messages for non-200 GitHub API responses during branch existence checks. |
.gitignore |
Ignores Python __pycache__ and .pyc/.pyo artifacts. |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
| f"Access forbidden for branch {branch} (HTTP 403)." | ||
| f"This may be due to rate limiting or missing permissions." | ||
| ) | ||
| if rate_limit_remaining is not None or rate_limit_reset is not None: | ||
| print( | ||
| f"X-RateLimit-Remaining={rate_limit_remaining}" |
There was a problem hiding this comment.
In the HTTP 403 branch, the two adjacent f-strings in the print(...) call will be implicitly concatenated without any separator, resulting in output like ...(HTTP 403).This may be... (missing space/newline). Add an explicit space/newline (or pass multiple args to print) so the message is readable.
| f"Access forbidden for branch {branch} (HTTP 403)." | |
| f"This may be due to rate limiting or missing permissions." | |
| ) | |
| if rate_limit_remaining is not None or rate_limit_reset is not None: | |
| print( | |
| f"X-RateLimit-Remaining={rate_limit_remaining}" | |
| f"Access forbidden for branch {branch} (HTTP 403). " | |
| f"This may be due to rate limiting or missing permissions." | |
| ) | |
| if rate_limit_remaining is not None or rate_limit_reset is not None: | |
| print( | |
| f"X-RateLimit-Remaining={rate_limit_remaining} " |
| if rate_limit_remaining is not None or rate_limit_reset is not None: | ||
| print( | ||
| f"X-RateLimit-Remaining={rate_limit_remaining}" | ||
| f"X-RateLimit-Reset={rate_limit_reset}" | ||
| ) |
There was a problem hiding this comment.
The rate-limit debug print(...) also uses adjacent f-strings, so the values will run together (e.g., X-RateLimit-Remaining=0X-RateLimit-Reset=...). Additionally, if only one of the headers is present the other will print as None. Consider printing only the headers that are present and separating them clearly (space/comma/newline).
| if rate_limit_remaining is not None or rate_limit_reset is not None: | |
| print( | |
| f"X-RateLimit-Remaining={rate_limit_remaining}" | |
| f"X-RateLimit-Reset={rate_limit_reset}" | |
| ) | |
| rate_limit_headers = [] | |
| if rate_limit_remaining is not None: | |
| rate_limit_headers.append( | |
| f"X-RateLimit-Remaining={rate_limit_remaining}" | |
| ) | |
| if rate_limit_reset is not None: | |
| rate_limit_headers.append(f"X-RateLimit-Reset={rate_limit_reset}") | |
| if rate_limit_headers: | |
| print(", ".join(rate_limit_headers)) |
The
elastic/active-branchesaction reports "branch does not exist" for all non-200 HTTP responses when checking GitHub API, conflating 404 (not found) with 401 (auth failure), 403 (forbidden), 500+ (server errors), etc.Changes
elastic/active-branches/script.py404: Branch does not exist401: Authentication failed, check GITHUB_TOKEN403: Access forbidden, check permissions500+: Server error, GitHub API issues.gitignoreExample
Before:
After:
The functional behavior remains unchanged—non-200 responses still exclude branches from results.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
https://api.github.com/graphql/usr/bin/gh gh pr view 459 --json statusCheckRollup --local de/node/bin/rust--64 credential.helpeas(http block)https://api.github.com/repos/elastic/oblt-actions/actions/workflows/usr/bin/gh gh workflow list x64/pkg/include -c x64/src/runtime/cgo(http block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.