Skip to content

Commit 1268dc6

Browse files
committed
switch prs to new Updateitem
1 parent eba2b80 commit 1268dc6

File tree

3 files changed

+19
-94
lines changed

3 files changed

+19
-94
lines changed

cli/cmds_project.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func CmdSync(_ *cobra.Command, args []string) error {
112112
c.Printf("<blue>updating</>...")
113113

114114
//update status to "Unclaimed PR" & update request type to
115-
// TODO switch to gh.UpdateItem
115+
// TODO we can loop through the fields and build a more dynamic query from a function p.UpdateItemFields()
116116
q := `query=
117117
mutation (
118118
$project:ID!, $item:ID!,

cli/cmds_prs.go

+11-93
Original file line numberDiff line numberDiff line change
@@ -157,101 +157,19 @@ func CmdPRs(_ *cobra.Command, _ []string) error {
157157
byStatus[statusText] = append(byStatus[statusText], pr.GetNumber())
158158

159159
c.Printf(" open %d days, waiting %d days\n", daysOpen, daysWaiting)
160-
161-
// TODO switch to gh.UpdateItem
162-
q := `query=
163-
mutation (
164-
$project:ID!, $item:ID!,
165-
$status_field:ID!, $status_value:String!,
166-
$pr_field:ID!, $pr_value:String!,
167-
$user_field:ID!, $user_value:String!,
168-
$daysOpen_field:ID!, $daysOpen_value:Float!,
169-
$daysWait_field:ID!, $daysWait_value:Float!,
170-
) {
171-
set_status: updateProjectV2ItemFieldValue(input: {
172-
projectId: $project
173-
itemId: $item
174-
fieldId: $status_field
175-
value: {
176-
singleSelectOptionId: $status_value
177-
}
178-
}) {
179-
projectV2Item {
180-
id
181-
}
182-
}
183-
set_pr: updateProjectV2ItemFieldValue(input: {
184-
projectId: $project
185-
itemId: $item
186-
fieldId: $pr_field
187-
value: {
188-
text: $pr_value
189-
}
190-
}) {
191-
projectV2Item {
192-
id
193-
}
194-
}
195-
set_user: updateProjectV2ItemFieldValue(input: {
196-
projectId: $project
197-
itemId: $item
198-
fieldId: $user_field
199-
value: {
200-
text: $user_value
201-
}
202-
}) {
203-
projectV2Item {
204-
id
205-
}
206-
}
207-
set_dopen: updateProjectV2ItemFieldValue(input: {
208-
projectId: $project
209-
itemId: $item
210-
fieldId: $daysOpen_field
211-
value: {
212-
number: $daysOpen_value
213-
}
214-
}) {
215-
projectV2Item {
216-
id
217-
}
218-
}
219-
set_dwait: updateProjectV2ItemFieldValue(input: {
220-
projectId: $project
221-
itemId: $item
222-
fieldId: $daysWait_field
223-
value: {
224-
number: $daysWait_value
225-
}
226-
}) {
227-
projectV2Item {
228-
id
229-
}
230-
}
231-
}
232-
`
233-
234-
p := [][]string{
235-
{"-f", "project=" + p.ID},
236-
{"-f", "item=" + *iid},
237-
{"-f", "status_field=" + p.FieldIDs["Status"]},
238-
{"-f", "status_value=" + status},
239-
{"-f", "pr_field=" + p.FieldIDs["PR#"]},
240-
{"-f", fmt.Sprintf("pr_value=%d", *pr.Number)}, // todo string + value
241-
{"-f", "user_field=" + p.FieldIDs["User"]},
242-
{"-f", fmt.Sprintf("user_value=%s", pr.User.GetLogin())},
243-
{"-f", "daysOpen_field=" + p.FieldIDs["Open Days"]},
244-
{"-F", fmt.Sprintf("daysOpen_value=%d", daysOpen)},
245-
{"-f", "daysWait_field=" + p.FieldIDs["Waiting Days"]},
246-
{"-F", fmt.Sprintf("daysWait_value=%d", daysWaiting)},
160+
161+
fields := []gh.ProjectItemField{
162+
{Name: "number", FieldID: p.FieldIDs["#"], Type: gh.ItemValueTypeNumber, Value: *pr.Number},
163+
{Name: "status", FieldID: p.FieldIDs["Status"], Type: gh.ItemValueTypeSingleSelect, Value: status},
164+
{Name: "user", FieldID: p.FieldIDs["User"], Type: gh.ItemValueTypeText, Value: pr.User.GetLogin()},
165+
{Name: "daysOpen", FieldID: p.FieldIDs["Open Days"], Type: gh.ItemValueTypeNumber, Value: daysOpen},
166+
{Name: "daysWait", FieldID: p.FieldIDs["Waiting Days"], Type: gh.ItemValueTypeNumber, Value: daysWaiting},
247167
}
248168

249-
if !f.DryRun {
250-
out, err := r.GraphQLQuery(q, p)
251-
if err != nil {
252-
c.Printf("\n\n <red>ERROR!!</> %s\n%s", err, *out)
253-
return nil
254-
}
169+
err = p.UpdateItem(*iid, fields)
170+
if err != nil {
171+
c.Printf("\n\n <red>ERROR!!</> %s", err)
172+
continue
255173
}
256174

257175
c.Printf("\n")

lib/gh/project-item.go

+7
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ type ItemValueType int
227227
const (
228228
ItemValueTypeText ItemValueType = iota
229229
ItemValueTypeNumber
230+
ItemValueTypeSingleSelect
230231
ItemValueTypeDate
231232
)
232233

@@ -268,6 +269,8 @@ func (p *Project) UpdateItem(itemID string, fields []ProjectItemField) error {
268269
varDefs = append(varDefs, fieldIDVar+":ID!")
269270
switch f.Type {
270271
case ItemValueTypeText:
272+
fallthrough
273+
case ItemValueTypeSingleSelect:
271274
varDefs = append(varDefs, fieldValueVar+":String!")
272275
case ItemValueTypeNumber:
273276
varDefs = append(varDefs, fieldValueVar+":Float!")
@@ -279,6 +282,8 @@ func (p *Project) UpdateItem(itemID string, fields []ProjectItemField) error {
279282
params = append(params, []string{"-f", fmt.Sprintf("%s_field=%s", fieldAlias, f.FieldID)})
280283
switch f.Type {
281284
case ItemValueTypeText:
285+
fallthrough
286+
case ItemValueTypeSingleSelect:
282287
params = append(params, []string{"-f", fmt.Sprintf("%s_value=%v", fieldAlias, f.Value)})
283288
case ItemValueTypeNumber:
284289
// Use -F so the value is recognized as a JSON number
@@ -292,6 +297,8 @@ func (p *Project) UpdateItem(itemID string, fields []ProjectItemField) error {
292297
valuePart = fmt.Sprintf("value: { text: %s }", fieldValueVar)
293298
case ItemValueTypeNumber:
294299
valuePart = fmt.Sprintf("value: { number: %s }", fieldValueVar)
300+
case ItemValueTypeSingleSelect:
301+
valuePart = fmt.Sprintf("value: { singleSelectOptionId: %s }", fieldValueVar)
295302
}
296303

297304
setCalls = append(setCalls, fmt.Sprintf(`

0 commit comments

Comments
 (0)