Composing workflows using aliases in RBTools

RBTools 0.7 introduced support for aliases, a handy way to simplify common tasks and workflows when working with source code and review requests.

With aliases, you can write your own RBTools commands that expand into, well, anything. They could be a set of common options for an existing command, or they could call out to shell commands.

You can define your own aliases for your personal use, but you can also define aliases for your entire team. Since they live in .reviewboardrc, aliases can be committed to your repository for everyone to use. This is quite powerful, as it can help to easily standardize workflows for your whole team.

I’m going to show you a few ways to compose workflows using aliases.

Simplify posting code for review

Feature branches in Git are great. They help you to stay organized when you have lots of changes that depend on each other. If you’ve made heavy use of them, you’ve probably used this workflow a bit:

# Post some code...
$ rbt post HEAD

# After making some changes to code...
$ rbt post -u HEAD

# After making some changes to the commit message...
$ rbt post -g yes -u HEAD

There aren’t a lot of parameters there, but you still have to remember them and type them every time. The -u HEAD or the -g yes -u HEAD gets repetitive.

Let’s add a few nice and short aliases in ~/.reviewboardrc:

ALIASES = {
    # Post this
    'pt': 'post HEAD',

    # Post this and update
    'ptu': 'post -u HEAD',

    # Post this, update, and re-guess the description from the commit message
    'ptug': 'post -g yes -u HEAD',
}

Now the workflow becomes simply:

# Post some code...
$ rbt pt

# After making some changes to code...
$ rbt ptu

# After making some changes to the commit message...
$ rbt ptug

Much shorter, and hopefully easier to remember.

Run unit tests before posting code

If your project has a unit test suite, you’re probably supposed to run it before posting code for review. It’s easy to forget, or to just ignore it, since it’s another step in your process. We can solve both of those problems.

Say your project has a ./scripts/run-tests.sh that runs your test suite and outputs 1 for failure, 0 for success. Let’s make an alias that ensures tests pass before posting, and we’ll even pre-populate the Testing Done field with a message stating they pass. Let’s call this p for short.

ALIASES = {
    'p': '!./scripts/run-tests.sh &&'
         'rbt post --testing-done="Unit tests pass." $*',
}

Now you’ll never forget to run tests, and you’ll even have less to type.

ProTip: Define this as an alias in the .reviewboardrc in your repository, and switch your team to use that instead of rbt post.

Sanity-check patches on a review request

If you’re the gatekeeper for your project’s code (perhaps you’re an open source developer?), you need to test the patches that other people write before landing them. Thanks to rbt patch, you can easily pull down a diff from a review request and apply it, but you still need to run your tests before landing it. You also need to be careful not to disturb any changes in your own tree, or to test on the wrong branch.

To really sandbox your testing, your ideal workflow may look something like this:

$ git clone -b master . /tmp/test-project-<review request id>
$ cd /tmp/test-project-<review request id>
$ rbt patch <review request id>
$ ./scripts/runtests.sh
$ cd -
$ rm -rf /tmp/test-project-<reviw request id>

Let’s make an alias for this:

ALIASES = {
    'test-patch': '!rm -rf /tmp/test-project-$1 &&'
                  'git clone -b master . /tmp/test-project-$1 &&'
                  'cd /tmp/test-project-$1 &&'
                  'rbt patch $1 &&'
                  './scripts/runtests.sh &&'
                  'rm -rf /tmp/test-project-$1',
}

Now you have a quick and easy way to check any patch applying to the repository you’re currently in, without messing up your repository, typing a bunch of commands, or worrying about directories.

Screenshot a window and attach it in one go

If you’re doing UI work, you’re posting screenshots a lot. This means taking a screenshot, saving it somewhere, and drag-and-dropping it into a review request with a caption.

Let’s get that down to one command.

Now, different operating systems have different tools for capturing a screenshot. I’ll show an example for MacOS X and another for Linux. For Windows, you’ll need to grab a command line screenshot tool.

ALIASES = {
    # For MacOS X:
    'attach-screenshot': '!screencapture -wo /tmp/screenshot.png &&'
                         'rbt attach --caption "$2" $1 /tmp/screenshot.png &&'
                         'rm /tmp/screenshot.png',

    # For Linux:
    'attach-screenshot': '!import /tmp/screenshot.png &&'
                         'rbt attach $* tmp/screenshot.png &&'
                         'rm /tmp/screenshot.png',
}

Now uploading a screenshot is quick and easy! To upload to review request #123, just run:

$ rbt attach-screenshot 123

You can even attach a caption or custom filename, like so:

$ rbt attach-screenshot --caption="About dialog" --filename=about-dlg.png 123

Share your workflows!

We’d love to hear about any workflows you come up with. Send them along. We may even feature them in a future post or as samples in the documentation!

Read More

RBTools 0.7 is here!

RBTools 0.7 is packed with new tools and improvements for your workflow, making it faster to install, post changes to RBCommons, and land your changes.

There’s a lot here, so we’ll go into the major new additions.

Easy installation for Windows and MacOS X

We’ve improved the installation experience. If you’re on Windows or MacOS X, you can simply download the RBTools installer for your platform. In seconds, you’ll be ready to use the latest RBTools.

Land reviewed changes with one command

The all-new rbt land is the fastest way to take a change (in a local branch or a review request), validate that it’s been reviewed, and land it in your repository. It will format the commit message to include the review request’s description and testing information, and can even handle pushing the change upstream and deleting the local branch in one go.

(This is currently only available for Git repositories. Support for other repositories will come soon.)

Exclude files from review

Sometimes you’ll have modified files that you just don’t want up for review. Auto-generated code, for instance. You can now exclude these when posting changes for review by using the new -X option to rbt post, or by setting EXCLUDE_PATTERNS in .reviewboardrc.

Make your own commands with aliases

Ever find yourself repeating a group of options? rbt post -g yes -u HEAD, for instance? In 0.7, you can create an alias — a new RBTools command, basically — for those options.

You can even go a step further and make an alias that runs non-RBTools commands. Want to always run unit tests before posting code? Make an alias. How about merging the latest upstream changes into your branch before posting? There’s another alias!

See the documentation on aliases for more information.

Faster communication with RBCommons

We’ve sped up RBTools by caching results from RBCommons. This means lots of operations, such as posting changes, is faster than ever.

If you’re using the RBTools Python API to write your own integrations, you’ll benefit from this with no additional work on your end.

And lots more!

We haven’t even talked about rbt stamp, support for API tokens, or all the bug fixes and other feature improvements.

Check out the release notes for the whole list of changes.

Read More

5 Tips for your RBTools workflow

If you’re a Review Board or RBCommons user, you’re probably familiar with RBTools, our handy set of command line tools for working with Review Board. (If you’re not using RBTools, I’m going to tell you how to get started with it in a bit.)

You’re probably most familiar with rbt post, or post-review in older versions. This is the tool that helps you quickly get a change onto Review Board, or to update an existing review request. It’s pretty handy, but how much do you really know about it? Or about the other commands included with RBTools? (Yes, there are others!)

I’m going to show you five of my favorite tips and tricks for RBTools that you may not know about.

5. Opening a browser after posting with rbt post -o

When you run rbt post, you usually get something like this:

$ rbt post
Review request #123 posted.

https://reviewboard.example.com/r/123/
https://reviewboard.example.com/r/123/diff/

Those links for opening the review request or diff are useful, but you can save yourself a step by having RBTools open your browser for you. Just pass -o to rbt post, like so:

$ rbt post -o

Your browser of choice will open, ready for editing. Want to do that automatically, every time? Add this to your .reviewboardrc in your home directory:

OPEN_BROWSER = True

4. Check your open review requests with rbt status

At some point or another, you’ll want to see what review requests you have open, either as a draft or currently pending review. I myself need to do this at times to help me remember if I’ve already posted something for review.

Sure, you could dig through the dashboard and check. That works great, but it means leaving the command line. That’s where the rbt status command comes in:

$ rbt status
   r/6676 - Add release notes for Review Board 2.0.12.
   r/6258 - Add release notes for Review Board 2.1 beta 1.

rbt status will show you all open review requests for the current repository – their IDs and their summaries. Pass --all and it’ll show you all open review requests across all repositories.

3. Attach files to review requests with rbt attach

Review Board makes it pretty easy to drag-and-drop files onto a review request in order to quickly upload them, but it does mean having the file manager and web page open. If you’re a command line junkie like me, you’d probably rather avoid that as much as possible.

rbt attach will let you upload a file to a review request with a single command. Just give it the review request ID, the file to upload, and an optional caption, and you’re done.

Let’s try it.

$ rbt attach 123 screenshot.png
Uploaded screenshot.png to review request 123.

Want to give it a caption?

$ rbt attach --caption "UI screenshot" 123 screenshot.png

2. Apply a review request’s diff to your tree with rbt patch

If you’re an open source developer, or you like to thoroughly test other people’s patches as part of reviewing their code, then this tip is for you.

rbt patch pulls down the latest patch (or a specified revision) from a review request and applies it to your tree. It can even create a commit for that patch, if using Git or Mercurial, by running rbt patch -c.

$ rbt patch -c 123
Changes committed to current branch.

We use this when accepting contributions from our own Review Board server. After a thorough review, we run rbt patch -c, edit the commit message as appropriate, and push it.

As a bonus, this will append a Reviewed at <url> line to the bottom of the commit message. If you’re using repository hooks to auto-close review requests (admins, see the “Hooks” link next to a repository in the administration UI), pushing this commit will take care of closing that out for you.

1. Easily update review requests with rbt post -u

If you’ve been using RBTools for a good long while, you’re probably used to passing -r <ID> to rbt post, in order to tell it which review request to update. This means having to look up the ID and making sure you don’t type it wrong.

In RBTools 0.6 or newer, we have a much simpler solution. Just pass -u. RBTools will automatically find a matching review request, asking if it’s not completely sure it’s a match, and update it for you. Let’s compare:

$ rbt post -r 123

vs.

$ rbt post -u

It’s much nicer. Get in the habit of using -u. It’s the wave of the future.

What if I’m not using RBTools?

Use it!

Seriously, RBTools is the best way to get the most out of Review Board. You can follow our installation instructions to get started. We’ll soon be announcing new installers to make this easier.

Learn more

The RBTools documentation is a great resource. You can learn about all the RBTools commands, our Python API for interfacing with Review Board, configuration options, and more.

We’ll be posting a new batch of tips and tricks for RBTools soon, plus some advanced Git and Review Board tips.

If you’re not already on our mailing list, subscribe today to keep up with the latest releases, tips, and strategies.

And now, we’d like to leave you with this:

Isn't it cute?

Read More

RBTools 0.6.3 is released!

Today’s release of RBTools 0.6.3 fixes a handful of annoying little bugs across Git, Mercurial, Subversion, Perforce, and ClearCase. If you use any one of these (and there’s a good chance you do), it’s time to upgrade!

In past releases, failed post operations could leave behind incomplete review requests, which wasn’t always obvious. RBTools will now print out the review request after a failure, making it easier to fix things up without creating a new review request.

We’ve also fixed a bug in the Python API for Review Board that resulted in errors when performing HTTP DELETE operations.

See the release notes for the complete list of fixes.

While this is a fairly small and bug-oriented release, we’re happy to announce that RBTools 0.7 is coming soon, with several new features and native installers for Windows and MacOS X!

Read More

RBTools 0.6.2 is released

This evening’s release of RBTools 0.6.2 fixes several bugs throughout rbt post and rbt patch.

Mercurial users will find that rbt patch now behaves as expected especially for Git diffs. No need to manually fetch and patch by hand anymore.

We’ve fixed some breakages that users hit with error messages coming from Review Board under certain conditions, and some compatibility issues with Perforce, ClearCase, and Git.

You can upgrade to RBTools 0.6.1 by typing:

    $ sudo easy_install -U RBTools

(If you’re on Windows, you shouldn’t need to type “sudo.”)

See the release notes for the full list of changes.

Read More

RBTools 0.6.1 is released

We have just released RBTools 0.6.1. This release improves upon April’s release of RBTools 0.6, fixing numerous bugs that have been reported to us over the past two months.

These fixes cover compatibility issues with different types of repositories, misleading or useless error messages, crashes in certain edge cases, and issues running on different operating systems.

You can upgrade to RBTools 0.6.1 by typing:

    $ sudo easy_install -U RBTools

(If you’re on Windows, you shouldn’t need to type “sudo.”)

If you’re running an older version, now’s a great time to upgrade! We outlined the major improvements in our RBTools 0.6 announcement.

See the release notes for the full list of changes in 0.6.1.

Read More

RBTools 0.6 is released

RBTools 0.6 has just been released, and it’s a big one. We spent a lot of time simplifying the process for posting and updating review requests, and we think it’s going to make life a lot easier for just about everyone.

Posting using Git or Mercurial used to require dealing with --parent and --revision-range, along with our custom revision syntax. Now all you have to do is pass native revisions or revision ranges to rbt post, like so:

$ rbt post HEAD
$ rbt post main-branch..feature-branch
$ rbt post 123:126

Compare this to the old way of doing things:

$ rbt post --parent=HEAD^
$ rbt post --revision-range=main-branch:feature-branch
$ rbt post --revision-range=123:126

We’ve also improved how “guessing” descriptions and summaries from commits work. In previous versions, you needed to run rbt post -g to enable guessing, but in 0.6, it’s now automatic for new review requests. This means less typing and less work to do.

That behavior can also be changed through new GUESS_FIELDS settings in .reviewboardrc. This is covered more in the documentation.

A few other goodies:

  • Feature and performance improvements for Mercurial
  • Git repository hook scripts for auto-closing review requests and requiring approval for pushes
  • Many new configuration options

And more.

A couple important notes. We’ve removed support for the old post-review tool. Running post-review will now tell you to use rbt post instead.

We’ve also removed support for Python 2.4. You will now need 2.5 or higher. We strongly recommend that everybody upgrades to Python 2.7.

See the release notes for the complete list of changes.

Read More

RBTools 0.5.5 is released

We just put out a release of RBTools 0.5.5. This fixes a handful of problems reported to us for rbt patch, Subversion, and Git.

rbt patch, one of our new tools introduced in 0.5.3, has had several bug fixes for applying commits to Git, and for properly handling Unicode characters in commit messages.

We fixed an issue with looking up repositories using Subversion. Some of you using the suggested RBTools configuration for your Subversion repositories have reported problems, which we’ve addressed in this release. Please let us know if you still encounter any issues.

When using rbt post with --revision-range revision1:revision2, RBTools 0.5.3 would fail to parse the revisions. While it allowed '..'-separated revisions, support for ':' was prematurely removed. We’ve restored this compatibility for now, but there are big changes coming in RBTools 0.6.

To upgrade your copy of RBTools, run:

    sudo easy_install -U RBTools

See the release notes for more information.

Read More

RBTools 0.5.3 is released

We have a great RBTools release for you today, with some new features and a whole lot of bug fixes.

rbt post has a new -u option that attempts to update an existing review request, instead of posting a new one. Previously, you would have to pass -r <review_request_id>. Now, when using -u, RBTools will look up possible matches and present them. We think this will be a major time-saver.

A new rbt setup-repo command makes setting up your repository much easier. Instead of writing a new .reviewboardrc file by hand, just run rbt setup-repo. It will prompt for your RBCommons team’s URL (for example, https://rbcommons.com/s/my-team/, try to locate the right repository entry, and then write the configuration file for you.

rbt patch has two new options for working with patches. --print will print the patch to the terminal instead of applying it. --commit (Git only for now) will commit the patch with the author’s name and review request’s description.

rbt diff doesn’t crash anymore! Huzzah!

Along with this, we have fixes and improvements for using third-party commands, Git, Bazaar, Mercurial, and Subversion.

See the release notes for the full list of changes.

Read More