resolve first todos

This commit is contained in:
6543 2021-05-19 23:09:29 +02:00
parent ea3c106944
commit e3ebcf47d3
1 changed files with 21 additions and 7 deletions

28
main.go
View File

@ -23,6 +23,8 @@ type Cache struct {
pullBaseBranch string `json:"pullBaseBranch"` pullBaseBranch string `json:"pullBaseBranch"`
} }


const perPage = 10

func loadCache() (cache *Cache) { func loadCache() (cache *Cache) {
// default values // default values
cache = &Cache{ cache = &Cache{
@ -115,11 +117,9 @@ func main() {
} }


repoList = append(repoList, repos...) repoList = append(repoList, repos...)

if len(repos) < 10 { if len(repos) < 10 {
break break
} }

page++ page++
} }
fmt.Println() fmt.Println()
@ -136,10 +136,24 @@ func main() {
func threatRepo(baseBranchRule glob.Glob, client *gitlab.Client, repo *gitlab.Project) { func threatRepo(baseBranchRule glob.Glob, client *gitlab.Client, repo *gitlab.Project) {
fmt.Printf("Handle Repository '%s'\n", repo.Name) fmt.Printf("Handle Repository '%s'\n", repo.Name)


// TODO: handle pagination var branchList []*gitlab.Branch
branchList, _, err := client.Branches.ListBranches(repo.ID, nil) var page = 1
if err != nil { for {
error(10, "Could not obtain branch list from '%s': %v\n", repo.Name, err) 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(" found %d branches:", len(branchList))
@ -181,7 +195,7 @@ func threatRepo(baseBranchRule glob.Glob, client *gitlab.Client, repo *gitlab.Pr
if len(pullList) == 0 { if len(pullList) == 0 {
fmt.Printf(" no existing pull for %s, creating one ...\n", baseBranch.Name) fmt.Printf(" no existing pull for %s, creating one ...\n", baseBranch.Name)
pull, _, err := client.MergeRequests.CreateMergeRequest(repo.ID, &gitlab.CreateMergeRequestOptions{ 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"), Description: optString("Auto created by https://code.obermui.de/6543/GitLab_MergeDevel2Default"),
SourceBranch: &baseBranch.Name, SourceBranch: &baseBranch.Name,
TargetBranch: &repo.DefaultBranch, TargetBranch: &repo.DefaultBranch,