Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

ScriptRunner: How to add PR reviewers (including Mandatory Reviewers) programmatically

erikvdibble March 12, 2020

Hi,

I know how to add PR reviewers to Bitbucket using REST api, but I'd like to do it via ScriptRunner (b/c I want to Add Mandatory Reviewers as well)

So I am wondering how one can add a PR Reviewers using ScriptRunner programmatically, including Mandatory Reviewers,

Would it be a REST call from a 'Customer Event Handler' (on PullRequestOpen event)?

Best Regards

ED 

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
Leo
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 12, 2020

Hi @erikvdibble,

This is quite simple. scriptrunner has a built-in-function for the same

To achieve this Repository Settings --> Script Event Handlers -->  Add Reviewers to pull requests  --> fill the fields and add it 

Hope this helps

 

BR,

Leo

erikvdibble March 13, 2020

Thanks Leo.

I know that way. But that's what I want to avoid -- the UI.  We have so many events I'd prefer not having to add these manually. 

Looking for a way to do:

Repository Settings --> Script Event Handlers -->  Add Reviewers to pull requests  --> fill the fields and add it 

from a script.

Robert Giddings [Adaptavist]
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 23, 2020

Hi @erikvdibble ,

Does configuring the "Auto add reviewers to pull requests" event handler at the global admin level help reduce your manual workload? You don't need to configure this event handler for each Repo individually.

https://scriptrunner.adaptavist.com/latest/bitbucket/StashEventHandlers.html#_auto_add_reviewers_to_pull_requests

Please let me know if you still require help with a custom Event Handler?

Kind regards,

Robert Giddings,

Product Manager, ScriptRunner for Bitbucket

Sean Dukehart September 23, 2020

I have the same problem - we want to Auto-Add Reviewers based on naming patterns:

  • Based on some Bitbucket Server events (PullRequestOpenedEvent, PullRequestRescopedEvent)
  • Based on the PR including certain files
  • We'd like to add all members of a certain AD Group to the PR as Mandatory Reviewers

The "Auto add reviewers to pull requests" doesn't work, because for each Bitbucket Project, there's a different AD Group that should be the mandatory reviewers. Our use-case is that each Project has independent DBAs. So for certain changelog files, we need to add that Bitbucket Project's DBAs as Mandatory Reviewers.

Robert Giddings [Adaptavist]
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 25, 2020

Hi @Sean Dukehart ,

I believe that the current "Auto-Add Reviewers to Pull Requests" (https://scriptrunner.adaptavist.com/latest/bitbucket/StashEventHandlers.html#_auto_add_reviewers_to_pull_requests) implementation for ScriptRunner for Bitbucket should answer your requirements, except responding to the PullRequestRescopedEvent I believe.

You should be able to use the "Condition" field to address the point about the PR containing certain files.

And you should be able to set up different "Auto-Add Reviewers to Pull Requests" listeners for each set of Projects that needs a different set of Mandatory reviewers.

If the built-in listener still does not meet all your requirements, ScriptRunner for Bitbucket gives you the ability to create your own event listeners (https://scriptrunner.adaptavist.com/latest/bitbucket/StashEventHandlers.html#_working_with_custom_listeners) allowing you to do pretty much anything you want directly with the Bitbucket API.

I hope this helps answer your question?

If you need any additional help, please let me know?

Kind regards,

Robert Giddings,

Product Manager, ScriptRunner for Bitbucket

Sean Dukehart September 25, 2020

@Robert Giddings [Adaptavist] - thanks for the input. Unfortunately, setting up different "Auto-Add Reviewers to Pull Requests" listeners for each set of Projects that needs a different set of Mandatory reviewers isn't really feasible; there are just too many Projects for us to go about doing this.

Using the custom listener approach, the Bitbucket APIs don't seem to facilitate:

  • Mandatory Reviewers (not sure how ScriptRunner is able to convey certain reviewers can't be removed from the PR as it's being created; but it does and those reviewers show a little lock icon)
  • Augmenting Reviewers as the PR is being opened. PullRequestOpenRequestedEvent gives the ability to observe the PR at this point, but it doesn't appear that the reviewers can be changed from within those events since it hasn't actually been opened and there isn't an id.

However, the "Auto-Add Reviewers to Pull Requests" listeners do have these abilities. So does it utilize additional Adaptivist APIs or use different hooks?

Thanks!

Robert Giddings [Adaptavist]
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
October 9, 2020

Hi @Sean Dukehart ,

Sorry for the late reply.

I'm going to reach out to you privately so I can discuss your requirements in further detail with you.

Kind regards,

Robert Giddings,

Product Manager, ScriptRunner for Bitbucket

TAGS
AUG Leaders

Atlassian Community Events