From d170e3ded434cc17274180d8bb505f68fabd9474 Mon Sep 17 00:00:00 2001 From: Wilson Freitas Date: Thu, 13 Aug 2026 05:35:35 -0300 Subject: [PATCH] fix deprecated GitHub authentication --- scripts/review_pr.py | 4 ++-- tests/test_review_pr.py | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/scripts/review_pr.py b/scripts/review_pr.py index 47ab10e..17ed486 100644 --- a/scripts/review_pr.py +++ b/scripts/review_pr.py @@ -18,7 +18,7 @@ from pathlib import Path from typing import Any, Callable from urllib.parse import urlsplit, urlunsplit -from github import Github, GithubException +from github import Auth, Github, GithubException ROOT = Path(__file__).resolve().parents[1] if str(ROOT) not in sys.path: @@ -605,7 +605,7 @@ def main() -> int: repository_name = env("GITHUB_REPOSITORY") if not repository_name: return fail("GITHUB_REPOSITORY is required") - client = Github(token) + client = Github(auth=Auth.Token(token)) findings, title = review_pr(repository_name, pr_number, client) except Exception as exc: return fail(str(exc)) diff --git a/tests/test_review_pr.py b/tests/test_review_pr.py index 7321406..43357b0 100644 --- a/tests/test_review_pr.py +++ b/tests/test_review_pr.py @@ -1,5 +1,6 @@ import io import unittest +import warnings from contextlib import redirect_stderr, redirect_stdout from datetime import datetime, timedelta, timezone from types import SimpleNamespace @@ -788,6 +789,27 @@ class MainTests(unittest.TestCase): self.assertIn("description: pass", stdout) self.assertIn("duplicates: pass", stdout) + def test_authentication_does_not_emit_a_deprecation_warning(self): + stdout = io.StringIO() + stderr = io.StringIO() + environment = { + "GITHUB_TOKEN": "token", + "GITHUB_REPOSITORY": "owner/list", + "PR_NUMBER": "10", + } + with ( + patch.dict("os.environ", environment, clear=True), + patch("sys.argv", ["review_pr.py"]), + patch("scripts.review_pr.review_pr", return_value=([], "Add Fresh")), + redirect_stdout(stdout), + redirect_stderr(stderr), + warnings.catch_warnings(), + ): + warnings.simplefilter("error", DeprecationWarning) + result = main() + + self.assertEqual(result, 0) + def test_failure_reports_failed_check_and_nonzero_status(self): finding = Finding("description", "PR body is empty")