forked from plouc/go-gitlab-client
/
list_group_merge_requests_cmd.go
64 lines (51 loc) · 1.29 KB
/
list_group_merge_requests_cmd.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
package cmd
import (
"fmt"
"strconv"
"github.com/fatih/color"
out "github.com/plouc/go-gitlab-client/cli/output"
"github.com/plouc/go-gitlab-client/gitlab"
"github.com/spf13/cobra"
)
func init() {
listCmd.AddCommand(listGroupMergeRequestsCmd)
}
func fetchGroupMergeRequests(groupId int) {
color.Yellow("Fetching group %d merge requests…", groupId)
o := &gitlab.MergeRequestsOptions{}
o.Page = page
o.PerPage = perPage
loader.Start()
collection, meta, err := client.GroupMergeRequests(groupId, o)
loader.Stop()
if err != nil {
fmt.Println(err.Error())
return
}
if len(collection.Items) == 0 {
color.Red("No merge request found for group %d", groupId)
} else {
out.MergeRequests(output, outputFormat, collection)
}
printMeta(meta, true)
handlePaginatedResult(meta, func() {
fetchGroupMergeRequests(groupId)
})
}
var listGroupMergeRequestsCmd = &cobra.Command{
Use: resourceCmd("group-merge-requests", "group"),
Aliases: []string{"gmr"},
Short: "List group merge requests",
RunE: func(cmd *cobra.Command, args []string) error {
ids, err := config.aliasIdsOrArgs(currentAlias, "group", args)
if err != nil {
return err
}
groupId, err := strconv.Atoi(ids["group_id"])
if err != nil {
return err
}
fetchGroupMergeRequests(groupId)
return nil
},
}