-
Notifications
You must be signed in to change notification settings - Fork 8k
Description
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
- Create a PR in an organization repo. The organization should have two teams and the teams should be linked to the repo.
- Add one team as a reviewer:
gh pr edit 1 --add-reviewer myorg/team1. This one succeeds. - Add the second team:
gh pr edit 1 --add-reviewer myorg/team2. This one fails:'' not found. - 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.