gogs: Ensure to list all repositories

In contrary of gitea listing which does not require to provide the q query
parameter, it is required for the gogs case.

After reading the gogs source code, the /repos/search endpoint generates
a sql request of the form: "SELECT * FROM repos WHERE name LIKE '%{q}%'".
By setting the q parameter value to "_", the LIKE clause acts as a
wildcard and all repositories are ensured to be returned.

Fixes #4698.
This commit is contained in:
Antoine Lambert 2023-06-26 15:16:48 +00:00
parent 206ac680dc
commit b9815ed577
2 changed files with 6 additions and 3 deletions

View file

@ -89,10 +89,13 @@ class GogsLister(Lister[GogsListerState, GogsListerPage]):
enable_origins=enable_origins,
)
self.query_params = {
self.query_params: Dict[str, Any] = {
"limit": page_size,
}
if self.LISTER_NAME == "gogs":
self.query_params["q"] = "_" # wildcard for all repositories
self.api_token = api_token
if self.api_token is None:
@ -175,7 +178,7 @@ class GogsLister(Lister[GogsListerState, GogsListerPage]):
yield GogsListerPage(repos=repos, next_link=next_link)
if next_link is not None:
body, links = self.page_request(next_link, {})
body, links = self.page_request(next_link, self.query_params)
def get_origins_from_page(self, page: GogsListerPage) -> Iterator[ListedOrigin]:
"""Convert a page of Gogs repositories into a list of ListedOrigins"""

View file

@ -18,7 +18,7 @@ TRY_GOGS_URL = "https://try.gogs.io/api/v1/"
def try_gogs_page(n: int):
return TRY_GOGS_URL + GogsLister.REPO_LIST_PATH + f"?page={n}&limit=3"
return TRY_GOGS_URL + GogsLister.REPO_LIST_PATH + f"?q=_&page={n}&limit=3"
P1 = try_gogs_page(1)