Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
Level
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Trying to retrieve email address of Pull Request author using API

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

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
Hana Kučerová Community Leader Oct 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.

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

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.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bitbucket

Calling any interview participants for Bitbucket Data Center

Hi everyone,  We are looking to learn more about development teams’ workflows and pain points, especially around DevOps, integrations, administration, scale, security, and the related challeng...

504 views 6 4
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you