fix(cron): retrieve all GitRepo's instead of first 25

This commit is contained in:
Jef Roosens 2022-05-25 09:24:01 +02:00
parent 96d0c2f1eb
commit 7f6e9e636c
Signed by untrusted user: Jef Roosens
GPG key ID: B75D4F293C7052DB
2 changed files with 23 additions and 2 deletions

View file

@ -4,7 +4,7 @@ import models { GitRepo, GitRepoFilter }
import net.http { Method }
import response { Response }
// get_git_repos returns the current list of repos.
// get_git_repos returns a list of GitRepo's, given a filter object.
pub fn (c &Client) get_git_repos(filter GitRepoFilter) ?[]GitRepo {
params := models.params_from(filter)
data := c.send_request<[]GitRepo>(Method.get, '/api/repos', params)?
@ -12,6 +12,27 @@ pub fn (c &Client) get_git_repos(filter GitRepoFilter) ?[]GitRepo {
return data.data
}
// get_all_git_repos retrieves *all* GitRepo's from the API using the default
// limit.
pub fn (c &Client) get_all_git_repos() ?[]GitRepo {
mut repos := []GitRepo{}
mut offset := u64(0)
for {
sub_repos := c.get_git_repos(offset: offset)?
if sub_repos.len == 0 {
break
}
repos << sub_repos
offset += u64(sub_repos.len)
}
return repos
}
// get_git_repo returns the repo for a specific ID.
pub fn (c &Client) get_git_repo(id int) ?GitRepo {
data := c.send_request<GitRepo>(Method.get, '/api/repos/$id', {})?