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

Code before:
		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
			}
		}
	}

	// When query is blank, append viewer if not already present.
	if query == "" && viewerLogin != "" && !viewerIncluded {
		actors = append(actors, AssignableUser{id: viewer.ID, login: viewer.Login, name: viewer.Name})
	}
	return actors, nil
}

func UpdatePullRequestBranch(client *Client, repo ghrepo.Interface, params githubv4.UpdatePullRequestBranchInput) error {
	var mutation struct {
		UpdatePullRequestBranch struct {
			PullRequest struct {
				ID string
			}
		} `graphql:"updatePullRequestBranch(input: $input)"`
	}
	variables := map[string]interface{}{"input": params}
	return client.Mutate(repo.RepoHost(), "PullRequestUpdateBranch", &mutation, variables)
}

func isBlank(v interface{}) bool {
	switch vv := v.(type) {
	case string:
		return vv == ""
	case []string:
		return len(vv) == 0
	default:
		return true

Review comment (bug):
Please correct me if I'm wrong. We add the viewer to the actors if it's not a search/query call. If it's a search call, we just don't do anything and let the viewer be there if it's returned by the API.

I can imagine this is related to the interactive experience, where we want to always display the viewer by default, right? If yes, then I can think of two things:

1. Since this is a UX kind of decision, why not just returning the viewer as a separate return value and let the caller handle the rest?
2. This manual addition of the viewer implies that we are certain that the viewer can be assigned to the issue/PR. It's probably right, because otherwise I'd expect the API to return an unauthorised error when we fetched the actors, but still it feels like it's a bit out of `gh` scope to assume this.

Let me know what do you think.



Code after:
	}

	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
			}
		}
	}

	// When query is blank, append viewer if not already present.
	if query == "" && viewerLogin != "" && !viewerIncluded {
		actors = append(actors, AssignableUser{id: viewer.ID, login: viewer.Login, name: viewer.Name})
	}
	return actors, nil
}

func UpdatePullRequestBranch(client *Client, repo ghrepo.Interface, params githubv4.UpdatePullRequestBranchInput) error {
	var mutation struct {
		UpdatePullRequestBranch struct {
			PullRequest struct {
				ID string
			}
		} `graphql:"updatePullRequestBranch(input: $input)"`
	}
	variables := map[string]interface{}{"input": params}
	return client.Mutate(repo.RepoHost(), "PullRequestUpdateBranch", &mutation, variables)
}

func isBlank(v interface{}) bool {
	switch vv := v.(type) {
	case string:
		return vv == ""
	case []string:
		return len(vv) == 0
	default:
		return true
	}
}