mirror of
https://github.com/wilsonfreitas/awesome-quant.git
synced 2026-08-23 16:58:06 +00:00
fix deprecated GitHub authentication
This commit is contained in:
@@ -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))
|
||||||
|
|||||||
@@ -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")
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user