refactor: migrate from github3.py to PyGithub#532
Merged
Conversation
## What/Why Replace github3.py with PyGithub to align with the other OSPO repos (cleanowners, measure-innersource, pr-conflict-detector, evergreen) that have already completed this migration. ## Proof it works 53 tests pass with 100% coverage. All pre-commit hooks pass (flake8, isort, pylint, mypy, black, gitleaks, end-of-file-fixer). ## Risk + AI role Low -- direct library swap with identical behavior, no new features. All code AI-generated (Claude Opus 4.6), guided by 4 reference PRs from sibling repos. ## Review focus - Auth patterns in auth.py (AppAuth/Token vs login_as_app_installation) - datetime handling in stale_repos.py (PyGithub returns datetime objects directly, so dateutil was dropped) Signed-off-by: jmeridth <jmeridth@gmail.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR migrates the action’s GitHub API integration from github3.py to PyGithub, updating authentication, repository queries, and exception handling to match the newer client library while keeping existing behavior and test coverage.
Changes:
- Replaced
github3.pyAPI usage withPyGithubequivalents across auth + stale-repo discovery logic. - Updated unit tests and mocks to reflect PyGithub return types (notably
datetime) and method names. - Updated dependencies/lockfile and type-checker/import-sorting configs for the new package.
Reviewed changes
Copilot reviewed 7 out of 10 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
auth.py |
Swaps auth implementation to PyGithub (Auth.Token / Auth.AppAuth + installation auth). |
stale_repos.py |
Updates org/user repo listing, topics, releases/PRs, and exception handling for PyGithub. |
test_auth.py |
Adjusts patches and assertions for the new auth flow and constructors. |
test_stale_repos.py |
Updates mocks to PyGithub method names/iterables and datetime-based fields. |
pyproject.toml |
Replaces github3-py with PyGithub>=2.6.0 and removes dateutil-related deps. |
uv.lock |
Reflects dependency graph changes for PyGithub and removed packages. |
.github/linters/.mypy.ini |
Updates ignore section from github3.* to github.*. |
.github/linters/.isort.cfg |
Updates import categorization for the new module names. |
.pylintrc |
Minor formatting tweak in linter config. |
.coveragerc |
Minor formatting tweak in coverage config. |
Update ghe parameter type to str | None in auth_to_github to match EnvVars.ghe. Use None instead of empty strings for int | None parameters in test_auth.py to match the function signature. Signed-off-by: jmeridth <jmeridth@gmail.com>
zkoppert
reviewed
Jul 5, 2026
zkoppert
left a comment
Collaborator
There was a problem hiding this comment.
Two small follow-ups plus a consistency thought on the now-dead auth guard. Details inline.
- Update ghe docstring to match widened str | None type - Pin PyGithub to ==2.9.1 for consistency with other deps - Remove dead github_connection None guard and its test Signed-off-by: jmeridth <jmeridth@gmail.com>
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.
Proposed Changes
Replace
github3.pywithPyGithubto align with the other OSPO repos (cleanowners, measure-innersource, pr-conflict-detector, evergreen) that have already completed this migration.What changed
github3.login/login_as_app_installationto PyGithub'sAuth.Token/Auth.AppAuth+get_installation_authorganization()->get_organization(),repositories()->get_repos(),topics().names->get_topics(), etc.), exception types (NotFoundError->UnknownObjectException,GitHubException->GithubException), and droppeddateutilsince PyGithub returnsdatetimeobjects directlypushed_atfrom ISO strings todatetimeobjectsgithub3-pyforPyGithub>=2.6.0, droppedpython-dateutil,types-python-dateutil, andtypes-requests.mypy.iniand.isort.cfgto referencegithubinstead ofgithub3Dependencies removed
github3-pypython-dateutiltypes-python-dateutil(dev)types-requests(dev)Dependencies added
PyGithub>=2.6.0Readiness Checklist
Author/Contributor
make lintand fix any issues that you have introducedmake testand ensure you have test coverage for the lines you are introducingProof it works
53 tests pass with 100% coverage. All pre-commit hooks pass.
Risk + AI role
Low -- direct library swap with identical behavior, no new features.
Review focus
auth.py(AppAuth/Token vs login_as_app_installation)stale_repos.py(PyGithub returns datetime objects directly, so dateutil was dropped)