Skip to content

refactor: port from github3.py to PyGithub#434

Merged
jmeridth merged 3 commits into
mainfrom
port-github3-to-pygithub
Jul 4, 2026
Merged

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

Conversation

@jmeridth

@jmeridth jmeridth commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Proposed Changes

Port from github3.py to PyGithub for GitHub API interactions, aligning this repo with the same library used across other community projects (pr-conflict-detector, measure-innersource).

What/Why

github3.py is being replaced with PyGithub across OSPO projects for consistency. PyGithub handles retry/timeout internally, removing the need for the requests dependency.

Proof it works

73 tests pass with 100% coverage.

Risk + AI role

Low -- 1:1 API migration with no behavioral changes. AI-assisted (Claude Opus 4.6) with human review.

Review focus

  • Auth flow in auth.py -- App auth now uses Auth.AppAuth + get_installation_auth instead of login_as_app_installation
  • Large file blob handling in cleanowners.py -- base64 decode path via get_git_blob

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

## What/Why

Replace github3.py with PyGithub for GitHub API interactions, aligning
this repo with the same library used across other OSPO projects
(pr-conflict-detector, measure-innersource).

## Proof it works

73 tests pass with 100% coverage. Pylint 10.00/10, mypy clean, flake8
clean, black formatted, isort clean.

## Risk + AI role

Low -- 1:1 API migration with no behavioral changes. All code
AI-generated (Claude Opus 4.6) with human review.

## Review focus

- Auth flow changes in auth.py (App auth now uses Auth.AppAuth +
  get_installation_auth instead of login_as_app_installation)
- Large file blob handling in cleanowners.py (base64 decode path)

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

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

Multi-model review of the github3 to PyGithub migration below (Opus, GPT-5.3-Codex, GPT-5.4, all findings verified in the repo venv). Two verified Highs where the PyGithub object types differ from github3: has_in_members needs a NamedUser rather than a login string, and the large-file content is None guard never fires. I also flagged the exception-scope broadening in the read paths. Details inline.

Comment thread cleanowners.py Outdated
Comment thread cleanowners.py Outdated
Comment thread cleanowners.py Outdated
Comment thread cleanowners.py Outdated
Comment thread cleanowners.py Outdated
- Resolve username to NamedUser before has_in_members() call
- Fix large file detection: check encoding=="none" instead of content is None
- Narrow except clauses to UnknownObjectException for 404-only semantics
- Log exception status/data in PR-creation error messages
- Fix import order (third-party before first-party)

Signed-off-by: jmeridth <jmeridth@gmail.com>
@jmeridth
jmeridth requested a review from zkoppert July 3, 2026 01:09
Comment thread cleanowners.py Outdated

Copilot AI left a comment

Copy link
Copy Markdown

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 GitHub API usage from github3.py to PyGithub to align this action with other OSPO/community projects, updating authentication, repository/file operations, and test mocks accordingly.

Changes:

  • Swap runtime dependency from github3-py to PyGithub and adjust lockfile/dev-deps.
  • Update GitHub API calls in cleanowners.py (org lookup, repo iteration, content updates, large-file blob handling, membership checks).
  • Refactor auth flow in auth.py to use Auth.Token and Auth.AppAuth + installation auth; update tests and mypy ignore rules for github.*.
Show a summary per file
File Description
uv.lock Replaces github3-py with pygithub and updates the resolved dependency graph.
pyproject.toml Updates declared dependencies to use PyGithub instead of github3-py (and removes some direct pins/dev deps).
cleanowners.py Ports GitHub API interactions to PyGithub equivalents (refs, contents, blobs, membership checks, exceptions).
auth.py Reimplements PAT/App authentication using PyGithub Auth helpers and Github client initialization.
test_auth.py Updates unit tests to patch PyGithub classes and validate new auth construction behavior.
test_cleanowners.py Updates mocks/expectations for PyGithub repo/org/content APIs and exception types.
.github/linters/.mypy.ini Adjusts mypy ignore rule from github3.* to github.*.

Review details

  • Files reviewed: 6/7 changed files
  • Comments generated: 8
  • Review effort level: Low

Comment thread cleanowners.py Outdated
Comment thread auth.py
Comment thread auth.py
Comment thread test_auth.py
Comment thread test_auth.py
Comment thread test_auth.py
Comment thread test_auth.py
Comment thread test_auth.py
- Wrap get_user() + has_in_members() in try/except for deleted accounts
- Strip trailing slash from GHE URL to prevent double slashes
- Fix test_auth.py type mismatches: use None/int instead of empty strings

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.

🚀

@jmeridth
jmeridth merged commit 691d96b into main Jul 4, 2026
39 checks passed
@jmeridth
jmeridth deleted the port-github3-to-pygithub branch July 4, 2026 20:25
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.

3 participants