Skip to content

Commit dc3c698

Browse files
authoredDec 4, 2022
Enhance client arguments and description (#160)
* Enhance client arguments and description * remove unused import
1 parent 1f9d778 commit dc3c698

File tree

4 files changed

+85
-16
lines changed

4 files changed

+85
-16
lines changed
 

‎aiogithubapi/client.py

+38-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from __future__ import annotations
33

44
import asyncio
5-
import json
65
from typing import Any, Dict
76

87
import aiohttp
@@ -65,7 +64,15 @@ def __init__(
6564
api_version: str | None = None,
6665
**kwargs: Dict[GitHubClientKwarg, Any],
6766
) -> None:
68-
"""Initialise the GitHub API client."""
67+
"""
68+
Initialise the GitHub API client.
69+
70+
**Arguments:**
71+
`session`: The aiohttp client session to use for making requests.
72+
`token`: The GitHub access token to use for authenticating requests. Can be a string or None.
73+
`api_version`: The version of the GitHub API to use. Can be a string or None.
74+
75+
"""
6976
self._base_request_data = GitHubBaseRequestDataModel(
7077
token=token,
7178
api_version=api_version,
@@ -79,16 +86,40 @@ async def async_call_api(
7986
endpoint: str,
8087
*,
8188
data: Dict[str, Any] | str | None = None,
89+
headers: Dict[str, Any] | None = None,
90+
method: HttpMethod = HttpMethod.GET,
91+
params: Dict[str, Any] | None = None,
92+
timeout: int | None = None,
8293
**kwargs: Dict[GitHubRequestKwarg, Any],
8394
) -> GitHubResponseModel:
84-
"""Execute the API call."""
95+
"""
96+
Makes an HTTP request to the specified endpoint using the specified parameters.
97+
98+
This method is asynchronous, meaning that it will not block the execution of the program while the request is being made and processed.
99+
100+
**Arguments**:
101+
102+
- `endpoint` (Required): The API endpoint to call.
103+
104+
**Optional arguments**:
105+
- `endpoint`: The API endpoint to call.
106+
- `data`: The data to include in the request body. Can be a dictionary, a string, or None.
107+
- `headers`: The headers to include in the request. Can be a dictionary or None.
108+
- `method`: The HTTP method to use for the request. Defaults to GET.
109+
- `params`: The query parameters to include in the request. Can be a dictionary or None.
110+
- `timeout`: The maximum amount of time to wait for the request to complete, in seconds. Can be an integer or None.
111+
112+
Returns:
113+
A GitHubResponseModel object representing the API response.
114+
"""
85115
request_arguments: Dict[str, Any] = {
86116
"url": self._base_request_data.request_url(endpoint),
87-
"method": kwargs.get(GitHubRequestKwarg.METHOD, HttpMethod.GET).lower(),
88-
"params": kwargs.get(GitHubRequestKwarg.PARAMS)
89-
or kwargs.get(GitHubRequestKwarg.QUERY, {}),
90-
"timeout": self._base_request_data.timeout,
117+
"method": kwargs.get(GitHubRequestKwarg.METHOD, method).lower(),
118+
"params": params
119+
or kwargs.get(GitHubRequestKwarg.PARAMS, kwargs.get(GitHubRequestKwarg.QUERY, {})),
120+
"timeout": timeout or self._base_request_data.timeout,
91121
"headers": {
122+
**(headers or {}),
92123
**self._base_request_data.headers,
93124
**kwargs.get("headers", {}),
94125
},

‎aiogithubapi/github.py

+1
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ async def versions(
167167
async def markdown(
168168
self,
169169
text: str,
170+
*,
170171
mode: str | None = None,
171172
context: RepositoryType | None = None,
172173
**kwargs: Dict[GitHubRequestKwarg, Any],

‎aiogithubapi/namespaces/repos.py

+45-8
Original file line numberDiff line numberDiff line change
@@ -103,21 +103,58 @@ async def get(
103103
async def list_commits(
104104
self,
105105
repository: RepositoryType,
106+
*,
107+
sha: str | None = None,
108+
path: str | None = None,
109+
author: str | None = None,
110+
since: str | None = None,
111+
until: str | None = None,
112+
per_page: int = 30,
113+
page: int = 0,
106114
**kwargs: Dict[GitHubRequestKwarg, Any],
107115
) -> GitHubResponseModel[List[GitHubCommitModel]]:
108116
"""
109-
List commits
110-
111-
**Arguments**:
112-
113-
`repository`
114-
115-
The repository to return commits from, example "octocat/hello-world"
116-
117+
List commits from a repository.
118+
119+
**Arguments**:
120+
121+
- `repository`: The repository to return commits from, specified as
122+
`<owner>/<repository>`, e.g. "octocat/hello-world".
123+
- `sha`: Filter the commits to only those with the given SHA.
124+
- `path`: Filter the commits to only those with changes to the given path.
125+
- `author`: Filter the commits to only those with the given author.
126+
- `since`: Filter the commits to only those that were made after the given
127+
date and time. The `since` parameter should be formatted as an ISO 8601
128+
date and time, e.g. "2022-12-03T12:34:56Z".
129+
- `until`: Filter the commits to only those that were made before the given
130+
date and time. The `until` parameter should be formatted as an ISO 8601
131+
date and time, e.g. "2022-12-03T12:34:56Z".
132+
- `per_page`: The number of commits to return per page. The default value is
133+
30 and the maximum allowed value is 100.
134+
- `page`: The page number to return. The default value is 0 (the first page).
135+
136+
For more details, see the API documentation at:
117137
https://docs.github.com/en/rest/reference/repos#list-commits
118138
"""
139+
params = {
140+
"per_page": per_page,
141+
"page": page,
142+
}
143+
144+
if sha is not None:
145+
params["sha"] = sha
146+
if path is not None:
147+
params["path"] = path
148+
if author is not None:
149+
params["author"] = author
150+
if since is not None:
151+
params["since"] = since
152+
if until is not None:
153+
params["until"] = until
154+
119155
response = await self._client.async_call_api(
120156
endpoint=f"/repos/{repository_full_name(repository)}/commits",
157+
params=params,
121158
**kwargs,
122159
)
123160
response.data = [GitHubCommitModel(data) for data in response.data]

‎tests/namespaces/test_repos.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ async def test_get_repository(github_api: GitHubAPI, mock_requests: MockedReques
2626

2727
@pytest.mark.asyncio
2828
async def test_list_commits(github_api: GitHubAPI, mock_requests: MockedRequests):
29-
response = await github_api.repos.list_commits(TEST_REPOSITORY_NAME)
29+
response = await github_api.repos.list_commits(TEST_REPOSITORY_NAME, sha="main", path="README.md", author="awesome_author", since="2021-01-01", until="2021-01-02")
3030
assert response.status == 200
3131
assert isinstance(response.data, list)
3232
assert response.data[0].commit.message == "Merge pull request #6"

0 commit comments

Comments
 (0)
Please sign in to comment.