Skip to content

fix: skip empty repositories instead of crashing - #591

Merged
jmeridth merged 4 commits into
github-community-projects:mainfrom
wjglerum:fix/empty-repo-404
Oct 9, 2026
Merged

jmeridth merged 4 commits into
github-community-projects:mainfrom
wjglerum:fix/empty-repo-404

Conversation

@wjglerum

@wjglerum wjglerum commented Jul 6, 2026 •

Copy link
Copy Markdown
Contributor

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:

github.GithubException.GithubException: This repository is empty.: 404
{"message": "This repository is empty.",
 "documentation_url": "https://docs.github.com/v3/repos/contents/#get-contents",
 "status": "404"}

check_optional_file() in exceptions.py calls repo.get_contents(...) to look for an existing dependabot.yml. For a repo where the file merely does not exist, PyGithub raises UnknownObjectException, which is caught and translated to OptionalFileNotFoundError. But for an empty repository, GitHub returns a 404 that PyGithub surfaces as the base GithubException ("This repository is empty."), not UnknownObjectException. That escapes the existing handler and aborts the whole run, so no other repositories in the org get processed.

Fix

Handle a 404 GithubException the same way as a missing optional file, so the repository is treated as having no config and skipped by the normal flow. Non-404 GithubExceptions (permissions, rate limits, server errors) are re-raised unchanged so genuine problems are not masked.

Tests

Added two cases to test_exceptions.py:

  • an empty-repository 404 (base GithubException) is translated to OptionalFileNotFoundError
  • a non-404 GithubException (e.g. 403) is re-raised unchanged

All existing tests still pass.

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>
@github-actions github-actions Bot added the fix label Jul 6, 2026
@wjglerum
wjglerum marked this pull request as ready for review July 6, 2026 10:37
@jmeridth
jmeridth requested a review from Copilot July 6, 2026 12:27

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 404 GithubException (empty repo case) into OptionalFileNotFoundError.
  • 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 thread exceptions.py
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>
@zkoppert

zkoppert commented Jul 8, 2026

Copy link
Copy Markdown
Collaborator

Appreciate you taking the time to work on a fix for this!

@jmeridth

Copy link
Copy Markdown
Collaborator

@wjglerum please check @zkoppert's comments above. Thank you for your contribution.

@jmeridth
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

@jmeridth jmeridth left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @wjglerum. I pushed the shared list_contents_or_empty helper zkoppert suggested and merged main. CI is green.

@jmeridth
jmeridth marked this pull request as ready for review October 9, 2026 03:00
@jmeridth
jmeridth merged commit 983fbbf into github-community-projects:main Oct 9, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants