How to assign different numbers of Pull Request reviewers from different teams in GutHub

Viewed 196

In GitHub we have:

  • Two teams, say TeamA and TeamB.
  • Three repos: RepoA, RepoB and RepoCommon.

TeamA works mostly in RepoA, TeamB in RepoB and they share code in RepoCommon. A minimum of two reviewers are required for a PR in any repo. (The real-world use-case is iOS, Android and Kotlin Multiplatform shared code but I'll stick with A and B to keep it generic).

We'd like to have:

  • Two reviewers from TeamA assigned to any PR in RepoA
  • Two reviewers from TeamB assigned to any PR in RepoB
  • One reviewer from TeamA and one reviewer from TeamB assigned to any PR in RepoCommon

By setting the Required Reviewers number for each team to 2, and adding both teams to the CODEOWNERS file (i.e. * @TeamA @TeamB) the common PRs get assigned 4 reviewers, preferentially showing only two from whichever team happens to be first in CODEOWNERS. If we set the Required Reviewers to 1 the Common repo receives the correct number but the team-specific repositories only receive a single reviewer. How can we have the best of both worlds?

1 Answers

By creating child teams with different Required Reviewers numbers to those of their parents and using these child teams in the Common CODEOWNERS it's possible to achieve the required split with minimal maintenance overhead. The team-specific repos' CODEOWNERS keep the parent teams.

Couple of caveats: You don't see the reviewers until the PR has actually been created (i.e. they don't appear in the Suggestions), and a refresh of the page seems to be required to show them properly, even though they have been assigned correctly. User education around GitHub's behaviour is sufficient in this case.

Related