CODEOWNER Required Reviews #22522
-
I’ve got a repository with 3 total collaborators, and the master/dev branches are set up to be:
Now, as I understood things, my open PR towards the dev branch should request a review from all Code Owners, but a single approved review should be enough to review. My PR automatically requested review from the other two collaborators, since both are Code Owners. So far, so good. One of them requested changes, which we discussed, made, and then approved. So the current status of his review is “approved”–yet this is not enough to merge the PR? The status box says Code owner review required Required statuses must pass before mergingAll required status checks on this pull request must run successfully to enable automatic merging. There are no status checks enabled (beyond required reviews), and I have at least one approved review, so I fail to see why the merge button didn’t turn that shiny Green (I have full privilege on the repo, so presumably I can merge when the review is approved). Is there any way to make sure at least one approved review is enough to merge the PR, or is this one of those “since it’s your PR you can’t merge it” things? |
Beta Was this translation helpful? Give feedback.
Replies: 19 comments 1 reply
-
It’s hard to say why you’re experiencing this behavior without some more information. Is the repository in question public? Can you share a link to a specific PR that is behaving in a way that you believe is not expected? Assuming that the repository in question is private, I can guess at one reason why more than one reviewer might be required. Let’s say you have a CODEOWNERS like the following:
In this case, any PR would require one (and only one) of those three people to approve it before it could be merged. But let’s say you have a more complex CODEOWNERS file:
And you submit a PR that includes both a JavaScript change as well as a change to some associated documentation. That PR would require one of either foo or bar to approve it for the JavaScript change and a separate approval from baz for the documentation. Maybe you could share just your CODEOWNERS file? |
Beta Was this translation helpful? Give feedback.
-
I figured it out; it was similar to what you describe below, where my changes were targeting two different patterns, requiring a review from two separate people to approve each change. Thanks for your help! |
Beta Was this translation helpful? Give feedback.
-
Elsewhere you have said you can specify code owners for specific branches. Can you please give an example? |
Beta Was this translation helpful? Give feedback.
-
There is an example in the CODEOWNERS help documentation. Let us know if you have any questions about it. |
Beta Was this translation helpful? Give feedback.
-
hey @lee-dohm I don’t see any code example. I found a blurb about branches, but nothing telling us how
on the docs page; what does an actual branch reference look like? would we have a new CODEOWNERS file per branch, or would we have the same CODEOWNERS file with all the branches and reviewers listed? |
Beta Was this translation helpful? Give feedback.
-
It’s probably better explained by saying that the one CODEOWNERS file has different contents per branch. So if there is one rule in the file on the |
Beta Was this translation helpful? Give feedback.
-
“In this case, any PR would require one (and only one) of those three people to approve it before it could be merged” Is there any way to require all of the listed people to approve? |
Beta Was this translation helpful? Give feedback.
-
No, there currently isn’t a way to do that built-in to the CODEOWNERS feature. If that was the one and only rule, you could do a hacky solution where you required a PR to have three approvals to be merged but if the CODEOWNERS contents ever changed, you would have to remember to manually update the number of required reviews. So it isn’t something I would recommend as a solution to the question you’re asking. |
Beta Was this translation helpful? Give feedback.
-
Is there a way to make it so the universal code owner can approve PRs to subdirectories that also have code owners. For example:
Let’s say someone does a PR to the I realize I can work around this by adding foo as an owner to |
Beta Was this translation helpful? Give feedback.
-
I can understand the rationale behind what you’re describing. However, that isn’t how the feature is currently implemented. But even if the rules were additive as you describe, it wouldn’t only notify For workflows customized to your particular development team, I would recommend investigating Probot or GitHub Actions to see if either of them can help you build a solution to fit your team’s needs. |
Beta Was this translation helpful? Give feedback.
-
So how do you avoid the PR merge from one branch to another overwrite the CODEOWNERS file with different content? |
Beta Was this translation helpful? Give feedback.
-
update the .gitignore file in all branches to include CODEOWNERS and from there you can specify different codeowners that won’t overwrite on merge |
Beta Was this translation helpful? Give feedback.
-
Bumping this: @lee-dohm |
Beta Was this translation helpful? Give feedback.
-
I’m not sure why you’re bumping this @logankilpatrick. |
Beta Was this translation helpful? Give feedback.
-
Hey! Sorry, it does not look like my bump was in the right place, but the final question on the thread was whether and how you could set it up such that you require multiple code owners to approve the PR. Thanks! |
Beta Was this translation helpful? Give feedback.
-
My post on 28 November, 2019 is in response to the question about how to require multiple owners to review a PR before it could be merged. As I stated in my post above, if the current CODEOWNERS implementation isn’t what you’re looking for, then I’d suggest investigating Probot or GitHub Actions to see if they’ll allow you to model the workflow you do want. I hope that helps! |
Beta Was this translation helpful? Give feedback.
-
A related question @lee-dohm: what happens if I require more PR approvals than there are code owners? Our use case: we want to require code owner review on a specific file. e.g CODEOWNERS file:
From my understanding, these 3 users would be codeowners for that file but if a PR doesn’t touch that file, there are 0 code owners. In this situation, is Github’s logic smart enough to not require approvals on a PR that only touches files without any owners? Or would every PR still require 3 approvals? Thanks in advance! |
Beta Was this translation helpful? Give feedback.
-
Great question @samajammin 👍 Requiring a specific number of reviews means that every PR must have that number of reviews before it can be merged. The logic will not forego requiring a PR review on PRs that have no files covered by
samajammin:
As I mentioned above, the general solution to having any sort of custom check logic that allows or prevents merging PRs is to use GitHub Actions or some similar system like Probot. |
Beta Was this translation helpful? Give feedback.
-
Hi @lee-dohm I’d like to ask the situation when PR matches multiple distinguished rules. Said that we have a
If someone make a PR touches both JS files and docs folder, is GitHub choose only |
Beta Was this translation helpful? Give feedback.
It’s hard to say why you’re experiencing this behavior without some more information. Is the repository in question public? Can you share a link to a specific PR that is behaving in a way that you believe is not expected?
Assuming that the repository in question is private, I can guess at one reason why more than one reviewer might be required. Let’s say you have a CODEOWNERS like the following:
In this case, any PR would require one (and only one) of those three people to approve it before it could be merged. But let’s say you have a more complex CODEOWNERS file:
And you submit a PR that includes both a JavaScript change as well as a change to…