Skip to content

fix(pygithub): use Auth.Token API for newer PyGithub versions - #36

Closed
YuanYuYuan wants to merge 1 commit into
ros-tooling:mainfrom
YuanYuYuan:fix/pygithub-auth
Closed

YuanYuYuan wants to merge 1 commit into
ros-tooling:mainfrom
YuanYuYuan:fix/pygithub-auth

Conversation

@YuanYuYuan

Copy link
Copy Markdown
Contributor

Summary

The deprecated Github(token) positional argument (login_or_token) no longer authenticates in PyGithub >= 2.0 — it silently fails with a 401. Switch to the explicit Github(auth=Auth.Token(token)) form.

Key Changes

  • ros_github_scripts/ci_for_pr.py: import Auth from github; replace Github(github_access_token) with Github(auth=Auth.Token(github_access_token))

Did you use Generative AI?

Yes. Claude (claude-sonnet-4-6) via Claude Code was used to assist with implementing the changes in this PR.

The deprecated positional login_or_token argument no longer authenticates
in recent PyGithub releases; switch to the explicit Auth.Token form.

Signed-off-by: yuanyuyuan <az6980522@gmail.com>
@YuanYuYuan

Copy link
Copy Markdown
Contributor Author

@christophebedard @emersonknapp, either of you could take a look? Thanks!

@emersonknapp
emersonknapp self-requested a review June 11, 2026 03:13
if not github_access_token:
panic('Neither environment variable GITHUB_ACCESS_TOKEN nor GITHUB_TOKEN are set')
github_instance = Github(github_access_token)
github_instance = Github(auth=Auth.Token(github_access_token))

@christophebedard christophebedard Jun 12, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this won't work if someone is using pygithub < 2.0. For example, my venv currently has 1.56, and I can see that auth= isn't a valid arg for version 1.57: https://pygithub.readthedocs.io/en/v1.57/github.html

I think the solution is to introduce a set of requirements.txt & constraints.txt files to pin the versions. Then we can bump to version 2.0 or whatever

@mergify

mergify Bot commented Aug 24, 2026

Copy link
Copy Markdown

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@YuanYuYuan

Copy link
Copy Markdown
Contributor Author

Closing as superseded.

  • main already uses Github(auth=Auth.Token(...)) in ci_for_pr.py, so this change is no longer needed.
  • @christophebedard's concern about PyGithub < 2.0 is resolved by the uv migration (feat: migrate from setup.py to uv for dependency management #40). pyproject.toml now pins PyGithub>=1.59.1,<2, and uv.lock resolves to 1.59.1. That is the first release with the Auth API, so auth= works on every version that can be installed.
  • The generate_contribution_report.py and find_restarted_ci.py scripts still call Github(token). This works under the current pin. I will open a separate PR if the pin moves to 2.x.

Thanks for the review.

@YuanYuYuan YuanYuYuan closed this Oct 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants