-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
130 lines (115 loc) · 3.06 KB
/
main.go
File metadata and controls
130 lines (115 loc) · 3.06 KB
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
package main
import (
"flag"
"github.com/cli/go-gh"
"github.com/cli/go-gh/pkg/api"
"log"
"strconv"
)
func getProjects(gqlclient api.GQLClient) []Project {
restClient, err := gh.RESTClient(nil)
if err != nil {
log.Fatal(err)
}
response := struct{ Login string }{}
err = restClient.Get("user", &response)
if err != nil {
log.Fatal(err)
}
var projects []Project
userProjects := queryUserProjects(gqlclient, response.Login)
for _, p := range userProjects {
project := struct {
Title string
Id string
Type string
}{
Title: p.Title,
Id: p.Id,
Type: "UserProject",
}
projects = append(projects, project)
}
repository := ghRepository()
if repository.IsInOrganization {
organizationProjects := queryOrganizationProjects(gqlclient, repository.Owner.Login)
for _, p := range organizationProjects {
project := struct {
Title string
Id string
Type string
}{
Title: p.Title,
Id: p.Id,
Type: "OrganizationProject",
}
projects = append(projects, project)
}
}
return projects
}
func main() {
var options struct {
issueNo int
prNo int
}
flag.IntVar(&options.issueNo, "issue", 0, "Issue Number")
flag.IntVar(&options.prNo, "pr", 0, "PullRequest Number")
flag.Parse()
gqlclient, err := gh.GQLClient(nil)
if err != nil {
log.Fatal(err)
}
projects := getProjects(gqlclient)
projectId := askOneProjectId(projects)
fields := getProjectFields(gqlclient, projectId)
var itemId string
var content Content
if options.issueNo != 0 || options.prNo != 0 {
if options.issueNo != 0 {
content = ghContent("Issue", strconv.Itoa(options.issueNo))
} else {
content = ghContent("PullRequest", strconv.Itoa(options.prNo))
}
} else {
itemTypes := []string{"Current PullRequest", "PullRequest", "Issue"}
selectedType := askOneContentType(itemTypes)
if selectedType == "Current PullRequest" {
content = ghCurrentPullRequest()
} else {
contentList := ghContentList(selectedType)
number := askContentNumber(selectedType, contentList)
content = ghContent(selectedType, number)
}
}
itemId = addProject(gqlclient, projectId, content.Id)
for _, field := range fields {
if field.DataType == "TEXT" {
input := askTextFieldValue(field.Name)
if input != "" {
updateTextProjectField(gqlclient, projectId, itemId, field.Id, input)
}
}
if field.DataType == "DATE" {
dateInput := askDateFieldValue(field.Name)
if dateInput != "" {
updateDateProjectField(gqlclient, projectId, itemId, field.Id, dateInput)
}
}
if field.DataType == "NUMBER" {
f := askNumberFieldValue(field.Name)
updateNumberProjectField(gqlclient, projectId, itemId, field.Id, f)
}
if field.DataType == "SINGLE_SELECT" || field.DataType == "ITERATION" {
selected := askOneSelectFieldValue(field.Name, field.Options)
if selected == "Skip" {
continue
}
if field.DataType == "ITERATION" {
updateIterationProjectField(gqlclient, projectId, itemId, field.Id, selected)
} else {
updateSingleSelectProjectField(gqlclient, projectId, itemId, field.Id, selected)
}
}
}
}