Skip to content

Commit

Permalink
implement Client.fetch_advisories
Browse files Browse the repository at this point in the history
  • Loading branch information
ShineyDev committed Jan 19, 2025
1 parent 8513561 commit 1354122
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 2 deletions.
52 changes: 50 additions & 2 deletions github/core/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
from aiohttp import ClientSession

from github.api import Metadata, RateLimit
from github.connection import Connection, VulnerabilityOrder
from github.connection import AdvisoryOrder, Connection, VulnerabilityOrder
from github.content import CodeOfConduct, License
from github.organization import Organization
from github.repository import Repository, Topic
from github.security import Vulnerability
from github.security import Advisory, Vulnerability
from github.user import AuthenticatedUser, User, UserStatus
from github.utility.types import DateTime, T_json_object

Expand Down Expand Up @@ -499,6 +499,54 @@ async def fetch_viewer(
data = await self._http.fetch_query_viewer(**kwargs)
return github.AuthenticatedUser._from_data(data, http=self._http)

def fetch_advisories(
self: Self,
/,
*,
cursor: str | None = MISSING,
limit: int = MISSING,
order_by: AdvisoryOrder = MISSING,
reverse: bool = MISSING,
**kwargs, # TODO
) -> Connection[Advisory]:
"""
|aiter|
Fetches security advisories.
Parameters
----------
cursor: :class:`str`
The cursor to start at.
limit: :class:`int`
The maximum number of elements to yield.
order_by: :class:`~github.AdvisoryOrder`
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.Advisory`]
"""

return github.Connection(
self._http.collect_query_advisories,
order_by.value if order_by is not MISSING else None,
data_map=lambda d: github.Advisory._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,
)

def fetch_vulnerabilities(
self: Self,
/,
Expand Down
20 changes: 20 additions & 0 deletions github/core/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
from github.repository.pull import PullData
from github.repository.repository import RepositoryData
from github.repository.topic import TopicData
from github.security.advisory import AdvisoryData
from github.security.vulnerability import VulnerabilityData
from github.user import User, UserStatus
from github.user.user import UserData, ViewerData
Expand Down Expand Up @@ -1252,6 +1253,25 @@ async def collect_pull_participants(

return await self._collect(query, *path, pull_id=pull_id, **kwargs)

async def collect_query_advisories(
self: Self,
/,
order_by: str | None,
*,
fields: Iterable[str] = MISSING,
**kwargs,
) -> ConnectionData[AdvisoryData]:
fields = github.utility.get_merged_graphql_fields(github.Advisory, fields)
query = "query($after:String,$before:String,$first:Int,$last:Int,$order_by:SecurityAdvisoryOrder){securityAdvisories(after:$after,before:$before,first:$first,last:$last,orderBy:$order_by){nodes{%s},pageInfo{endCursor,hasNextPage,hasPreviousPage,startCursor}}}" % ",".join(fields)
path = ("securityAdvisories",)

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

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

async def collect_query_vulnerabilities(
self: Self,
/,
Expand Down

0 comments on commit 1354122

Please sign in to comment.