Skip to content

Commit 4ae1193

Browse files
author
Nate Smith
authored
Merge pull request cli#186 from github/issue-list-no-assignee
Fix `issue list` re: issues that have an assignee
2 parents cbecae7 + 9c36c7b commit 4ae1193

File tree

3 files changed

+41
-20
lines changed

3 files changed

+41
-20
lines changed

api/queries_issue.go

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -154,19 +154,6 @@ func IssueList(client *Client, ghRepo Repo, state string, labels []string, assig
154154
return nil, fmt.Errorf("invalid state: %s", state)
155155
}
156156

157-
// If you don't want to filter by lables, graphql requires you need
158-
// to send nil instead of an empty array.
159-
if len(labels) == 0 {
160-
labels = nil
161-
}
162-
163-
var assignee interface{}
164-
if len(assigneeString) > 0 {
165-
assignee = assigneeString
166-
} else {
167-
assignee = nil
168-
}
169-
170157
query := fragments + `
171158
query($owner: String!, $repo: String!, $limit: Int, $states: [IssueState!] = OPEN, $labels: [String!], $assignee: String) {
172159
repository(owner: $owner, name: $repo) {
@@ -183,12 +170,16 @@ func IssueList(client *Client, ghRepo Repo, state string, labels []string, assig
183170
owner := ghRepo.RepoOwner()
184171
repo := ghRepo.RepoName()
185172
variables := map[string]interface{}{
186-
"limit": limit,
187-
"owner": owner,
188-
"repo": repo,
189-
"states": states,
190-
"labels": labels,
191-
"assignee": assignee,
173+
"limit": limit,
174+
"owner": owner,
175+
"repo": repo,
176+
"states": states,
177+
}
178+
if len(labels) > 0 {
179+
variables["labels"] = labels
180+
}
181+
if assigneeString != "" {
182+
variables["assignee"] = assigneeString
192183
}
193184

194185
var resp struct {

command/issue_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,34 @@ func TestIssueList_withFlags(t *testing.T) {
150150
eq(t, reqBody.Variables.States, []string{"OPEN"})
151151
}
152152

153+
func TestIssueList_nullAssigneeLabels(t *testing.T) {
154+
initBlankContext("OWNER/REPO", "master")
155+
http := initFakeHTTP()
156+
157+
http.StubResponse(200, bytes.NewBufferString(`
158+
{ "data": { "repository": {
159+
"hasIssuesEnabled": true,
160+
"issues": { "nodes": [] }
161+
} } }
162+
`))
163+
164+
_, err := RunCommand(issueListCmd, "issue list")
165+
if err != nil {
166+
t.Errorf("error running command `issue list`: %v", err)
167+
}
168+
169+
bodyBytes, _ := ioutil.ReadAll(http.Requests[0].Body)
170+
reqBody := struct {
171+
Variables map[string]interface{}
172+
}{}
173+
json.Unmarshal(bodyBytes, &reqBody)
174+
175+
_, assigneeDeclared := reqBody.Variables["assignee"]
176+
_, labelsDeclared := reqBody.Variables["labels"]
177+
eq(t, assigneeDeclared, false)
178+
eq(t, labelsDeclared, false)
179+
}
180+
153181
func TestIssueList_disabledIssues(t *testing.T) {
154182
initBlankContext("OWNER/REPO", "master")
155183
http := initFakeHTTP()

command/pr_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,14 @@ func RunCommand(cmd *cobra.Command, args string) (*cmdOut, error) {
5050
cmd.SetErr(&errBuf)
5151

5252
// Reset flag values so they don't leak between tests
53+
// FIXME: change how we initialize Cobra commands to render this hack unnecessary
5354
cmd.Flags().VisitAll(func(f *pflag.Flag) {
5455
switch v := f.Value.(type) {
5556
case pflag.SliceValue:
5657
v.Replace([]string{})
5758
default:
58-
if v.Type() == "bool" {
59+
switch v.Type() {
60+
case "bool", "string":
5961
v.Set(f.DefValue)
6062
}
6163
}

0 commit comments

Comments
 (0)