82

I do pull requests in a repo where it's always the same person reviewing. I would like to set him as the default reviewer so that I don't always have to choose him at each pull request, it'd be automatic. How to do that ?

1
  • Not aware of the marking a default Reviewer. But if tagging a default person can work in your PR that is feasible.
    – Naman
    Commented Sep 21, 2017 at 9:40

3 Answers 3

104

GitHub has the ability to set the default reviewer using a CODEOWNERS file.

Code owners are automatically requested for review when someone opens a pull request that modifies code that they own. When someone with admin permissions has enabled required reviews, they can optionally require approval from a code owner.

To use a CODEOWNERS file, create a new file called CODEOWNERS in the root, docs/, or .github/ directory of the repository, in the branch where you'd like to add the code owners.

4
  • I tried this on GitHub Enterprise Server 2.18.4 and it didn't seem to work. Commented Oct 21, 2019 at 22:13
  • It looks like it should be supported- help.github.com/en/enterprise/2.18/user/…. Their support should be able to help
    – osowskit
    Commented Oct 22, 2019 at 2:33
  • Correct link for CODEOWNERS info
    – Shadoath
    Commented May 13, 2022 at 14:55
  • And why I set, when I can't a code owner, but um default, with on all time need review, type a new dev on the team, I'd like if here review for understand more, but on all time I need set with is review. Commented Jul 18, 2023 at 13:49
47

You should add .github/CODEOWNERS file with users to send PR to.

Example to send PR for any change on codebase represented by *:

## code changes will send PR to following users
* @option1-user1 @option1-user2 @option2-your-org/team-name

See: https://docs.github.com/en/enterprise/2.18/user/github/creating-cloning-and-archiving-repositories/about-code-owners

Note: .github/CODEOWNERS should be in main branch to be effective.

3
  • The same answer was given 4 years ago...
    – Cjmarkham
    Commented Dec 30, 2021 at 23:03
  • 20
    @Cjmarkham True, but this answer offers better details and is more to the point. The current accepted answer is just a huge block quote. Commented Jan 10, 2022 at 15:50
  • Worked for me. However, not on intermediate branches such as develop, uat
    – daydreamer
    Commented Jan 18 at 20:50
1

When initiating a new pull request, Bitbucket automatically scans for the presence of a CODEOWNERS file in the .github directory of the repository.

You can specify the number of reviewers to select and define the selection criteria. Here are some examples of how this syntax can be used.

.github/CODEOWNERS

                    # .bitbucket/CODEOWNERS
            
                    # Default reviewers for files not matching patterns below
                    *      [email protected] [email protected]
            
                    # Choose all members of a workspace group
                    *.js   @workspace-idk/frontenders:all
            
                    # Choose group members tagged on the fewest open PRs
                    *.py   @workspace-be/backenders:least_busy(2)
            
                    # Choose randomly from a custom team (defined in teams.yaml)
                    *.tf   @teams/sre-leads:random(2)

Not the answer you're looking for? Browse other questions tagged or ask your own question.