Skip to content

Commit

Permalink
fix: issue where trusted plugins showed up as 3rd party (#2106)
Browse files Browse the repository at this point in the history
  • Loading branch information
antazoey authored Jun 1, 2024
1 parent 5665aba commit 8c83a38
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/ape/utils/_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import subprocess
import tempfile
import zipfile
from collections.abc import Iterator
from io import BytesIO
from pathlib import Path
from typing import Any, Optional, Union
Expand Down Expand Up @@ -99,8 +100,17 @@ def available_plugins(self) -> set[str]:
if not repo.get("private", False) and repo["name"].startswith(f"{self.FRAMEWORK_NAME}-")
}

def get_org_repos(self) -> list[dict]:
return self._get(f"orgs/{self.ORGANIZATION_NAME}/repos")
def get_org_repos(self) -> Iterator[dict]:
params = {"per_page": 100, "page": 1}
while True:
response = self._get(f"orgs/{self.ORGANIZATION_NAME}/repos", params=params)
repository_count = len(response)

if repository_count == 0:
break

yield from response
params["page"] += 1

def get_release(self, org_name: str, repo_name: str, version: str) -> dict:
if version == "latest":
Expand Down Expand Up @@ -207,8 +217,8 @@ def download_package(
for source_file in package_path.iterdir():
shutil.move(str(source_file), str(target_path))

def _get(self, url: str) -> Any:
return self._request("GET", url)
def _get(self, url: str, params: Optional[dict] = None) -> Any:
return self._request("GET", url, params=params)

def _request(self, method: str, url: str, **kwargs) -> Any:
url = f"{self.API_URL_PREFIX}/{url}"
Expand Down
7 changes: 7 additions & 0 deletions tests/functional/utils/test_github.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,10 @@ def side_effect(method, uri, *arg, **kwargs):
expected_uri = "https://api.github.com/repos/test/path/releases/tags"
assert calls[0][0] == ("GET", f"{expected_uri}/{version}")
assert calls[1][0] == ("GET", f"{expected_uri}/{opposite}")

def test_get_org_repos(self, github_client, mock_session):
_ = list(github_client.get_org_repos())
call = mock_session.method_calls[-1]
params = call.kwargs["params"]
# Show we are fetching more than the default 30 per page.
assert params == {"per_page": 100, "page": 1}

0 comments on commit 8c83a38

Please sign in to comment.