-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathlist.go
57 lines (48 loc) · 1.05 KB
/
list.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
package cmd
import (
"fmt"
"github.com/ldez/prm/v3/config"
"github.com/ldez/prm/v3/local"
"github.com/ldez/prm/v3/types"
)
// List list PRs.
func List(options *types.ListOptions) error {
// get configuration
configs, err := config.ReadFile()
if err != nil {
return err
}
if options.All {
displayProjects(configs, options.SkipEmpty)
} else {
repoDir, err := local.GetGitRepoRoot()
if err != nil {
return err
}
conf, err := config.Find(configs, repoDir)
if err != nil {
return err
}
displayPullRequests(conf.PullRequests)
}
return nil
}
func displayPullRequests(pulls map[string][]types.PullRequest) {
if len(pulls) == 0 {
fmt.Println("* 0 PR.")
} else {
for _, prs := range pulls {
for _, pr := range prs {
fmt.Printf("* %d: %s - %s\n", pr.Number, pr.Owner, pr.BranchName)
}
}
}
}
func displayProjects(configs []config.Configuration, skipEmpty bool) {
for _, conf := range configs {
if len(conf.PullRequests) > 0 || !skipEmpty {
fmt.Println(conf.Directory)
displayPullRequests(conf.PullRequests)
}
}
}