Repository: cli/cli
File: api/queries_pr.go (Go)

Code before:
	}

	variables := map[string]interface{}{
		"id": githubv4.ID(assignableID),
	}
	if query != "" {
		variables["query"] = githubv4.String(query)
	} else {
		variables["query"] = (*githubv4.String)(nil)
	}

	var result responseData
	if err := client.Query(repo.RepoHost(), "SuggestedAssignableActors", &result, variables); err != nil {
		return nil, err
	}

	var nodes []struct {
		User struct {
			ID       string
			Login    string
			Name     string
			TypeName string `graphql:"__typename"`
		} `graphql:"... on User"`
		Bot struct {
			ID       string
			Login    string
			TypeName string `graphql:"__typename"`
		} `graphql:"... on Bot"`
	}

	if result.Node.PullRequest.SuggestedActors.Nodes != nil {
		nodes = result.Node.PullRequest.SuggestedActors.Nodes
	} else if result.Node.Issue.SuggestedActors.Nodes != nil {
		nodes = result.Node.Issue.SuggestedActors.Nodes
	}

	actors := make([]AssignableActor, 0, len(nodes)+1) // +1 in case we add viewer
	viewer := result.Viewer
	viewerLogin := viewer.Login
	viewerIncluded := false

	for _, n := range nodes {
		if n.User.TypeName == "User" && n.User.Login != "" {
			actors = append(actors, AssignableUser{id: n.User.ID, login: n.User.Login, name: n.User.Name})
			if query == "" && viewerLogin != "" && n.User.Login == viewerLogin {
				viewerIncluded = true
			}
		} else if n.Bot.TypeName == "Bot" && n.Bot.Login != "" {
			actors = append(actors, AssignableBot{id: n.Bot.ID, login: n.Bot.Login})
			if query == "" && viewerLogin != "" && n.Bot.Login == viewerLogin {
				viewerIncluded = true

Review comment (suggestion):
Now, I'm seeing this type, maybe we can move it to the top and reused it in `responseData` struct. WDYT?

Regardless of that, we can have the same reduction here as well:

```suggestion
	var nodes []struct {
		TypeName string `graphql:"__typename"`
		User struct {
			ID       string
			Login    string
			Name     string
		} `graphql:"... on User"`
		Bot struct {
			ID       string
			Login    string
		} `graphql:"... on Bot"`
	}
```

Code after:
	variables := map[string]interface{}{
		"id": githubv4.ID(assignableID),
	}
	if query != "" {
		variables["query"] = githubv4.String(query)
	} else {
		variables["query"] = (*githubv4.String)(nil)
	}

	var result responseData
	if err := client.Query(repo.RepoHost(), "SuggestedAssignableActors", &result, variables); err != nil {
		return nil, err
	}

	var nodes []struct {
		TypeName string `graphql:"__typename"`
		User struct {
			ID       string
			Login    string
			Name     string
		} `graphql:"... on User"`
		Bot struct {
			ID       string
			Login    string
		} `graphql:"... on Bot"`
	}

	if result.Node.PullRequest.SuggestedActors.Nodes != nil {
		nodes = result.Node.PullRequest.SuggestedActors.Nodes
	} else if result.Node.Issue.SuggestedActors.Nodes != nil {
		nodes = result.Node.Issue.SuggestedActors.Nodes
	}

	actors := make([]AssignableActor, 0, len(nodes)+1) // +1 in case we add viewer
	viewer := result.Viewer
	viewerLogin := viewer.Login
	viewerIncluded := false

	for _, n := range nodes {
		if n.TypeName == "User" && n.User.Login != "" {
			actors = append(actors, AssignableUser{id: n.User.ID, login: n.User.Login, name: n.User.Name})
			if query == "" && viewerLogin != "" && n.User.Login == viewerLogin {
				viewerIncluded = true
			}
		} else if n.TypeName == "Bot" && n.Bot.Login != "" {
			actors = append(actors, AssignableBot{id: n.Bot.ID, login: n.Bot.Login})
			if query == "" && viewerLogin != "" && n.Bot.Login == viewerLogin {
				viewerIncluded = true
			}
		}
	}