I am struggling to parse data from the Bitbucket REST API into smart values. What I am trying to do is to:
- get pullRequests from the Bitbucket (done),
- filter out irrelevant PRs by "name", looking for Jira key,
- print out the status of 1 (or more) relevant PR.
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!