How to override default reviewers via scriptrunner
Asked by nisha:

Hi,

I have a repo in bitbucket that have default reviewers with minimum required = 1.

Those default reviewers are defined under Repository Settings -\> PULL REQUESTS -\> Default Reviewers.

In addition I have Dynamically add reviewers to pull requests listener that add another default users to the PR but those users are not considered as 1 required approval for the PRS  

How can I solve it?

Thanks


Answers:
author: Robert Giddings [Adaptavist]
body: Hi [@nisha](/t5/user/viewprofilepage/user-id/2878507) ,

Thank you for the post.

I am the Product Manager for ScriptRunner for Bitbucket.

First off, the native "Default reviewers" functionality found in Bitbucket's Repository Settings is independent from ScriptRunner for Bitbucket's "Dynamically Add Reviewers" or "Auto-Add Reviewers" (depending on which ScriptRunner feature you are using?).

An explanation as to why this is, is documented here: <https://docs.adaptavist.com/sr4bib/6.43.0/features/listeners/built-in-listeners/dynamically-add-reviewers-to-a-pull-request> and here: <https://docs.adaptavist.com/sr4bib/6.43.0/features/listeners/built-in-listeners/auto-add-reviewers-to-a-pull-request>

So, in order to resolve the issue you currently have, I would recommend the following:

1) Stop current use of the Bitbucket native "Default reviewers" functionality.

2) Use either ScriptRunner for Bitbucket's "Dynamically Add Reviewers" or "Auto-Add Reviewers". (Documentation links above).

3) Also use ScriptRunner for Bitbucket's "Require a Minimum Number of Approvers" as documented here: <https://docs.adaptavist.com/sr4bib/6.43.0/features/script-merge-checks/built-in-merge-checks/require-a-minimum-number-of-approvers>

However, one caveat to be aware of. ScriptRunner's "Require a Minimum Number of Approvers" currently will accept approval from any reviewer added to a Pull Request. I.e. those also added manually. Not just those reviewers added by ScriptRunner. This is something we might look to improve in the future.

In the meantime, does the proposed solution above meet your needs?

Kind regards,

Robert Giddings,

Product Manager, ScriptRunner for Bitbucket

comments: author: nisha
body: Hi [@Robert Giddings \[Adaptavist\]](/t5/user/viewprofilepage/user-id/1196283) thank you for your response.

What I did is as follow:

\* Use "Auto-Add Reviewers" for mandatory and default reviewers, no conditions always the same reviewers

\* Use "Dynamically Add Reviewers" for adding 3 more reviewers conditionally by files path

\* Use "Require a minimum number of approvers" set for 2

Want to make sure with you please that in this way PRs that do not include changes in specific files path will require 2 approvals according to the "Auto-Add Reviewers" script,

and PRs that do include changes in specific files will require 2 approvals according to the reviewers from both scripts "Auto-Add Reviewers" or "Dynamically Add Reviewers"

correct?

And another question what is the different between "Auto-Add Reviewers" and "Dynamically Add Reviewers"?

Thank you


author: Robert Giddings [Adaptavist]
body: Hi [@nisha](/t5/user/viewprofilepage/user-id/2878507) ,

I believe what you have said is correct. However you might like to create a test repository to confirm the set-up works as you'd like.

Regarding your question, ScriptRunner for Bitbucket has had the "Auto-Add Reviewers" feature for a long time. But it uses Form widgets to select a static list of reviewers.

Users like yourself wanted more conditional control over when reviewers were added to Pull Requests, so we added "Dynamically Add Reviewers", to give users more control.

The outcome of both scripts is the same. I.e. a list of reviewers that automatically populate the Pull Request create screen.

Hope that helps answer your query?

Kind regards,

Robert Giddings,

Product Manager, ScriptRunner for Bitbucket


author: M Bleyer
body: I have a PR with some Merge Checks and Listeners in ScriptRunner on Bitbucket Server.  
That works fine so far - when the PR is initially created, some people are added as mandatory and optional, depending on some conditions (e.g. frontend code versus backend code in the same git repo for example).

Now I would like to add additional reviewers **later**, e.g. in a second step - only AFTER at least one member of a first group of reviewers has approved a PR.

I explicitly don't want to add all the reviewers at once during PR creation (to reduce the noise in their inboxes), but want to update them later based on a condition.  

<br />

I did the same with Listener dynamically-add-reviewers-to-a-pull-request and a condition  
and the new additional mandatory reviewers get added to the PR  
e.g. by calling

```
addMandatoryUsers("user", "userB")
```

But they are then not added to the list of reviewers shown in the web UI e.g.  
/projects/PROJECTKEY/repos/REPOKEY/pull-requests/12345/overview  
in the top right and also get no email.  

Instead, the message is  
*userA and userB are mandatory reviewers for this pull request, they must be added as reviewers before this pull request can be merged.*   

So is there a way to add reviewers later, so that the show up in the reviewers list in the UI, and get notified automatically?  
It's very cumbersome for the PR creator to have to add them all manually.  

Note: the above is independant of who the actual approvers are, as I am checking that with custom merge checks.


Tags: bitbucket-cloud

cloud