-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmutation.go
130 lines (115 loc) · 4.04 KB
/
mutation.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
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 (
"encoding/json"
"github.com/cli/go-gh/pkg/api"
graphql "github.com/cli/shurcooL-graphql"
"log"
)
func updateDateProjectField(gqlclient api.GQLClient, projectId string, itemId string, fieldId string, fieldValue string) {
b := []byte(`{"date":"` + fieldValue + `T00:00:00Z"}`)
var v NamedDateValue
if err := json.Unmarshal(b, &v); err != nil {
panic(err)
}
var mutation struct {
UpdateProjectV2ItemFieldValue struct {
ClientMutationID string
} `graphql:"updateProjectV2ItemFieldValue(input: {projectId: $projectId itemId: $itemId fieldId: $fieldId value: {date: $value}})"`
}
variables := map[string]interface{}{
"projectId": graphql.ID(projectId),
"itemId": graphql.ID(itemId),
"fieldId": graphql.ID(fieldId),
"value": v.Date,
}
err := gqlclient.Mutate("UpdateFieldValue", &mutation, variables)
if err != nil {
log.Fatal(err)
}
}
func updateIterationProjectField(gqlclient api.GQLClient, projectId string, itemId string, fieldId string, fieldValue string) {
var mutation struct {
UpdateProjectV2ItemFieldValue struct {
ClientMutationID string
} `graphql:"updateProjectV2ItemFieldValue(input: {projectId: $projectId itemId: $itemId fieldId: $fieldId value: {iterationId: $value}})"`
}
variables := map[string]interface{}{
"projectId": graphql.ID(projectId),
"itemId": graphql.ID(itemId),
"fieldId": graphql.ID(fieldId),
"value": graphql.String(fieldValue),
}
err := gqlclient.Mutate("UpdateFieldValue", &mutation, variables)
if err != nil {
log.Fatal(err)
}
}
func updateSingleSelectProjectField(gqlclient api.GQLClient, projectId string, itemId string, fieldId string, fieldValue string) {
var mutation struct {
UpdateProjectV2ItemFieldValue struct {
ClientMutationID string
} `graphql:"updateProjectV2ItemFieldValue(input: {projectId: $projectId itemId: $itemId fieldId: $fieldId value: {singleSelectOptionId: $value}})"`
}
variables := map[string]interface{}{
"projectId": graphql.ID(projectId),
"itemId": graphql.ID(itemId),
"fieldId": graphql.ID(fieldId),
"value": graphql.String(fieldValue),
}
err := gqlclient.Mutate("UpdateFieldValue", &mutation, variables)
if err != nil {
log.Fatal(err)
}
}
func updateNumberProjectField(gqlclient api.GQLClient, projectId string, itemId string, fieldId string, fieldValue float64) {
var mutation struct {
UpdateProjectV2ItemFieldValue struct {
ClientMutationID string
} `graphql:"updateProjectV2ItemFieldValue(input: {projectId: $projectId itemId: $itemId fieldId: $fieldId value: {number: $value}})"`
}
variables := map[string]interface{}{
"projectId": graphql.ID(projectId),
"itemId": graphql.ID(itemId),
"fieldId": graphql.ID(fieldId),
"value": graphql.Float(fieldValue),
}
err := gqlclient.Mutate("UpdateFieldValue", &mutation, variables)
if err != nil {
log.Fatal(err)
}
}
func updateTextProjectField(gqlclient api.GQLClient, projectId string, itemId string, fieldId string, fieldValue string) {
var mutation struct {
UpdateProjectV2ItemFieldValue struct {
ClientMutationID string
} `graphql:"updateProjectV2ItemFieldValue(input: {projectId: $projectId itemId: $itemId fieldId: $fieldId value: {text: $value}})"`
}
variables := map[string]interface{}{
"projectId": graphql.ID(projectId),
"itemId": graphql.ID(itemId),
"fieldId": graphql.ID(fieldId),
"value": graphql.String(fieldValue),
}
err := gqlclient.Mutate("UpdateFieldValue", &mutation, variables)
if err != nil {
log.Fatal(err)
}
}
func addProject(gqlclient api.GQLClient, projectId string, contentId string) (itemId string) {
var addProjectMutation struct {
AddProjectV2ItemById struct {
Item struct {
Id string
}
} `graphql:"addProjectV2ItemById(input: {contentId: $contentId projectId: $projectId})"`
}
addProjectVariables := map[string]interface{}{
"contentId": graphql.ID(contentId),
"projectId": graphql.ID(projectId),
}
err := gqlclient.Mutate("Assign", &addProjectMutation, addProjectVariables)
if err != nil {
log.Fatal(err)
}
return addProjectMutation.AddProjectV2ItemById.Item.Id
}