Are you using Stash and getting tired of pushing your changes and navigating to Stash’s web UI simply to create a pull request? Wish you could do all of this through one simple git command? Wait no more!

Introducing the Stash Command Line Tools!

Why?

Context switching impacts development speeds. I often feel this as I want to throw some code up for review, but don’t need the hassle of launching a browser window to open Stash to execute a menial task which can be easily automated.

Installation

This command line helper for Stash is written in Ruby and is deployed as a Ruby Gem. Installation is easy, simply run the following command:

1
$ gem install atlassian-stash

Once the gem is installed, the command stash should be in your PATH.

Now that the gem is installed, run the stash configure command. This will prompt for details about your Stash instance.

Creating a pull request

Use the pull-request command to create a pull request in Stash. E.g:

1
2
$ stash pull-request myBranch master @michael
Create a pull request from 'myBranch' into 'master' with 'michael' as a reviewer

or

1
2
$ stash pull-request master
Create a pull request from the current branch into 'master'

During the configuration stage, the script prompts the user to add a convenient git alias to create a pull request, so that the following command can be executed:

1
$ git create-pull-request master

How does it work

It’s a ruby gem which is built using Jeweler. The command handling is done using Commander, so it’s very extensible and easy to write.

Configuration data is written to and read out of a YAML file, ~/.stashconfig.yml which is chmod to 0600 as we need to store the Stash username and password in plain text. If you enter an empty password when configuring the script, you’ll be prompted for your password on every Stash command which is run (some of us don’t like storing our passwords in plain text files).

When creating a pull request, the script extracts the Stash project key and repository slug from the remote by parsing git remote -v. The pull request title is generated by using the first commit to the source branch, by running git log –reverse –format=%s target..source.

We’ll be continuing to improve these tools, some improvement in the pipeline include:

  • Allow the user to set the title and description of a PR
  • Pulling out a pull request description from the commit message body
  • Checking that the source branch is fully pushed to the server, and providing an option to do so if not
  • Create a host of new commands, such as:
    • Listing all/my pull requests for the current repo
    • Switch to the source branch for a particular repo (so that I can review the code with my local clone)

However, we need you! If you’re a ruby wizard and use Stash, fork the project on Bitbucket and create a pull request to contribute back. You can be awesome too!