fix: skip empty repositories instead of crashing#591
Open
wjglerum wants to merge 1 commit into
Open
Conversation
check_optional_file() only caught UnknownObjectException, but an empty
repository (one with no commits) returns a 404 that PyGithub raises as
the base GithubException ("This repository is empty."). That escaped the
handler and crashed the whole run when iterating an organization that
contains a freshly-created, never-pushed repo.
Handle a 404 GithubException the same way as a missing optional file so
the repository is skipped. Non-404 GithubExceptions are re-raised
unchanged. Adds tests for both cases.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves robustness when scanning GitHub organizations by preventing Evergreen from crashing on empty repositories (repositories with no commits) when checking for optional configuration files via PyGithub.
Changes:
- Extend
check_optional_file()to translate 404GithubException(empty repo case) intoOptionalFileNotFoundError. - Add unit tests covering the empty-repository 404 translation and ensuring non-404
GithubExceptions are still re-raised.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
exceptions.py |
Adds handling for base GithubException 404s (empty repos) to match existing optional-file behavior. |
test_exceptions.py |
Adds test coverage for empty-repository 404 behavior and non-404 re-raise behavior. |
Comment on lines
+50
to
+58
| except GithubException as e: | ||
| # An empty repository (one with no commits) returns a 404 that PyGithub | ||
| # raises as the base GithubException ("This repository is empty.") | ||
| # rather than UnknownObjectException. Treat it the same as a missing | ||
| # optional file so the repository is skipped instead of crashing the run. | ||
| if e.status == 404: | ||
| raise OptionalFileNotFoundError( | ||
| status=e.status, data=e.data, headers=e.headers | ||
| ) from e |
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.
Problem
When Evergreen iterates over an organization that contains an empty repository (one created but never pushed to, so it has no commits), the run crashes:
check_optional_file()inexceptions.pycallsrepo.get_contents(...)to look for an existingdependabot.yml. For a repo where the file merely does not exist, PyGithub raisesUnknownObjectException, which is caught and translated toOptionalFileNotFoundError. But for an empty repository, GitHub returns a 404 that PyGithub surfaces as the baseGithubException("This repository is empty."), notUnknownObjectException. That escapes the existing handler and aborts the whole run, so no other repositories in the org get processed.Fix
Handle a 404
GithubExceptionthe same way as a missing optional file, so the repository is treated as having no config and skipped by the normal flow. Non-404GithubExceptions (permissions, rate limits, server errors) are re-raised unchanged so genuine problems are not masked.Tests
Added two cases to
test_exceptions.py:GithubException) is translated toOptionalFileNotFoundErrorGithubException(e.g. 403) is re-raised unchangedAll existing tests still pass.