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,298,228
Community Members
 
Community Events
165
Community Groups

How Do I Sync PR Reviewer and Jira Assignee?

Hi Folks.

I'm looking for a solution for the following workflow.

  • User A is the ASSIGNEE of a jira ISSUE with the STATUS "In Progress"
  • User A submits a PR to Bitbucket and sets the REVIEWER value to User B
  • The associated Jira issue should automatically do the following:
    • Move the Status to "Code Review" (this is not a problem)
    • Change the issue ASSIGNEE to match the REVIEWER value, "User B" (this is the problem)
      • Note: we would like this to be dynamic, such that if the reviewer field is updated after creation, it will still sync in Jira.
    • When the PR is approved reassign back to the Requester (this is not a problem)

I'm guessing this is a webhook solution, but I'm a bit of a greenhorn when it comes to BB-Jira webhooks. Any suggestions would be much appreciated.

Thanks,

Shaye

1 answer

Hi Shaye,

I spent a while looking into this, and good news I think I have a solution.  Bad news, this solution is a bit complex to setup and not without its limitations.  But I will go into the benefits and drawbacks of this approach at the end.  In my example, I was using Bitbucket Cloud and a Jira Cloud site.

First, within Jira Cloud I went into the Project Settings > Automation.  In here I created a new automation rule.  That rule had a trigger of Incoming webhook.

When you choose that trigger type, find the Webhook URL: this will always start with a https://automation.atlassian.com address.  Copy that full address.

automation rule first part only.png

Leave that tab open, then open a new browser tab over in your Bitbucket site.  Go into Repository Settings > Webhooks.  Click the Add webhook button, and create a new webhook that Bitbucket will send.  Add the URL from step one to this URL field on this page, like so:

Screen Shot 2021-09-23 at 12.53.38 PM.png

In my case, I was only triggering this webhook when the Pull Request was created or Updated.  Save this webhook.

Return to the first tab with the Jira project automation rule still open.  In my rule I had to select the Execute this automation rule with "Issues provided running the following JQL search".

Screen Shot 2021-09-23 at 4.50.09 PM.png

and I set the JQL value to be a smart value of one of the webhooks payload attributes.  In my example, my project key is SCRUM.

issuekey = {{WebhookData.pullrequest.description.match("(SCRUM-[1-9][0-9]*)")}}

Note: I updated this JQL query since the initial answer was posted, as this one is more accurate.

In your case, you will need to replace that SCRUM with the project key of your project.

 

Next, you need to create a new action in this automation rule.  Select the action called Assign issue.  From there you need to choose Smart value and enter a value of:

{{webhookData.pullrequest.reviewers.account_id}}

Screenshot of my configuration:

Screen Shot 2021-09-23 at 12.53.16 PM.png

Save the rule and publish it.  And that can make this possible.

(You can safely ignore the second action in my rule screenshot, I was just using the Add comment action to test out and make sure that my smart value was rendering the expected value before trying to set the Assignee)

 

Caveats of this approach:

  1. The biggest problem with this is that Jira's assignee field only permits a single value at a time.  But the Reviewers field in Bitbucket is an array of user accounts.  Meaning reviewers can potentially have multiple values here.  Jira can't handle that for the assignee field.  I'm honestly not sure what will happen if your reviewers contains more than one user account here.
  2. This automation doesn't take into consideration if the Reviewer is a member of this Jira site at all.  Nor does it check if the user has assignable permission.  If that user cannot be assigned to this issue either by permission restrictions or lack of product access, then this rule can't override that.
  3. The Pull request in this case has to contain only a single Jira issue key within the description.  If the PR has multiple Jira issues keys within it, this automation is only going to operate upon the first issue key it finds
  4. In my testing I only put the issue key in the Title of the PR.  I did not test out the Message body to see if perhaps adding the issue key there might not trigger the Jira automation.

 

In the process of researching this, I found a feature request for the desired functionality here:  JSWCLOUD-17281 Unfortunately, this has been closed as something that is not planned to be implemented within Jira Software Cloud.

I also found that Automation for Jira does have a feature request that seeks to add development user fields as smart values that Jira could then use.  See AUT-1997 for details.  If that request is someday implemented, it would likely make this much easier to achieve in automation without the need for a webhook at all.

 

Sorry there is not an easier way to set this up today.  But I agree that I can see how this could be useful.  I would suggest watching that AUT ticket, as that feature could make this kind of integration a better experience.

Let me know if you have any problems with this approach.

Cheers,

Andy

Suggest an answer

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

Git push size limits are coming to Bitbucket Cloud starting April 4th, 2022

Beginning on April 4th, we will be implementing push limits. This means that your push cannot be completed if it is over 3.5 GB. If you do attempt to complete a push that is over 3.5 GB, it will fail...

2,225 views 2 9
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