resolve first todos

This commit is contained in:
6543 2021-05-19 23:09:29 +02:00
parent ea3c106944
commit e3ebcf47d3

24
main.go
View File

@ -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,12 +136,26 @@ 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)
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))
fmt.Printf(" ")
for _, b := range 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,