Create pull request from command line


NOTE: This post has been created for Bitbucket.

Novadays, I am creating so much pull request which has small differences compare to other.

After getting bored, I found the way how to create pull request from command line.

In this blog post I’ll share the method with you.


 

Necessary things:

  • Example pull request which you create from GUI.
    • This is necessary because some fields like reviewers or your fromRef.project.key needs to be written in script.

I assume that you already prepare your awesome pull request which does not contain any bug. Now we can go for automation.

 

Let’s assume you have link similar to this while you are create pull request from browser.

 

https://example.domain.com/git/projects/example-project-name/repos/example-reponame/pull-requests/state=OPEN

Change it like

https://example.domain.com/git/rest/api/1.0/projects/example-project-name/repos/example-reponame/pull-requests?state=OPEN

After writing this URL to your browser, you have to see JSON response which contains information related with all pull requests that has state OPEN. 1

 

Necessary values which you have to copy from your browser.

  1. values[0].fromRef.project.key >> Shows your kind of unique id in Bitbucket
  2. values[0].toRef.project.key >> Shows project name in Bitbucket
  3. Also we need project name
    • I write this static, you can change this if you want.
  4. values[0].reviewers >> This is optional.
    • You need to copy all reviewers block which Bitbucket offers as default.
    • Don’t forget your reviewers will always the same. If there is new joiner add him/her to the list.

 

Main script is here. Search for TODO to see  where you have to change.

 

 

I hope this will be useful for you and going to save your time.