Skip to content

Commit

Permalink
implement Milestone.fetch_pulls
Browse files Browse the repository at this point in the history
  • Loading branch information
ShineyDev committed Jan 9, 2025
1 parent 34d34a6 commit d7baa4c
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 2 deletions.
20 changes: 20 additions & 0 deletions github/core/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,26 @@ async def collect_milestone_issues(

return await self._collect(query, *path, milestone_id=milestone_id, order_by=order_by_data, **kwargs)

async def collect_milestone_pulls(
self: Self,
/,
milestone_id: str,
order_by: str | None,
*,
fields: Iterable[str] = MISSING,
**kwargs,
) -> ConnectionData[PullData]:
fields = github.utility.get_merged_graphql_fields(github.Pull, fields)
query = "query($after:String,$before:String,$first:Int,$last:Int,$order_by:IssueOrder,$milestone_id:ID!){node(id:$milestone_id){...on Milestone{pullRequests(after:$after,before:$before,first:$first,last:$last,orderBy:$order_by){nodes{%s},pageInfo{endCursor,hasNextPage,hasPreviousPage,startCursor}}}}}" % ",".join(fields)
path = ("node", "pullRequests")

if order_by is None:
order_by_data = None
else:
order_by_data = {"direction": "ASC", "field": order_by}

return await self._collect(query, *path, milestone_id=milestone_id, order_by=order_by_data, **kwargs)

async def collect_organization_mannequins(
self: Self,
/,
Expand Down
53 changes: 51 additions & 2 deletions github/repository/milestone.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
from typing import cast
from typing_extensions import Self

from github.connection import Connection, IssueOrder
from github.connection import Connection, IssueOrder, PullOrder
from github.core.http import HTTPClient
from github.repository import Issue, MilestoneState
from github.repository import Issue, MilestoneState, Pull
from github.utility.types import DateTime

import github
Expand Down Expand Up @@ -458,6 +458,55 @@ def fetch_issues(
**kwargs,
)

def fetch_pulls(
self: Self,
/,
*,
cursor: str | None = MISSING,
limit: int = MISSING,
order_by: PullOrder = MISSING,
reverse: bool = MISSING,
**kwargs, # TODO
) -> Connection[Pull]:
"""
|aiter|
Fetches pull requests in the milestone.
Parameters
----------
cursor: :class:`str`
The cursor to start at.
limit: :class:`int`
The maximum number of elements to yield.
order_by: :class:`~github.PullOrder`
The field by which to order the elements.
reverse: :class:`bool`
Whether to yield the elements in reverse order.
Raises
------
~github.core.errors.ClientObjectMissingFieldError
The :attr:`id` attribute is missing.
:rtype: :class:`~github.Connection`[:class:`~github.Pull`]
"""

return github.Connection(
self._http.collect_milestone_pulls,
self.id,
order_by.value if order_by is not MISSING else None,
data_map=lambda d: github.Pull._from_data(d, http=self._http),
cursor=cursor if cursor is not MISSING else None,
limit=limit if limit is not MISSING else None,
reverse=reverse if reverse is not MISSING else False,
**kwargs,
)


__all__ = [
"Milestone",
Expand Down

0 comments on commit d7baa4c

Please sign in to comment.