forked from plouc/go-gitlab-client
/
ls_project_branches.go
65 lines (51 loc) · 1.35 KB
/
ls_project_branches.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package cmd
import (
"fmt"
"github.com/fatih/color"
out "github.com/plouc/go-gitlab-client/cli/output"
"github.com/plouc/go-gitlab-client/gitlab"
"github.com/spf13/cobra"
)
var branchesSearch string
func init() {
lsCmd.AddCommand(lsProjectBranchesCmd)
lsProjectBranchesCmd.Flags().StringVarP(&branchesSearch, "search", "s", "", "Search term")
}
func fetchProjectBranches(projectId string) {
color.Yellow("Fetching project's branches (id: %s)…", projectId)
o := &gitlab.BranchesOptions{}
o.Page = page
o.PerPage = perPage
if branchesSearch != "" {
o.Search = branchesSearch
}
loader.Start()
collection, meta, err := client.ProjectBranches(projectId, o)
loader.Stop()
if err != nil {
fmt.Println(err.Error())
return
}
if len(collection.Items) == 0 {
color.Red("No branch found for project %s", projectId)
} else {
out.Branches(output, outputFormat, collection)
}
printMeta(meta, true)
handlePaginatedResult(meta, func() {
fetchProjectBranches(projectId)
})
}
var lsProjectBranchesCmd = &cobra.Command{
Use: resourceCmd("project-branches", "project"),
Aliases: []string{"pb"},
Short: "List project branches",
RunE: func(cmd *cobra.Command, args []string) error {
ids, err := config.aliasIdsOrArgs(currentAlias, "project", args)
if err != nil {
return err
}
fetchProjectBranches(ids["project_id"])
return nil
},
}