Forums

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

Trying to retrieve email address of Pull Request author using API

Josh Berry October 17, 2019

I am using Adpatavist ScriptRunner.

I want to get the email address of whoever raised a pull request, as part of an Event Handler (so it can be sent on to Jenkins)

This is the code I have got to:

PullRequestOpenRequestedEvent event = (PullRequestOpenRequestedEvent)event

def pullRequest=event.getPullRequest()
def email = pullRequest.getAuthor().getUser().getEmailAddress()

 If I just look a the pull request in JSON via the API I can see the email address I want to get

"author": {
"user": {
"name": "myname",
"emailAddress": "myname@test.com",

However, when I do this I get the following error in the logs:

192.168.1.1,127.0.0.1 "POST /projects/XXX/repos/YYY/pull-requests HTTP/1.1" c.o.s.b.DynamicEventListenerInvoker Event handler failed: event: com.atlassian.bitbucket.event.pull.PullRequestOpenRequestedEvent file: <inline script>
java.lang.IllegalStateException: Pull request author could not be found in its participants
                at com.atlassian.stash.internal.pull.InternalPullRequest.getAuthor(InternalPullRequest.java:192)
                at com.atlassian.bitbucket.pull.PullRequest$getAuthor.call(Unknown Source)
                at Script937.run(Script937.groovy:20)

 Participants is an empty object in the API, and never seems to have anything in it (even when I add reviewers etc)

Am I just missing something fundamental with the API calls? Is my Bitbucket server configured incorrectly?

Any ideas appreciated

3 answers

1 accepted

0 votes
Answer accepted
Josh Berry October 18, 2019

For anyone else who happens across this, I had the location of getUser within the API incorrect, I got it working using the following:

PullRequestOpenEvent event = (PullRequestOpenEvent)event
def email = event.getUser().getEmailAddress()
0 votes
Yogesh Mude
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.
September 24, 2020

Hi @Josh Berry 

Hope you are doing well.

I am looking to update/set the pull request merge commit author as the Original author (pull request open author or developer).

Usually, the developer who (he/she)  worked on the branch will open the pull request and add the reviewers (senior developer/ team lead) to review the pull request changes. Once reviewer reviews or accepts the changes and merge the pull request to Master branch with commit message but the commit author will set as reviewer (because he/she is the one who commit).

So my question is here ...i want to set the pull request merge commit author should set to teh open pull request author.

I am able to get the autoer details using the PullRequestMergeEvent so now i want to compare it to original author and then set it.

Do you have any sample script code to update the pull request commit?

Thanks in advance.

0 votes
Hana Kučerová
Community Champion
October 17, 2019

Hi Josh,

to be able to obtain an email address of a pull request author, you have to send GET request to URL: /rest/api/1.0/projects/{projectKey}/repos/{repositorySlug}/pull-requests/{pullRequestId}

According to log it seems to me, that you are sending POST request and also there is no pull request id in the url.

Josh Berry October 18, 2019

Ah, GET vs POST might be the bit of information I was missing. Thanks very much, a new path to go down

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events