Creating stash pull request programmatically

I want to create a pull request automatically once a new branch is added to a project. My script will take a reviewer's name and branch name and will create a branch on stash repository using git command. Is there a way for me to create a pull request through my script?Is there a stash client in similar lines as jira client? Or can it be done using stash RestAPI or Java API?

2 answers

This widget could not be displayed.

Hi Vikas,

Personally I would do this as a Stash plugin. Here is an example of a plugin that acts as a webhook to notify a Jenkins URL:

The most important class:

In Stash 2.0+ the RepositoryPushEvent has access to the RefChanges, which have a 'type' which might be ADD. For those refs you could create a PullRequest by injecting the PullRequestService and calling create.

You could also do this via REST, but then you will need a script to poll Stash for new changes.

I hope this helps.


Thanks Charles, Your first two links are not working but i got the idea. I will try the command line interface suggested by Stefan and see if it does everything which we require.

Is it possible for you to update the broken links?

Hi Vikas,

Sorry about that. I migrated that repository to our Atlassian account. They should work now.


This widget could not be displayed.

Hi Vikas,

You might be interested in



Thanks Stefan, I will try this. This was exactly what i was looking for.

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Aug 10, 2018 in Bitbucket

What is your #1 piece of advice to new users getting started using Bitbucket?

Hello Community! My name is Claire Maynard, and I’m a Product Marketing Manager on the Bitbucket team. I’m interested in hearing what advice or tips you have for new users getting started on ...

286 views 15 2
Join discussion

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you