fix deprecated GitHub authentication

This commit is contained in:
Wilson Freitas
2026-08-13 05:35:44 -03:00
parent d227860071
commit d170e3ded4
2 changed files with 24 additions and 2 deletions
+2 -2
View File
@@ -18,7 +18,7 @@ from pathlib import Path
from typing import Any, Callable from typing import Any, Callable
from urllib.parse import urlsplit, urlunsplit from urllib.parse import urlsplit, urlunsplit
from github import Github, GithubException from github import Auth, Github, GithubException
ROOT = Path(__file__).resolve().parents[1] ROOT = Path(__file__).resolve().parents[1]
if str(ROOT) not in sys.path: if str(ROOT) not in sys.path:
@@ -605,7 +605,7 @@ def main() -> int:
repository_name = env("GITHUB_REPOSITORY") repository_name = env("GITHUB_REPOSITORY")
if not repository_name: if not repository_name:
return fail("GITHUB_REPOSITORY is required") return fail("GITHUB_REPOSITORY is required")
client = Github(token) client = Github(auth=Auth.Token(token))
findings, title = review_pr(repository_name, pr_number, client) findings, title = review_pr(repository_name, pr_number, client)
except Exception as exc: except Exception as exc:
return fail(str(exc)) return fail(str(exc))
+22
View File
@@ -1,5 +1,6 @@
import io import io
import unittest import unittest
import warnings
from contextlib import redirect_stderr, redirect_stdout from contextlib import redirect_stderr, redirect_stdout
from datetime import datetime, timedelta, timezone from datetime import datetime, timedelta, timezone
from types import SimpleNamespace from types import SimpleNamespace
@@ -788,6 +789,27 @@ class MainTests(unittest.TestCase):
self.assertIn("description: pass", stdout) self.assertIn("description: pass", stdout)
self.assertIn("duplicates: 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): def test_failure_reports_failed_check_and_nonzero_status(self):
finding = Finding("description", "PR body is empty") finding = Finding("description", "PR body is empty")