add GetRunsWithFilter
This commit is contained in:
parent
df5883186c
commit
1ddb33bf3c
1 changed files with 26 additions and 2 deletions
|
|
@ -150,6 +150,25 @@ type RunsPayload struct {
|
|||
WorkflowRuns []Run `json:"workflow_runs"`
|
||||
}
|
||||
|
||||
func GetRunsWithFilter(client *api.Client, repo ghrepo.Interface, limit int, f func(Run) bool) ([]Run, error) {
|
||||
path := fmt.Sprintf("repos/%s/actions/runs", ghrepo.FullName(repo))
|
||||
runs, err := getRuns(client, repo, path, 50)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
filtered := []Run{}
|
||||
for _, run := range runs {
|
||||
if f(run) {
|
||||
filtered = append(filtered, run)
|
||||
}
|
||||
if len(filtered) == limit {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return filtered, nil
|
||||
}
|
||||
|
||||
func GetRunsByWorkflow(client *api.Client, repo ghrepo.Interface, limit, workflowID int) ([]Run, error) {
|
||||
path := fmt.Sprintf("repos/%s/actions/workflows/%d/runs", ghrepo.FullName(repo), workflowID)
|
||||
return getRuns(client, repo, path, limit)
|
||||
|
|
@ -172,9 +191,14 @@ func getRuns(client *api.Client, repo ghrepo.Interface, path string, limit int)
|
|||
for len(runs) < limit {
|
||||
var result RunsPayload
|
||||
|
||||
pagedPath := fmt.Sprintf("%s?per_page=%d&page=%d", path, perPage, page)
|
||||
parsed, err := url.Parse(path)
|
||||
query := parsed.Query()
|
||||
query.Set("per_page", fmt.Sprintf("%d", perPage))
|
||||
query.Set("page", fmt.Sprintf("%d", page))
|
||||
parsed.RawQuery = query.Encode()
|
||||
pagedPath := parsed.String()
|
||||
|
||||
err := client.REST(repo.RepoHost(), "GET", pagedPath, nil, &result)
|
||||
err = client.REST(repo.RepoHost(), "GET", pagedPath, nil, &result)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue