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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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

0 votes
Leo Community Leader Mar 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

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.

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

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.

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

@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!

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

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Trello

📹 What is a Trello board?

Hi, Atlassian Community! My name is Brittany Joiner and I am a Trello enthusiast and Atlassian Community Leader. I'll be sharing with you a series of videos with my top tips on how to best use Tre...

0 views 0 2
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you