Skip to content

'' not found error when adding/removing a team reviewer with gh pr edit #3705

@mercimat

Description

@mercimat

Describe the bug

According to the documentation of gh pr edit, the --add-reviewer and --remove-reviewer flags accept team users with the following format: myorg/team-slug.
If the PR doesn't have any team user specified in the "reviewers" section, the existing code works.
But if the PR already has a team user specified in the "reviewers" section, the gh pr edit 1 --add-reviewer myorg/other-team command fails with the error message: '' not found.

Steps to reproduce the behavior

  1. Create a PR in an organization repo. The organization should have two teams and the teams should be linked to the repo.
  2. Add one team as a reviewer: gh pr edit 1 --add-reviewer myorg/team1. This one succeeds.
  3. Add the second team: gh pr edit 1 --add-reviewer myorg/team2. This one fails: '' not found.
  4. Remove the first team: gh pr edit 1 --remove-reviewer myorg/team1. This one fails too: '' not found.

Expected vs actual behavior

--add-reviewer and --remove-reviewer flags should allow the user to update the reviewers field of a PR with users and teams. This should work whether or not there is already a user or a team reviewer.

Logs

There were no logs, except for the error message. I manually added printf in the code to debug and find the root cause. Here are my findings.
The error is returned by the TeamsToIDs function in api/queries_repo.go, because one element in names is an empty string.
The empty string is actually generated by the Logins function in api/queries_pr.go.
The Logins function uses the RequestedReviewer.Login attribute for both normal users and teams. But teams don't have a Login field (see Team graphql reference). So, when parsing an existing PR with a team as reviewer, the Logins function returns a list with an empty string element.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions