Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Automation: update issue with multiple reviewers from Github Webhook

Vincent January 8, 2024 edited

Desired situation:

on Github someone adds 1 or more people as reviewers to a PR, I want this to reflect in the Jira ticket

What already works:

- I get the correct issue from the PR titlte
- I can add a single reviewer

What doesn't work:

I cannot add multiple reviewers.

I have a lookup table to map github username to jira user id, which works for single users just fine. But I can't get it to work for multiple users, I tried:

- Just putting the whole array in the LUT `{{githubToJiraUsers(webhookData.pull_request.requested_reviewers.login)}}`
- Putting single values in the LUT `{{#githubToJiraUsers(webhookData.pull_request.requested_reviewers}}{{githubToJiraUsers({{login}})}}{{/}}`
- Use the for-each functionality of automation to update a variable
- Use the for-each functionality to update the issue directly with the current reviewer (removes the current reviewers already in the Issue AND only adds the last one)
- Use the for-each to do advanced field updating with JSON and use "update" (cannot get this to work)

Two of my many JSON attempts:

{
"update": {
"reviewers": {
"update": {{githubToJiraUser(login)}}
},
},
}

 and

{
"update": {
"reviewers": [{
"add": "{{githubToJiraUser(login)}}"
}],
},

Json attempt:

Screenshot 2024-01-11 at 08.50.23.png

Attempt with smart values list

Screenshot 2024-01-11 at 09.07.04.png

I tried the smart value list in 2 ways:

Screenshot 2024-01-11 at 09.14.41.png

These re the logs of those 2:

Screenshot 2024-01-11 at 09.15.33.png

 

If anyone has any ideas how to approach this, help is greatly appreciated.

 

11-01-2024: (edited with screenshots)

1 answer

0 votes
Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 8, 2024

Hi @Vincent -- Welcome to the Atlassian Community!

For a question like this, please post an image of your complete automation rule, images of any relevant actions / conditions / branches, an image of the audit log details showing the rule execution, and explain what is not working as expected.  Those will provide context for the community to offer ideas.  Thanks!

Until we see those...

I hypothesize you are trying to branch over the reviewers in the webhookData to add them one by one.  And so there could be a problem in either parsing the reviewers or the branch handling.  Seeing the rule may confirm this.

Kind regards,
Bill

Vincent January 11, 2024

Hi @Bill Sheboy 

I updated the question! I hope I supplied enough additional information :)

Thank you for your time and help!

Kind regards,
Vincent

Vincent January 11, 2024

About the branching, when I do a loop and just set the users one by one, only the last one is saved, since "edit issue" overrides the current value.

When I do new user + {{issue.reviewers}} it only adds 1, because it seems like issue.reviewers is not updated on each iteration...

screenshot:

Screenshot 2024-01-11 at 09.21.11.png

Bill Sheboy
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 11, 2024

Thanks for those additional details, and your observation about the branching is correct:

Branches which could be on more-than-one-thing are executed in parallel and asynchronously.  There is no guarantee of when the branch will complete, up to the end of rule processing.  Please look here to learn more: https://support.atlassian.com/cloud-automation/docs/jira-automation-branches/#Ordering-of-branch-executions  There is a suggestion to add an option for sequential versus parallel rule execution, and you may watch it to see any updates: https://jira.atlassian.com/browse/AUTO-32

What this means for your rule is the edits repeatedly walk-over the Reviewers, and there is no way to predict what values will be in there when the rule completes.

The work-arounds to ensure your rule behaves as expected are:

  1. Perform one single edit.  The way to do this is to build a JSON expression for adding (or setting) reviews, and chain together repeated replace() function calls to substitute the Jira user accountId values for the github ones.  Then use that expression in a single advanced edit.
  2. Build a service (with a language with sequential processing) to call the REST API to edit the issues, and then call that new service from the rule.

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events