Skip to content

refactor: migrate from github3.py to PyGithub#532

Merged
jmeridth merged 3 commits into
mainfrom
migrate-github3-to-pygithub
Jul 6, 2026
Merged

refactor: migrate from github3.py to PyGithub#532
jmeridth merged 3 commits into
mainfrom
migrate-github3-to-pygithub

Conversation

@jmeridth

@jmeridth jmeridth commented Jul 4, 2026

Copy link
Copy Markdown
Collaborator

Proposed Changes

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.

What changed

  • auth.py: Rewrote authentication from github3.login/login_as_app_installation to PyGithub's Auth.Token/Auth.AppAuth + get_installation_auth
  • stale_repos.py: Updated all API calls (organization() -> get_organization(), repositories() -> get_repos(), topics().names -> get_topics(), etc.), exception types (NotFoundError -> UnknownObjectException, GitHubException -> GithubException), and dropped dateutil since PyGithub returns datetime objects directly
  • test_auth.py / test_stale_repos.py: Updated mock targets, exception constructors, and pushed_at from ISO strings to datetime objects
  • pyproject.toml: Swapped github3-py for PyGithub>=2.6.0, dropped python-dateutil, types-python-dateutil, and types-requests
  • Linter configs: Updated .mypy.ini and .isort.cfg to reference github instead of github3

Dependencies removed

  • github3-py
  • python-dateutil
  • types-python-dateutil (dev)
  • types-requests (dev)

Dependencies added

  • PyGithub>=2.6.0

Readiness Checklist

Author/Contributor

  • If documentation is needed for this change, has that been included in this pull request
  • run make lint and fix any issues that you have introduced
  • run make test and ensure you have test coverage for the lines you are introducing

Proof 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 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)

## 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>
@jmeridth jmeridth added the Mark Ready When Ready Automatically mark draft PR ready when checks pass label Jul 4, 2026
@jmeridth jmeridth self-assigned this Jul 4, 2026
@github-actions github-actions Bot added the automation automation label Jul 4, 2026
@jmeridth
jmeridth requested a review from Copilot July 4, 2026 20:46
@github-actions
github-actions Bot marked this pull request as ready for review July 4, 2026 20:49
@github-actions
github-actions Bot requested a review from zkoppert as a code owner July 4, 2026 20:49
@github-actions github-actions Bot removed the Mark Ready When Ready Automatically mark draft PR ready when checks pass label Jul 4, 2026

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 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.py API usage with PyGithub equivalents 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.

Comment thread auth.py Outdated
Comment thread test_auth.py Outdated
Comment thread test_auth.py
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 zkoppert 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.

Two small follow-ups plus a consistency thought on the now-dead auth guard. Details inline.

Comment thread auth.py
Comment thread pyproject.toml Outdated
Comment thread auth.py Outdated
- 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>
@jmeridth
jmeridth requested a review from zkoppert July 5, 2026 18:05

@zkoppert zkoppert 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.

🚀

@jmeridth
jmeridth merged commit 1528080 into main Jul 6, 2026
35 checks passed
@jmeridth
jmeridth deleted the migrate-github3-to-pygithub branch July 6, 2026 16:37
@jmeridth jmeridth mentioned this pull request Jul 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants