From e3ebcf47d3a5e4fdc5aa8ee6f93083a112c74511 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Wed, 19 May 2021 23:09:29 +0200 Subject: [PATCH] resolve first todos --- main.go | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/main.go b/main.go index a38ac85..c0e283b 100644 --- a/main.go +++ b/main.go @@ -23,6 +23,8 @@ type Cache struct { pullBaseBranch string `json:"pullBaseBranch"` } +const perPage = 10 + func loadCache() (cache *Cache) { // default values cache = &Cache{ @@ -115,11 +117,9 @@ func main() { } repoList = append(repoList, repos...) - if len(repos) < 10 { break } - page++ } fmt.Println() @@ -136,10 +136,24 @@ func main() { func threatRepo(baseBranchRule glob.Glob, client *gitlab.Client, repo *gitlab.Project) { fmt.Printf("Handle Repository '%s'\n", repo.Name) - // TODO: handle pagination - branchList, _, err := client.Branches.ListBranches(repo.ID, nil) - if err != nil { - error(10, "Could not obtain branch list from '%s': %v\n", repo.Name, err) + var branchList []*gitlab.Branch + var page = 1 + for { + bL, _, err := client.Branches.ListBranches(repo.ID, &gitlab.ListBranchesOptions{ + ListOptions: gitlab.ListOptions{ + Page: page, + PerPage: perPage, + }, + }) + if err != nil { + error(10, "Could not obtain branch list from '%s': %v\n", repo.Name, err) + } + + branchList = append(branchList, bL...) + if len(bL) < 10 { + break + } + page++ } fmt.Printf(" found %d branches:", len(branchList)) @@ -181,7 +195,7 @@ func threatRepo(baseBranchRule glob.Glob, client *gitlab.Client, repo *gitlab.Pr if len(pullList) == 0 { fmt.Printf(" no existing pull for %s, creating one ...\n", baseBranch.Name) pull, _, err := client.MergeRequests.CreateMergeRequest(repo.ID, &gitlab.CreateMergeRequestOptions{ - Title: optString(fmt.Sprintf("%s <- %s", repo.DefaultBranch, baseBranch.Name)), // TODO: better title (required) + Title: optString(fmt.Sprintf("%s <- %s", repo.DefaultBranch, baseBranch.Name)), Description: optString("Auto created by https://code.obermui.de/6543/GitLab_MergeDevel2Default"), SourceBranch: &baseBranch.Name, TargetBranch: &repo.DefaultBranch,