Merge pull request #186 from github/issue-list-no-assignee

Fix `issue list` re: issues that have an assignee
This commit is contained in:
Nate Smith 2019-12-20 10:22:25 -06:00 committed by GitHub
commit 4ae1193684
3 changed files with 41 additions and 20 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()

View file

@ -50,12 +50,14 @@ func RunCommand(cmd *cobra.Command, args string) (*cmdOut, error) {
cmd.SetErr(&errBuf)
// Reset flag values so they don't leak between tests
// FIXME: change how we initialize Cobra commands to render this hack unnecessary
cmd.Flags().VisitAll(func(f *pflag.Flag) {
switch v := f.Value.(type) {
case pflag.SliceValue:
v.Replace([]string{})
default:
if v.Type() == "bool" {
switch v.Type() {
case "bool", "string":
v.Set(f.DefValue)
}
}