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.
This commit is contained in:
Mislav Marohnić 2019-12-20 13:07:11 +01:00
parent cbecae73b7
commit 00cede9e5f
2 changed files with 38 additions and 19 deletions

View file

@ -154,19 +154,6 @@ func IssueList(client *Client, ghRepo Repo, state string, labels []string, assig
return nil, fmt.Errorf("invalid state: %s", state)
}
// If you don't want to filter by lables, graphql requires you need
// to send nil instead of an empty array.
if len(labels) == 0 {
labels = nil
}
var assignee interface{}
if len(assigneeString) > 0 {
assignee = assigneeString
} else {
assignee = nil
}
query := fragments + `
query($owner: String!, $repo: String!, $limit: Int, $states: [IssueState!] = OPEN, $labels: [String!], $assignee: String) {
repository(owner: $owner, name: $repo) {
@ -183,12 +170,16 @@ func IssueList(client *Client, ghRepo Repo, state string, labels []string, assig
owner := ghRepo.RepoOwner()
repo := ghRepo.RepoName()
variables := map[string]interface{}{
"limit": limit,
"owner": owner,
"repo": repo,
"states": states,
"labels": labels,
"assignee": assignee,
"limit": limit,
"owner": owner,
"repo": repo,
"states": states,
}
if len(labels) > 0 {
variables["labels"] = labels
}
if assigneeString != "" {
variables["assignee"] = assigneeString
}
var resp struct {

View file

@ -150,6 +150,34 @@ func TestIssueList_withFlags(t *testing.T) {
eq(t, reqBody.Variables.States, []string{"OPEN"})
}
func TestIssueList_nullAssigneeLabels(t *testing.T) {
initBlankContext("OWNER/REPO", "master")
http := initFakeHTTP()
http.StubResponse(200, bytes.NewBufferString(`
{ "data": { "repository": {
"hasIssuesEnabled": true,
"issues": { "nodes": [] }
} } }
`))
_, err := RunCommand(issueListCmd, "issue list")
if err != nil {
t.Errorf("error running command `issue list`: %v", err)
}
bodyBytes, _ := ioutil.ReadAll(http.Requests[0].Body)
reqBody := struct {
Variables map[string]interface{}
}{}
json.Unmarshal(bodyBytes, &reqBody)
_, assigneeDeclared := reqBody.Variables["assignee"]
_, labelsDeclared := reqBody.Variables["labels"]
eq(t, assigneeDeclared, false)
eq(t, labelsDeclared, false)
}
func TestIssueList_disabledIssues(t *testing.T) {
initBlankContext("OWNER/REPO", "master")
http := initFakeHTTP()