Skip to content

Commit a0ea98f

Browse files
committed
Update githubkit to fix validation error with /gh commit
1 parent 2442dc6 commit a0ea98f

File tree

6 files changed

+14
-74
lines changed

6 files changed

+14
-74
lines changed

bot/src/ghutils/ui/embeds/commits.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
from __future__ import annotations
22

33
import logging
4-
from datetime import datetime
54
from typing import Any
65

76
from discord import Embed
@@ -13,7 +12,6 @@
1312
from ghutils.utils.github import (
1413
CommitCheckState,
1514
RepositoryName,
16-
SmartPaginator,
1715
gh_request,
1816
shorten_sha,
1917
)
@@ -48,7 +46,7 @@ async def create_commit_embed(
4846

4947
if (author := commit.commit.author) and author.date:
5048
try:
51-
embed.timestamp = datetime.fromisoformat(author.date)
49+
embed.timestamp = author.date
5250
except ValueError:
5351
pass
5452

@@ -73,13 +71,12 @@ async def _get_commit_check_state(
7371

7472
# checks
7573
try:
76-
async for suite in SmartPaginator(
74+
async for suite in github.rest.paginate(
7775
github.rest.checks.async_list_suites_for_ref,
76+
map_func=lambda r: r.parsed_data.check_suites,
7877
owner=repo.owner,
7978
repo=repo.repo,
8079
ref=sha,
81-
map_func=lambda resp: resp.parsed_data.check_suites,
82-
limit_func=lambda resp: resp.parsed_data.total_count,
8380
):
8481
match suite.status:
8582
case "queued":

bot/src/ghutils/utils/discord/references.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ async def search_for_autocomplete(
174174
) -> list[tuple[str | int, str]]:
175175
results = await gh_request(
176176
github.rest.search.async_issues_and_pull_requests(
177-
f"{search} is:{self.issue_type} repo:{repo}",
177+
q=f"{search} is:{self.issue_type} repo:{repo}",
178178
per_page=25,
179179
)
180180
)
@@ -264,7 +264,7 @@ async def search_for_autocomplete(
264264
) -> list[tuple[str | int, str]]:
265265
if search:
266266
resp = await github.rest.search.async_commits(
267-
f"{search} repo:{repo}",
267+
q=f"{search} repo:{repo}",
268268
per_page=25,
269269
)
270270
results = resp.parsed_data.items

bot/src/ghutils/utils/discord/transformers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ async def autocomplete( # pyright: ignore[reportIncompatibleMethodOverride]
6666
try:
6767
result = await gh_request(
6868
github.rest.search.async_repos(
69-
query,
69+
q=query,
7070
per_page=25,
7171
)
7272
)
@@ -122,7 +122,7 @@ async def autocomplete( # pyright: ignore[reportIncompatibleMethodOverride]
122122
try:
123123
result = await gh_request(
124124
github.rest.search.async_users(
125-
value,
125+
q=value,
126126
per_page=25,
127127
)
128128
)

bot/src/ghutils/utils/github.py

Lines changed: 3 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,17 @@
44
from dataclasses import dataclass
55
from datetime import datetime
66
from enum import Enum
7-
from typing import Any, Awaitable, Callable, List, Literal, Self, cast, overload
7+
from typing import Any, Awaitable, Literal, Self, overload
88

99
from discord import Color
10-
from githubkit import GitHub, Paginator, Response
10+
from githubkit import GitHub, Response
1111
from githubkit.rest import (
1212
FullRepository,
1313
Issue,
1414
IssuePropPullRequest,
1515
PullRequest,
1616
ReactionRollup,
1717
Release,
18-
Repository,
1918
)
2019

2120

@@ -169,71 +168,13 @@ def from_url(cls, url: str) -> Self:
169168
return cls(owner=match["owner"], repo=match["repo"])
170169

171170
@classmethod
172-
def from_repo(cls, repo: Repository | FullRepository) -> Self:
171+
def from_repo(cls, repo: FullRepository) -> Self:
173172
return cls(owner=repo.owner.login, repo=repo.name)
174173

175174
def __str__(self) -> str:
176175
return f"{self.owner}/{self.repo}"
177176

178177

179-
class SmartPaginator[RT](Paginator[RT]):
180-
"""Subclass of `Paginator` that allows checking the `total_count` field (or similar)
181-
provided in some requests, to avoid making an unnecessary extra request after the
182-
final page.
183-
184-
Only supports async, since this bot only uses async requests.
185-
"""
186-
187-
def __init__[**CP, CT](
188-
self,
189-
request: Callable[CP, Awaitable[Response[CT]]],
190-
map_func: Callable[[Response[CT]], list[RT]],
191-
limit_func: Callable[[Response[CT]], int],
192-
page: int = 1,
193-
per_page: int = 100,
194-
*args: CP.args,
195-
**kwargs: CP.kwargs,
196-
):
197-
super().__init__(
198-
request=request,
199-
map_func=map_func,
200-
page=page,
201-
per_page=per_page,
202-
*args,
203-
**kwargs,
204-
)
205-
206-
self.request = request
207-
self.map_func = map_func
208-
self.limit_func = limit_func
209-
210-
self._limit: int | None = None
211-
self._prev_pages_data_count = 0
212-
213-
async def _aget_next_page(self) -> List[RT]:
214-
if (
215-
self._limit is not None
216-
and self._prev_pages_data_count + self._index >= self._limit
217-
):
218-
return []
219-
220-
self._prev_pages_data_count += len(self._cached_data)
221-
response = cast(
222-
Response[Any],
223-
await self.request(
224-
*self.args,
225-
**self.kwargs,
226-
page=self._current_page, # type: ignore
227-
per_page=self._per_page, # type: ignore
228-
),
229-
)
230-
self._cached_data = self.map_func(response)
231-
self._limit = self.limit_func(response)
232-
self._index = 0
233-
self._current_page += 1
234-
return self._cached_data
235-
236-
237178
async def gh_request[T](future: Awaitable[Response[T]]) -> T:
238179
"""Helper function to simplify extracting the parsed data from GitHub requests."""
239180
resp = await future

requirements-dev.lock

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ aiosignal==1.3.1
2121
annotated-types==0.7.0
2222
# via pydantic
2323
anyio==4.4.0
24+
# via githubkit
2425
# via httpx
2526
# via starlette
2627
# via watchfiles
@@ -93,7 +94,7 @@ fluent-syntax==0.19.0
9394
frozenlist==1.4.1
9495
# via aiohttp
9596
# via aiosignal
96-
githubkit==0.11.8
97+
githubkit==0.13.1
9798
# via ghutils-bot
9899
greenlet==3.0.3 ; (python_full_version < '3.13' and platform_machine == 'AMD64') or (python_full_version < '3.13' and platform_machine == 'WIN32') or (python_full_version < '3.13' and platform_machine == 'aarch64') or (python_full_version < '3.13' and platform_machine == 'amd64') or (python_full_version < '3.13' and platform_machine == 'ppc64le') or (python_full_version < '3.13' and platform_machine == 'win32') or (python_full_version < '3.13' and platform_machine == 'x86_64')
99100
# via sqlalchemy

requirements.lock

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ aiosignal==1.3.1
2121
annotated-types==0.7.0
2222
# via pydantic
2323
anyio==4.4.0
24+
# via githubkit
2425
# via httpx
2526
# via starlette
2627
# via watchfiles
@@ -87,7 +88,7 @@ fluent-syntax==0.19.0
8788
frozenlist==1.4.1
8889
# via aiohttp
8990
# via aiosignal
90-
githubkit==0.11.8
91+
githubkit==0.13.1
9192
# via ghutils-bot
9293
greenlet==3.0.3 ; (python_full_version < '3.13' and platform_machine == 'AMD64') or (python_full_version < '3.13' and platform_machine == 'WIN32') or (python_full_version < '3.13' and platform_machine == 'aarch64') or (python_full_version < '3.13' and platform_machine == 'amd64') or (python_full_version < '3.13' and platform_machine == 'ppc64le') or (python_full_version < '3.13' and platform_machine == 'win32') or (python_full_version < '3.13' and platform_machine == 'x86_64')
9394
# via sqlalchemy

0 commit comments

Comments
 (0)