Repository navigation
fix: skip empty repositories instead of crashing - #591
Merged
jmeridth merged 4 commits intoOct 9, 2026
Merged
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. |
Addresses review feedback: the previous change only hardened check_optional_file(), but empty repositories also 404 in dependabot_file.py (repo.get_contents on "/", ".github/workflows", ".devcontainer"), which only catch UnknownObjectException and would still crash the run. Add an is_empty_repo() helper (repo.size == 0) and skip empty repos at the top of the main loop, before any content lookup, so none of the downstream get_contents paths are reached for them. The check_optional_file GithubException handling is kept as a defensive backstop. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Collaborator
|
Appreciate you taking the time to work on a fix for this! |
Collaborator
jmeridth
marked this pull request as draft
August 20, 2026 22:00
## What/Why repo.size is GitHub's cached disk usage, so the size == 0 skip falsely flags repos with commits as empty (e.g. jsplumb/jsplumb) and never enables Dependabot on them. Replace it with a list_contents_or_empty helper that treats a 404 from either UnknownObjectException or the base GithubException as "nothing here", covering the empty-repo case at the three directory lookups in build_dependabot_file. Addresses review feedback from zkoppert and Copilot on PR github-community-projects#591. ## Proof it works New tests cover the helper (contents, missing path, empty repo, non-404 re-raise) and build_dependabot_file on an empty repo returning None. make lint passes (pylint 10.00, mypy clean). make test: 187 passed, 100% coverage. ## Risk Low. Missing-path behavior is unchanged; empty repos now fall through to "no compatible package manager" instead of crashing or being skipped by an unreliable size check. ## AI role Generated by Claude Opus 5.5 from the reviewer's suggested helper; human review pending. ## Review focus - Non-404 GithubExceptions from directory lookups still propagate Signed-off-by: jmeridth <jmeridth@gmail.com>
… into pr-591 Signed-off-by: jmeridth <jmeridth@gmail.com> @ Conflicts: @ dependabot_file.py @ test_dependabot_file.py @ test_exceptions.py
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.