How to get pull request creator / author as a smart value in Jira automation?
Asked by Meghanand Baraskar:

I am trying to have a rule wherein if the ticket isn't in the correct status when the pull request is created, a comment is added addressing the pull request creator to transition the ticket in correct status. However, I am unable to derive the name of the pull request creator using smart value tags. I tried {{pullRequest.creator}}, {{pullRequest.author}}, {{issue.development.pullRequest.creator}} and so on but with no success


Answers:
author: Alexis Robert
body: Hi [@Meghanand Baraskar](/t5/user/viewprofilepage/user-id/1529722) ,

I recently had the same issue with another question : <https://community.atlassian.com/t5/Jira-Software-questions/Automation-Trigger-Who-Runs-Flow/qaq-p/1586669>

The answer is : not possible yet, but there's a feature logged for this <https://codebarrel.atlassian.net/browse/AUT-1997>

Let me know if this helps,

--Alexis


author: Darryl Lee
body: It's a little ugly, but I *think* you could do a Web Request to get this.

You'd need to take your {{pullRequest.url}} and use some text manipulations to change it into the appropriate API call (depends on your Git server - you'd also have to set up a service account/token etc etc). For Bitbucket Server, this seemed to work:

```
$SERVER/rest/api/latest/projects/$PROJECT/repos/$YOURREPO/pull-requests/4
```

This returned a nice bit of JSON, and you would then be able access the User account, display name, and email thusly:

```
{{webhookResponse.body.author.user.name}}
{{webhookResponse.body.author.user.displayName}}
{{webhookResponse.body.author.user.emailAddress}}
```

comments: author: Meghanand Baraskar
body: Thank you [@Darryl Lee](/t5/user/viewprofilepage/user-id/1365322) for your response. I am however, not quite familiar with how to go about doing what you have suggested. We too are using Bitbucket but I don't know what I can do with the URL I get from {{pullRequest.url}}


author: Darryl Lee
body: Hi, sorry, I should have provided some references and a little more explanation.

What I'm cavalierly suggesting (without testing) is that you use the [Send outgoing web request](https://support.atlassian.com/jira-software-cloud/docs/automation-actions/#Automationactions-Sendoutgoingwebrequest) action to talk to the [Bitbucket API](https://developer.atlassian.com/bitbucket/api/2/reference/) which contains a call that should let you get information about a Pull Request.

The idea is that you'd take the {{pullRequest.url}} and use some of the [Smart Value text functions](https://support.atlassian.com/jira-software-cloud/docs/smart-values-text-fields/) to rewrite it into a URL that you could use to make a call to the the Bitbucket API to obtain the Author info.

So if {{pullRequest.url}} is this:

```
https://YOURSERVER/projects/YOURPROJECT/repos/YOURREPO/pull-requests/7
```

You could a use:

    {{pullRequest.url.replace("/projects/","/rest/api/latest/projects/")}}

To get to:

```
https://YOURSERVER/rest/api/latest/projects/YOURPROJECT/repos/YOURREPO/pull-requests/4
```

So you would put that bit with the replace into the Webhook URL field.

The trick here is that to talk to your Bitbucket server, you'll need to be authenticated.

I found [this old post](https://stackoverflow.com/questions/49116873/basic-auth-not-working-when-trying-to-get-raw-contents-from-bitbucket) that makes it sound like Basic Auth should work with username/password, but you really should instead create a [Personal Access Token](https://confluence.atlassian.com/bitbucketserver/personal-access-tokens-939515499.html).

ANYWAYS, once you set up a token, you'll follow steps similar to these:

[Automation for Jira - Send web request using Jira REST API](https://community.atlassian.com/t5/Jira-articles/Automation-for-Jira-Send-web-request-using-Jira-REST-API/ba-p/1443828)

But instead of the Jira REST API, you'll be talking to the Bitbucket API, again, using the generated URL above.

Here's another good reference to what we're trying to do here, although in this example, they don't need to deal with authentication:

[Send Web Request Action now Provides Response Data](https://blog.codebarrel.io/new-feature-send-web-request-action-now-provides-response-data-9551934ed3c9)

Anyways, unfortunately this is all theoretical. I don't have any projects with active Pull Requests where I can test this kind of thing. Has anyone else ever done this in real life?


Tags: cloud