Skip to content

Commit 4b2ecd4

Browse files
committed
Upgrade to pygithub 2.8
This commit syncs Meta internal changes. The only significant change is migration from pygithub from 1.59 to 2.8, which changed the authentication API. Other changes are formatting applied automatically by bots. Signed-off-by: Ihor Solodrai <[email protected]>
1 parent 8f39ca1 commit 4b2ecd4

15 files changed

+47
-55
lines changed

kernel_patches_daemon/__main__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
from github.Repository import Repository
2020
from kernel_patches_daemon.config import KPDConfig
2121
from kernel_patches_daemon.daemon import KernelPatchesDaemon
22-
2322
from opentelemetry import metrics
2423
from opentelemetry.sdk.metrics import MeterProvider
2524
from opentelemetry.sdk.metrics.export import (

kernel_patches_daemon/branch_worker.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@
4848
from github.PullRequest import PullRequest
4949
from github.Repository import Repository
5050
from github.WorkflowJob import WorkflowJob
51-
5251
from kernel_patches_daemon.config import (
5352
EmailConfig,
5453
PRCommentsForwardingConfig,
@@ -782,7 +781,7 @@ def update_e2e_test_branch_and_update_pr(
782781

783782
def can_do_sync(self) -> bool:
784783
github_ratelimit = self.git.get_rate_limit()
785-
if github_ratelimit.core.remaining < MIN_REMAINING_GITHUB_TOKENS:
784+
if github_ratelimit.resources.core.remaining < MIN_REMAINING_GITHUB_TOKENS:
786785
return False
787786
return True
788787

kernel_patches_daemon/config.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
# pyre-unsafe
88

99
import json
10-
1110
import logging
1211
import os
1312
import re

kernel_patches_daemon/github_connector.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
TOKEN_REFRESH_THRESHOLD_TIMEDELTA = timedelta(
3838
seconds=ACCESS_TOKEN_REFRESH_THRESHOLD_SECONDS
3939
)
40-
assert hasattr(
41-
Auth, "TOKEN_REFRESH_THRESHOLD_TIMEDELTA"
42-
), "Could not monkey patch TOKEN_REFRESH_THRESHOLD_TIMEDELTA, it may have changed upstream."
40+
assert hasattr(Auth, "TOKEN_REFRESH_THRESHOLD_TIMEDELTA"), (
41+
"Could not monkey patch TOKEN_REFRESH_THRESHOLD_TIMEDELTA, it may have changed upstream."
42+
)
4343
Auth.TOKEN_REFRESH_THRESHOLD_TIMEDELTA = TOKEN_REFRESH_THRESHOLD_TIMEDELTA
4444

4545
BOT_USER_LOGIN_SUFFIX = "[bot]"
@@ -65,9 +65,9 @@ def __init__(
6565
app_auth: Optional[Auth.AppInstallationAuth] = None,
6666
http_retries: Optional[int] = None,
6767
) -> None:
68-
assert bool(github_oauth_token) ^ bool(
69-
app_auth
70-
), "Only one of github_oauth_token or app_auth can be set"
68+
assert bool(github_oauth_token) ^ bool(app_auth), (
69+
"Only one of github_oauth_token or app_auth can be set"
70+
)
7171
self.repo_name: str = os.path.basename(repo_url)
7272
self.base_repo_url: str = repo_url
7373
self.auth_type = AuthType.UNKNOWN
@@ -89,12 +89,9 @@ def __init__(
8989
self.github_account_name = gh_user.login
9090
else:
9191
self.auth_type = AuthType.APP_AUTH
92+
# In PyGithub 2.x, AppInstallationAuth stores the AppAuth object in _app_auth
9293
# pyrefly: ignore # missing-attribute
93-
app = GithubIntegration(
94-
auth=Auth.AppAuth(
95-
app_id=app_auth.app_id, private_key=app_auth.private_key
96-
)
97-
).get_app()
94+
app = GithubIntegration(auth=app_auth._app_auth).get_app()
9895
self.github_account_name = app.name
9996
# Github appends '[bot]' suffix to the NamedUser
10097
# >>> pull.user
@@ -138,9 +135,9 @@ def __init__(
138135
self.user_or_org = org
139136
self.repo = self.git.get_organization(org).get_repo(self.repo_name)
140137

141-
assert (
142-
self.auth_type != AuthType.UNKNOWN
143-
), "Auth type is still set to unknown... something is wrong."
138+
assert self.auth_type != AuthType.UNKNOWN, (
139+
"Auth type is still set to unknown... something is wrong."
140+
)
144141

145142
def __get_new_auth_token(self) -> str:
146143
# refresh token if needed

kernel_patches_daemon/github_logs.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
import aiohttp
1717
from github.WorkflowJob import WorkflowJob
18-
1918
from kernel_patches_daemon.status import gh_conclusion_to_status, Status
2019

2120
logger: logging.Logger = logging.getLogger(__name__)

kernel_patches_daemon/github_sync.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
DefaultGithubLogExtractor,
2929
GithubLogExtractor,
3030
)
31-
3231
from kernel_patches_daemon.patchwork import Patchwork, Series, Subject
3332
from kernel_patches_daemon.stats import HistogramMetricTimer, Stats
3433
from opentelemetry import metrics
@@ -387,7 +386,7 @@ async def sync_patches(self) -> None:
387386

388387
rate_limit = worker.git.get_rate_limit()
389388
github_ratelimit_remaining.record(
390-
rate_limit.core.remaining,
389+
rate_limit.resources.core.remaining,
391390
{"user": worker.github_account_name},
392391
)
393392

kernel_patches_daemon/patchwork.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,12 @@
1818

1919
import aiohttp
2020
import cachetools.keys
21-
2221
import dateutil.parser as dateparser
2322
from aiohttp_retry import ExponentialRetry, RetryClient
2423
from cachetools import TTLCache
25-
2624
from kernel_patches_daemon.config import SERIES_ID_SEPARATOR
2725
from kernel_patches_daemon.status import Status
2826
from multidict import MultiDict
29-
3027
from opentelemetry import metrics
3128
from pyre_extensions import none_throws
3229

pyproject.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ classifiers = [
1616
"Typing :: Typed",
1717
"Topic :: Utilities",
1818
]
19-
2019
[tool.poetry.dependencies]
2120
aiohttp = "^3.8"
2221
aiohttp-retry = "^2.8"
@@ -26,7 +25,7 @@ python = "^3.10"
2625
cachetools = "^5.3.0"
2726
gitpython = "^3.1"
2827
opentelemetry-api = "^1.18.0"
29-
pygithub = "^1.59.0"
28+
pygithub = "^2.8.1"
3029
pyre-extensions = "^0.0.30"
3130
opentelemetry-sdk = "^1.18.0"
3231
python-dateutil = "^2.8.2"

tests/common/patchwork_mock.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,9 @@
77
# pyre-unsafe
88

99
import re
10-
1110
from typing import Any, Dict, Final
1211

1312
from aioresponses import aioresponses
14-
1513
from kernel_patches_daemon.patchwork import (
1614
IRRELEVANT_STATES,
1715
Patchwork,

tests/test_branch_worker.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222
from unittest.mock import AsyncMock, MagicMock, patch
2323

2424
import git
25-
2625
from aioresponses import aioresponses
27-
2826
from freezegun import freeze_time
2927
from git.exc import GitCommandError
3028
from kernel_patches_daemon.branch_worker import (
@@ -58,14 +56,12 @@
5856
from kernel_patches_daemon.patchwork import Series, Subject
5957
from kernel_patches_daemon.status import Status
6058
from munch import Munch, munchify
61-
6259
from tests.common.patchwork_mock import (
6360
DEFAULT_TEST_RESPONSES,
6461
get_default_pw_client,
6562
init_pw_responses,
6663
PatchworkMock,
6764
)
68-
6965
from tests.common.utils import load_test_data, read_fixture, read_test_data_file
7066

7167

@@ -1097,7 +1093,7 @@ def setUp(self):
10971093
self.repo.create_head("two_commit_change", commit="master").checkout()
10981094
for i in range(2):
10991095
with open(f"{self.tmp_dir}/file.txt", "a") as f:
1100-
f.write(f"line {i+1}\n")
1096+
f.write(f"line {i + 1}\n")
11011097
self.repo.index.add(["file.txt"])
11021098
self.repo.index.commit("split change, part {i+1}\n")
11031099

@@ -1107,7 +1103,7 @@ def setUp(self):
11071103
).checkout()
11081104
for i in range(2):
11091105
with open(f"{self.tmp_dir}/file.txt", "a") as f:
1110-
f.write(f"line {i+1}\n")
1106+
f.write(f"line {i + 1}\n")
11111107
self.repo.index.add(["file.txt"])
11121108
self.repo.index.commit(self.SINGLE_COMMIT_CHANGE_MESSAGE)
11131109

0 commit comments

Comments
 (0)