X Tutup
Skip to content

Commit 00cede9

Browse files
committed
Fix issue list re: issues that have an assignee
Given the GraphQL query: issues(filterBy: {assignee: $assignee}) It turns out that passing a query variable `"assignee": null` is NOT equivalent to omitting the variable altogether: - `"assignee": null` seems to filter out issues that HAVE an assignee; - omitting `assignee` correctly returns all issues.
1 parent cbecae7 commit 00cede9

File tree

2 files changed

+38
-19
lines changed

2 files changed

+38
-19
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()

0 commit comments

Comments
 (0)
X Tutup