Git Codeowners logic for multi team approvals

2k Views Asked by At

I am trying to figure out how to achieve the following behaviour using the CODEOWNERS file

  • github group '@myorg/devops` can approve all pull requests in the repo

  • github group '@myorg/devops' or group '@myorg/dev' can approve pull requests in dev1 and dev2 folders in the repo. This means one groups approval is sufficient.

Setup:

  • Repository has branch protection rule for 'master branch . This rule has 'Require review from Code Owners flag switched on

  • CODEOWNERS file saved in `.github/CODEOWNERS' and it has following content:

    *   @myorg/devops
    dev1/  @myorg/dev @myorg/devops
    dev2/  @myorg/dev @myorg/devops
    

Outcome:

When PR is done for files inside dev1 or dev2 folders, member of '@myorg/devops' approves it. Github however requests another approval from '@myorg/dev' group.

What am I doing wrong here?

1

There are 1 best solutions below

0
Serc On BEST ANSWER

Can you share a screenshot or error message?

According to the document "or" statement works

# In this example, any change inside the /scripts directory

# will require approval from @doctocat or @octocat.

/scripts/ @doctocat @octocat

By the way, it shouldn't matter if the owner is a user or a team.

# Teams can be specified as code owners as well. Teams should

# be identified in the format @org/team-name. Teams must have

# explicit write access to the repository. In this example,

# the octocats team in the octo-org organization owns all .txt files.

*.txt @octo-org/octocats

My guess is that branch protection rule in your repository is saying that 2 approvals are needed for a PR. See "Require approvals" section in this page