Repository navigation
chore(github): upgrade PyGithub to 2.x and migrate off deprecated auth classes - #3240
Conversation
…h classes Moves the PyGithub pin from ==1.59.* to >=2.10,<3 and migrates the two call sites (plus the import) that used APIs deprecated since 1.59: - GithubIntegration(integration_id=..., private_key=...) -> the app-JWT path now passes auth=Auth.AppAuth(...), which also feeds GET /app for the bot slug. - AppAuthentication(app_id=..., private_key=..., installation_id=...) -> the installation-token path now uses Auth.AppInstallationAuth wrapping an Auth.AppAuth, so provider.auth._app_auth stays the wrapped AppAuth that tests rely on for JWT creation. Deprecation cleanup ahead of PyGithub 3.x rather than a fix for anything currently broken; the GitHub App unit coverage passes with no github-module DeprecationWarnings and the full unit suite is unchanged (4450 passed). Refs: The-PR-Agent#3193
IsmaelMartinez
left a comment
There was a problem hiding this comment.
The new auth path holds up against real PyGithub 2.10.0, so this is close. One ask here, two inline.
Nothing asserts the new auth= kwarg. The GithubIntegration stubs in test_review_persistent_comment_authorship.py, at lines 371 and 393, are def integration(**kwargs), so they pass either way: I reverted the call site to the old integration_id= form and all twelve tests in that file stayed green. Capturing and asserting the kwarg would pin the migration.
Pin the PyGithub 2.x migration in the unit tests the review asked for and make the 2.x pacing and retry defaults an explicit, configurable choice so the upgrade stays behaviour-neutral against the 1.59 baseline.
|
Pushed 291c8f9 addressing the review:
Full unit suite: 4452 passed, 1 skipped, 1 xfailed (4450 on main plus the two new tests). |
IsmaelMartinez
left a comment
There was a problem hiding this comment.
Thanks for pinning the auth kwarg in the stubs rather than only changing the call site. Approving.
Reverting the call site to integration_id= now turns two of the twelve tests in that file red, where all twelve stayed green before, so the migration is held in place.
On pacing I re-measured against real PyGithub 2.10.0: stock defaults come out at 0.25s, 1.0s and GithubRetry(total=10), and the client this branch builds comes out at 0, 0 and None. Neutral against 1.59, with the opt-in documented in the section. Worth naming what the zero default gives up: retry=None declines 2.x's secondary rate limit backoff on writes, and pr-agent only retries _get_diff_files.
Suite 4458 against a 4456 baseline on today's main.
The generated page now carries the three [github] pacing keys added in The-PR-Agent#3240 and the two comment corrections from this branch, and the key-count guard moves from 292 to 295 to match. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
PyGithub 2.x adds a "url" string to every GET dict, so get_languages() on GitHub carried a value that sort_files_by_main_languages and get_main_pr_language could not rank, and every /describe, /review and /improve on GitHub failed since The-PR-Agent#3240. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01J7XRE8KVG5XdDd2PNwwy42 (cherry picked from commit 2edacb7fa04d440c47ca764b1c77e51fd22c08d7)
Description
Implements #3193: moves the PyGithub pin from
==1.59.*to>=2.10,<3and migrates the two call sites (plus the import) that use APIs PyGithub deprecated back in the 1.59 era.pr_agent/git_providers/github_provider.py:14drops theAppAuthenticationimport (no longer referenced after the migration).GithubIntegration(integration_id=..., private_key=..., base_url=...)now passesauth=Auth.AppAuth(app_id=..., private_key=...)on the app-JWT path, withbase_urlunchanged.AppAuthentication(app_id=..., private_key=..., installation_id=...)now usesAuth.AppInstallationAuth(Auth.AppAuth(...), installation_id=...)on the installation-token path, soprovider.auth._app_authstays the wrappedAppAuththattest_github_app_auth.pyrelies on for JWT creation.PyGithub>=2.10,<3; the lockfile diff is limited to the PyGithub version/hashes.DeprecationWarningfrom the app-auth path.GithubIntegrationstubs intest_review_persistent_comment_authorship.pynow capture and assert that the newauthkwarg is anAuth.AppAuth, so the migration cannot silently regress to the deprecated constructor.[github]settings now mirror the 1.59 behaviour (seconds_between_requests = 0,seconds_between_writes = 0,api_retries = 0) and_get_github_clientpasses them to theGithub(...)constructor explicitly, so the upgrade stays behaviour neutral unless an operator opts in. The app-auth docstring intest_github_app_auth.pyand thestr()comment in the provider were refreshed to match 2.x behaviour: PyGithub#3272 landed in 2.7.0, so the cast is now a harmless guarantee rather than the load-bearing requirement it was on 1.59.Why this is the right replacement shape
The
Auth.AppAuthswap alone would be correct at theGithubIntegrationsite (the app JWT needed forGET /app), but the deployment path issues an installation-scoped token, so it needsAuth.AppInstallationAuthwrappingAuth.AppAuth.Auth.AppAuthalone would not work there, a correction to the issue's original suggestion.Verification
tests/unittest/test_github_app_auth.py,tests/unittest/test_review_persistent_comment_authorship.pyandtests/unittest/test_github_provider_import.pypass on the 2.10.0 pin.-W error::DeprecationWarning:githubproduces no github-module deprecation warnings, confirming the old auth path is gone from our call sites.closes #3193