How to create a reviewer group?
Asked by Karlen Kishmiryan:

Hi

I just learned about the CODEOWNERS. However, I'm struggling to achieve the functionality I need. That is, to **require** at least one approval from each user group for merging the PR (2 user groups, 2 approvals in total).

I have created a CODEOWNERS file, which has a single file pattern (\*) mapped to two user groups. When I create a PR, I can see that one person from each team gets randomly added to the PR as a reviewer. In my repo settings, I have a "merge to branch" restriction, which requires at least 2 approvals. However, it doesn't force the approvals to be exactly from the same two people who have been randomly selected. In case ANY two people approve it, then it can be merged (this is what I want to avoid).

I have also tried setting the restriction not on reviewers, but specifically on default reviewers. In this case it also didn't work, because the randomly selected two people never become part of the default reviewers "on-the-fly". So, even if they approve the PR, it's still pending on default reviewers' approvals.

Is there any way at all to achieve this behavior? Am I missing anything?

Thanks


Answers:
author: Ben
body: Hi Karlen,

The nature of code owners is that it will automatically assign users associated with the specific file path/pattern in your repository. When you use \* it will mean that any users defined here are owners of all file paths within your repository - hence why it is randomly assigning users from this pool.

I'd suggest more tightly defining paths to ensure that only certain users are added, rather than have this be random.

This is covered in our documentation:

* <https://bitbucket.org/blog/code-owners>

I would also suggest reviewing our custom merge checks documentation, as you may be able to write a Forge app to cover your merge check use case:

* <https://support.atlassian.com/bitbucket-cloud/docs/set-up-and-use-custom-merge-checks/>

If you need more support, please raise a support ticket using the Premium company workspace URL that you are a member of, as community is a public forum which is not appropriate to share potentially sensitive information regarding your repo/users inside:

* <https://support.atlassian.com/contact/#/>

If you have issues raising a support ticket, please let me know which timezone you are in so I may raise one on your behalf with a support team in your geolocation.

Cheers!

- Ben (Bitbucket Cloud Support)

comments: author: Karlen Kishmiryan
body: Hi Ben,  
Thank you for the reply.

My ultimate goal is to make sure that every change gets reviewed by two distinct teams before it can be merged. Who will review from each team is not important for me, hence I'm just specifying two user groups for all files with a random selection strategy.

I think the shortcoming to achieve this is in the merge check functionality. If the people, who are selected via CODEOWNERS would become **default reviewers** rather than just reviewers, then I could use the merge check based on default reviewers. It would force the approvals to be from these people only in order to proceed with merge. But it's not the case and as you mentioned, perhaps I'll need a Forge app to perform the logic I need. Unfortunately, at this point of time, we don't have a capacity to work on it. So I guess I'll just have to give up on this and look for other approaches.

Thanks


Tags: bitbucket-cloud

cloud