I am struggling to parse data from the Bitbucket REST API into smart values. What I am trying to do is to:
I have webRequest like this
webhookResponse.body.detail.pullRequests: [
{ author: a, name: "ABCD", ..., status: "OPEN" }
{ author: b, name: "DEFG", ..., status: "OPEN" }
]
I want the status of "ABCD" PR only.
Now the issues.
1.
If I do "advanced branching", smart value = {{webhookResponse.body.detail.pullRequests.status}}
as variable "PR", log action "PR: {{PR}}", it will produce
PR: OPEN, OPEN
That means it did NOT iterate over the list, but rather joined it to a string?
2. if I do
log action: "distinct: {{webhookResponse.body.detail.pullRequests.status.distinct}}"
it will produce
distinct: [OPEN, OPEN]
does it mean it's a string, not a list?
3. if I do
log action: "substring: {{webhookResponse.body.detail.pullRequests.status.substring(3)}}"
to test for a string, it will produce
substring: []
So it is NOT a string.
4. if I do
log action: "match: {{webhookResponse.body.detail.pullRequests.status.match("(.*)")}}"
it will produce
match: []
So no luck.
5. If I do
log action: "splitted: {{webhookResponse.body.detail.pullRequests.status.split(",")}}"
or
log action: "splitted: {{#webhookResponse.body.detail.pullRequests.name.split(",")}} {{.}} {{/}}"
It will produce
splitted: []
Which contradicts the earlier "distinct: [OPEN, OPEN]"
6. If I do
log action: "name-status: {{#webhookResponse.body.detail.pullRequests}} {{name}}-{{status}}, {{/}}"
it will produce
name-status: ABCD, DEFG-OPEN, OPEN,
However I would expect it to produce
ABCD-OPEN, DEFG-OPEN
But I think I missing something here.
Ultimately I want to do either:
1. Smart branching and iterate over {{webhookResponse.body.detail.pullRequests}} = PR
Then check if {{PR.name}} contains "ABCD" and return {{PR.status}}.
I would need the whole pull request as a variable, not just one property like "name".
or
2. Variable
{{#webhookResponse.body.detail.pullRequests}}
{{#if(name.match("(ABCD)")}} {{status}} {{/}} {{/}}
Which would simply give me the status.
Any help appreciated!
OK, I cracked it after 2 days.
webhookResponse.body.detail.pullRequests is actually an array of an array, so you need to iterate over
{{webhookResponse.body.detail.pullRequests.get(0)}} as PR
and then you can do
if {{PR.name}} contains "ABCD", do whatever.
Hi @Pavel __ Helia -- Welcome to the Atlassian Community!
I am glad to learn you found an expression that works for you.
As you discovered in automation rules, sometimes nested lists get implicitly converted to arrays...which then totally breaks use in many functions and iterators. Another example of this is the Sprint field within a list of issues, such as Lookup Issues.
Often the only solution is to serialize the objects into a created variable in a known format with delimiters, use a dynamic match() expression to extract the target, and then convert types (as needed) to get the data.
Kind regards,
Bill
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.