Skip to content

Commit c0465cb

Browse files
committed
Implement bulk open, bulk close
1 parent a8a96f1 commit c0465cb

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

api/queries_bulk.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,3 +116,38 @@ func BulkAddLabels(client *Client, inputs []BulkInput, labelNames []string) erro
116116

117117
return nil
118118
}
119+
120+
func BulkChangeState(client *Client, inputs []BulkInput, state string) error {
121+
ids, err := ResolveNodeIDs(client, inputs)
122+
if err != nil {
123+
return err
124+
}
125+
126+
var mutations []string
127+
var newState string
128+
129+
switch state {
130+
case "open":
131+
newState = "OPEN"
132+
case "close":
133+
newState = "CLOSED"
134+
default:
135+
return fmt.Errorf("unrecognized state: %q", state)
136+
}
137+
138+
for i, id := range ids {
139+
mutations = append(mutations, fmt.Sprintf(`
140+
m%03d: updateIssue(input: {
141+
id: %q
142+
state: %s
143+
}) { clientMutationId }
144+
`, i, id.Issue.ID, newState))
145+
}
146+
147+
err = client.GraphQL(fmt.Sprintf(`mutation{%s}`, strings.Join(mutations, "")), nil, nil)
148+
if err != nil {
149+
return err
150+
}
151+
152+
return nil
153+
}

command/bulk.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,11 @@ func bulk(cmd *cobra.Command, args []string) error {
103103
}
104104

105105
operation := args[0]
106-
// TODO: open, close
107106
switch operation {
108107
case "add":
109108
return api.BulkAddLabels(client, inputItems, labels)
109+
case "open", "close":
110+
return api.BulkChangeState(client, inputItems, operation)
110111
case "browse":
111112
for _, item := range inputItems {
112113
url := fmt.Sprintf("https://github.com/%s/%s", item.Repository.RepoOwner(), item.Repository.RepoName())

0 commit comments

Comments
 (0)