Set a default reviewer - github

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 ?

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.

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.

Related

Github organization member can't merge PR's even though he has write access

I have a protected github repository, where I want a user that was already allowed 'read' access to also be able to merge PR's, so I gave him the 'write' role. According to the github docs that should be enough. Still he is not able to merge, and he sees a warning about not having write access. Am I missing something?
As far as I know, when the private repo is yours and someone else opens a pull request to it, you as the owner have to merge the pull request in the respective branch.

Permission required so users can add Required Reviewer to Pull Requests

Members of my team sometimes need to add required Reviewers to their pull requests to ensure that a certain person actually performs the review.
We have a policy where a group of developers is automatically added to the pull request, which for 99% of the time is fine, but sometimes we need to add an extra person or 2.
There isn't a permission that is standing out explicitly showing which setting to use.
Any clues would be good
Looks like you are talking about this option. Some users are lacking it.
It's a new Pull Request Experience for Azure Repos. It should be the same permission to remove a required reviewer from Azure Devops
When you want to remove that required reviewer from the Automatically include code reviewers, you need to make sure someone who has the permissions to Edit policies (Project Administrators) to
Note: You need to check the Branch policies of the branch which you want to merge, for example, you merge from Dev to master, you need check the Branch policies of the master branch.
Then, after remove that required reviewer, you could go back to your pull request and click the X button:
So it should be the same let somebody to make required for reviewers. Try to assign them edit policy permission.
Hope this helps.

github CODEOWNERS: Disable email notifications for default owners

Is there a way to disable email notifications to the default owners configured in a github CODEOWNERS file?
In the code owners documentation, I can only find the following:
These owners will be the default owners for everything in
the repo. Unless a later match takes precedence,
#global-owner1 and #global-owner2 will be requested for
review when someone opens a pull request.
#global-owner1 #global-owner2
While I do want to have the default code owners, I don't want an email notification being sent out to each code owner for each push, review remark, review approval, merge, etc. It's to much spam and makes it easy to overlook important notifications, e.g., when someone is explicitly added as a reviewer or mentioned in a comment.
The CODEOWNERS notification system can not be turned off. But you can turn off all notification from a repository from the repository settings.

Merge PR by Github action if review was approved by a user

Is it possible to configure Github actions workflow to merge pull request if it was approved (submitted review with approve keyword) by one of the users (static fixed list, which can be written in workflow config file)? I tried to find it in documentation: https://help.github.com/en/articles/workflow-syntax-for-github-actions#on
- I suppose I can use on: [pull_request_review] trigger for action, but documentation didn't mention how to access event payload in action yaml file, where I need to extract reviewer login from this payload.
I found this in https://help.github.com/en/articles/virtual-environments-for-github-actions#filesystems-on-github-hosted-machines:
workflow/event.json: The POST payload of the webhook event that triggered the workflow. GitHub rewrites this each time an action executes to isolate file content between actions. Use the GITHUB_EVENT_PATH environment variable to access this file.
So the next step will be figuring out how to parse a JSON file and extract some data that a later step can use. For that, looking at GitHub's setup-dotnet action might prove useful. In line 62 of installer.ts, they call a function called core.exportVariable, which as you can see here, causes ##[set-env name=NAME;]value to be printed in the action's output. I've personally verified that this causes the environment variable called NAME to automatically be present in later steps of the same workflow job.
Now, I don't yet know if you can simply do echo "##[set-env name=NAME;]$VALUE" in a run step of a GitHub workflow and have that work; it's possible that you'll have to write a custom action in Typescript to get access to core.exportVariable. But once you have parsed the JSON, that would be one way of passing that information on to later steps in your job.
In addition of rmunn's answer, you might also want to protect your branch:
GitHub Actions: Prevent GitHub Actions from approving pull requests (2022, 14th Jan.)
We have introduced a new policy setting that controls whether GitHub Actions can approve pull requests.
This protects against a user using Actions to satisfy the "Required approvals" branch protection requirement and merging a change that was not reviewed by another user.
To prevent breaking existing workflows, Allow GitHub Actions reviews to count towards required approval is enabled by default.
However, an organization admin can disable it under the organization's Actions settings.
That way, you are sure approvals were made exclusively by users, not by other actions.

Adding default reviewers to Github repository

I followed the instructions here https://help.github.com/articles/about-codeowners/ but it doesn't seem to work. I even added the CODEOWNERS file at both the root and .github directory. The reviewers specified in the CODEOWNERS file are not selected automatically when a pull request is created. See screenshots below. Onyone who has set this up, could you point to where the problem is. Thank you.
You need to be sure that your base branch has:
the 'Protect this branch' flag activated
the 'Require pull request reviews before merging' flag activated
the 'Require review from Code Owners' flag activated
Then in the CODEOWNERS file, located either in the root of the repo or in the .github subfolder, you need to have either a user described with '#user', a user described with his email like 'user#domain.com', or a team described with '#org/teamname'.
You will need also to be sure that:
your contributors (users and teams) have for each of them the 'write' access to the repo
the team is not a 'secret' team, only the 'visible' teams would be taken into account
Double-check the CODEOWNERS file syntax
The pattern is followed by one or more GitHub usernames or team names using the standard #username or #org/team-name format.
(I don't see # in your case)
You can also refer to a user by an email address that has been added to their GitHub account, for instance user#example.com.
If the syntax is correct, then you can contact GitHub support to have them investigate.
The OP Pratheep actually find this is working:
You need the # and referring to my last screenshot above, you don't see the reviewers in the list when creating the PR.
But once the PR is created, then you will see the reviewers in the list.
I believe it was by design not to show. Because if you show the reviewers in that list before the PR is created, the names can be removed.
This way no one can create a PR without notifying the codeowners/default reviewers.