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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,558,986
Community Members
 
Community Events
184
Community Groups

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
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
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.

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.
Mar 23, 2020 • edited Sep 25, 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

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.
Sep 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

@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.
Oct 09, 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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events