Skip to content

Commit

Permalink
Add retries to github repo reader (run-llama#10980)
Browse files Browse the repository at this point in the history
  • Loading branch information
rwood-97 authored and Dominastorm committed Feb 28, 2024
1 parent 8e0ce12 commit 9cee763
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def __init__(
verbose: bool = False,
concurrent_requests: int = 5,
timeout: Optional[int] = 5,
retries: int = 0,
filter_directories: Optional[Tuple[List[str], FilterType]] = None,
filter_file_extensions: Optional[Tuple[List[str], FilterType]] = None,
):
Expand All @@ -92,6 +93,7 @@ def __init__(
- concurrent_requests (int): Number of concurrent requests to
make to the Github API.
- timeout (int or None): Timeout for the requests to the Github API. Default is 5.
- retries (int): Number of retries for requests made to the Github API. Default is 0.
- filter_directories (Optional[Tuple[List[str], FilterType]]): Tuple
containing a list of directories and a FilterType. If the FilterType
is INCLUDE, only the files in the directories in the list will be
Expand All @@ -115,6 +117,7 @@ def __init__(
self._verbose = verbose
self._concurrent_requests = concurrent_requests
self._timeout = timeout
self._retries = retries
self._filter_directories = filter_directories
self._filter_file_extensions = filter_file_extensions

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,7 @@ async def request(
method: str,
headers: Dict[str, Any] = {},
timeout: Optional[int] = 5,
retries: int = 0,
**kwargs: Any,
) -> Any:
"""
Expand All @@ -285,6 +286,7 @@ async def request(
- `method (str)`: HTTP method to use for the request.
- `headers (dict)`: HTTP headers to include in the request.
- `timeout (int or None)`: Timeout for the request in seconds. Default is 5.
- `retries (int)`: Number of retries for the request. Default is 0.
- `**kwargs`: Keyword arguments to pass to the endpoint URL.
Returns:
Expand All @@ -297,7 +299,7 @@ async def request(
Examples:
>>> response = client.request("getTree", "GET",
owner="owner", repo="repo",
tree_sha="tree_sha", timeout=5)
tree_sha="tree_sha", timeout=5, retries=0)
"""
try:
import httpx
Expand All @@ -314,6 +316,7 @@ async def request(
headers=_headers,
base_url=self._base_url,
timeout=timeout,
transport=httpx.AsyncHTTPTransport(retries=retries),
) as _client:
try:
response = await _client.request(
Expand All @@ -331,6 +334,7 @@ async def get_branch(
branch: Optional[str] = None,
branch_name: Optional[str] = None,
timeout: Optional[int] = 5,
retries: int = 0,
) -> GitBranchResponseModel:
"""
Get information about a branch. (Github API endpoint: getBranch).
Expand All @@ -339,6 +343,9 @@ async def get_branch(
- `owner (str)`: Owner of the repository.
- `repo (str)`: Name of the repository.
- `branch (str)`: Name of the branch.
- `branch_name (str)`: Name of the branch (alternative to `branch`).
- `timeout (int or None)`: Timeout for the request in seconds. Default is 5.
- `retries (int)`: Number of retries for the request. Default is 0.
Returns:
- `branch_info (GitBranchResponseModel)`: Information about the branch.
Expand All @@ -360,6 +367,7 @@ async def get_branch(
repo=repo,
branch=branch,
timeout=timeout,
retries=retries,
)
).text
)
Expand All @@ -370,6 +378,7 @@ async def get_tree(
repo: str,
tree_sha: str,
timeout: Optional[int] = 5,
retries: int = 0,
) -> GitTreeResponseModel:
"""
Get information about a tree. (Github API endpoint: getTree).
Expand All @@ -379,6 +388,7 @@ async def get_tree(
- `repo (str)`: Name of the repository.
- `tree_sha (str)`: SHA of the tree.
- `timeout (int or None)`: Timeout for the request in seconds. Default is 5.
- `retries (int)`: Number of retries for the request. Default is 0.
Returns:
- `tree_info (GitTreeResponseModel)`: Information about the tree.
Expand All @@ -395,6 +405,7 @@ async def get_tree(
repo=repo,
tree_sha=tree_sha,
timeout=timeout,
retries=retries,
)
).text
)
Expand All @@ -405,6 +416,7 @@ async def get_blob(
repo: str,
file_sha: str,
timeout: Optional[int] = 5,
retries: int = 0,
) -> Optional[GitBlobResponseModel]:
"""
Get information about a blob. (Github API endpoint: getBlob).
Expand All @@ -414,6 +426,7 @@ async def get_blob(
- `repo (str)`: Name of the repository.
- `file_sha (str)`: SHA of the file.
- `timeout (int or None)`: Timeout for the request in seconds. Default is 5.
- `retries (int)`: Number of retries for the request. Default is 0.
Returns:
- `blob_info (GitBlobResponseModel)`: Information about the blob.
Expand All @@ -431,6 +444,7 @@ async def get_blob(
repo=repo,
file_sha=file_sha,
timeout=timeout,
retries=retries,
)
).text
)
Expand All @@ -444,6 +458,7 @@ async def get_commit(
repo: str,
commit_sha: str,
timeout: Optional[int] = 5,
retries: int = 0,
) -> GitCommitResponseModel:
"""
Get information about a commit. (Github API endpoint: getCommit).
Expand All @@ -453,6 +468,7 @@ async def get_commit(
- `repo (str)`: Name of the repository.
- `commit_sha (str)`: SHA of the commit.
- `timeout (int or None)`: Timeout for the request in seconds. Default is 5.
- `retries (int)`: Number of retries for the request. Default is 0.
Returns:
- `commit_info (GitCommitResponseModel)`: Information about the commit.
Expand All @@ -469,6 +485,7 @@ async def get_commit(
repo=repo,
commit_sha=commit_sha,
timeout=timeout,
retries=retries,
)
).text
)
Expand Down

0 comments on commit 9cee763

Please sign in to comment.