-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.go
77 lines (66 loc) · 1.57 KB
/
cli.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
66
67
68
69
70
71
72
73
74
75
76
77
package main
import (
"encoding/json"
"github.com/cli/go-gh"
"log"
)
func ghRepository() Repository {
args := []string{"repo", "view", "--json", "name,owner,isInOrganization"}
stdOut, _, err := gh.Exec(args...)
if err != nil {
log.Fatal(err)
}
var repository Repository
if err := json.Unmarshal(stdOut.Bytes(), &repository); err != nil {
panic(err)
}
return repository
}
func ghCurrentPullRequest() Content {
args := []string{"pr", "view", "--json", "id,number,title"}
stdOut, _, err := gh.Exec(args...)
if err != nil {
log.Fatal(err)
}
var currentPR Content
if err := json.Unmarshal(stdOut.Bytes(), ¤tPR); err != nil {
panic(err)
}
return currentPR
}
func ghContent(contentType string, number string) Content {
var subCommand string
if contentType == "Issue" {
subCommand = "issue"
} else {
subCommand = "pr"
}
args := []string{subCommand, "view", number, "--json", "id,number,title"}
stdOut, _, err := gh.Exec(args...)
if err != nil {
log.Fatal("Error: not found " + contentType)
}
var content Content
if err := json.Unmarshal(stdOut.Bytes(), &content); err != nil {
panic(err)
}
return content
}
func ghContentList(contentType string) []Content {
var subCommand string
if contentType == "Issue" {
subCommand = "issue"
} else {
subCommand = "pr"
}
args := []string{subCommand, "list", "--limit", "50", "--json", "id,number,title"}
stdOut, _, err := gh.Exec(args...)
if err != nil {
log.Fatal(err)
}
var contents []Content
if err := json.Unmarshal(stdOut.Bytes(), &contents); err != nil {
panic(err)
}
return contents
}