Archive for the ‘Open Source’ Category

TortoiseHg Review Board dialog ported to PyQt for Thg 2.0

06 Nov

Over the last couple of weeks I have spent a lot of time porting the Review Board dialog I wrote for TortoiseHg to use the PyQt framework and the upcoming release of TortoiseHg 2.0.

Review Board is a powerful tool to increase the quality of code in any organisation. The Review Board Mercurial extension was an excellent way to submit diffs to the review board server directly from the command line. This dialog takes this simplicity to the next level by providing a way to post reviews directly from TortoiseHg. It is is available now in the current beta release of TortoiseHg 2.0.

It requires a slightly modified version of the Review Board Mercurial extension that can be downloaded here – https://bitbucket.org/michaeldewildt/mercurial-reviewboard.

To use the dialog in TortoiseHg 2.0 you need to activate the above Review Board mercurial extension in the global mercurial settings file. Once activated, the Review Board dialog and menu items will be available in TortoiseHg 2.0.

You can set the Review Board extension settings in the TortoiseHg settings dialog under the Review Board tab. The Review Board server, username and password is required because the dialog will download a list of repositories and existing review requests from the server.

Once the settings are correct you are now ready to post a review to the Review Board server. To do so the user will need to select an outgoing change set or set of outgoing change sets from the TortoiseHg Workbench and click the right mouse button to bring up the context menu. From here you can select Post to Review Board that will open the Review Board dialog.

Within this dialog the user can set up the review that they are posting to the Review Board server. The user can choose to post a new review or update an existing review in addition to a list of the change sets that the user originally selected.

If the ‘outgoing’ option is not checked the review will contain the change sets between and equal to the top and bottom checked change set. For example if there are 5 change sets in the list and the first and last is not checked then the review will include change sets 2, 3 and 4 regardless if change set 3 is checked or not.

The Post and Update Review tabs have a set of fields and options dependant on the task chosen. In addition to these specialised options there are two options that relate to both that can be set.

1. Create diff with all outgoing change sets on this branch – This option will grey out the change sets box. The review will ignore what the user originally selected and will include all outgoing changes under this selected change set in the change sets list.
2. Publish immediately – This one is self explanatory, the review will not be posted as a draft.

Within the “Post Review” tab the user has two fields to complete/select.

1. Repository ID – A list of repository id’s that have been set up on the Review Board server
2. Summary – The summary of the review request that is being posted to Review Board. If this field is left blank then the summary will be set to the commit message of the first change set in the list

Within the “Update Review” tab the user has two fields to select.

1. Review ID – The review that the user wishes to update
2. Update fields of this existing request – The updated review will overwrite the current description in the existing review

Finally, once the user is happy with the options selected they can hit the Post Review button and the diff will be bundled up and posted to the Review Board server.

The review description will contain a list of the change sets posted and their commit messages.

 

TortoiseHg Reviewboard extension available for testing

13 Sep

I have finished my first fairly stable version of a Reviewboard extension for TortoiseHg that allows you to post reviews to reviewboard directly from the TortoiseHg repository explorer.

Introduction

This is the first application I have written in Python and I must say I really like the language. Its elegant, intuitive and very easy to pick up. Coming from C based languages like PHP and C#, Python, at first takes a little bit to get used to. This is mainly due to the significance of white space and layout of the code therefore I found myself tacking semicolons onto most statments and looking for curly brackets around code bocks.

I used Jetbrains PyCharm IDE which is very simmilar to PhpStorm therfore making development a breeze because I already knew most of the IDE idioms. Most of the code I wrote myself using examples for other areas of TortoiseHg. The post review code is based on the Reviewboard plugin for Mercurial which can be found here.

The Post Review UI

The post review feature can be accessed from the TortoiseHg context menu by right clicking on the revision that you would like to diff to and post to review board. You can either choose to post a new review request or update an existing one.

TortoiseHg context menu with Review Board sub menu

TortoiseHg context menu with Review Board sub menu

Choosing “Post Review” will load the post review dialog that will connect to reviewboard with the credentials you have set in the settings section. This is done via the reviewboard API and will get a list of repository ID’s that are set up on your reviewboard. Once loaded the user can enter the summary of the review they are about to post and choose from two options.

  1. Include all outgoing change sets – This will create a diff comparing all your change sets in the current branch to with your upstream repository.
  2. Publish immediatly – This will publish the review request immediately

Clicking the “Post Review” button will create a diff for the selected revision and upload it to the reviewboard server with the summary inputted and the option selected. The description will contain each change set and its commit message.

Once the review request is created a link to the address will be opened in the browser set in the Reviewboard options within the TortoiseHg settings.

The Reviewboard dialog for a new review request

Choosing “Update Review” will load a similar dialog to the one above where instead of a list of repositories, you will get a list of existing review requests for the current day.  Also, in addition to the two options above you will get an option to override the description originally posted to reviewboard.

The update review dialog

In order to connect to a reviewboard installation you will need to set the path, user and password for reviewboard, as well as the full path to your favorite browser in the TortoiseHg settings dialog under the new Reviewboard tab.

NOTE: Currently the password is stored in CLEAR TEXT and will be saved as such in the TortoiseHg settings file. I do plan to change this in the future.

Reviewboard settings within the TortoiseHg settings dialog

Installation

The reviewboard extension has been merged with the “default” branch of TortoiseHg. These days this branch is very much the same as the “stable” branch of TortoiseHg due to most, if not all, of the development happening in the Qt version of TortioseHg.

Windows Vista/7

  1. Download and install TortoiseHg from http://tortoisehg.bitbucket.org/ if you haven’t already got it
  2. Clone the TortoiseHg with Reviewboard extension source from http://bitbucket.org/michaeldewildt/tortoisehg_reviewboard
  3. Open Windows Explorer with Administrator privligaes and navigate to your TortoiseHg installation directory. Usually “C:\Program Files (x86)\TortoiseHg” for x64 windows, for x86 windows omit (x86).
  4. Copy “tortoisehg_reviewboard\icons\reviewboard.png” from the cloned location to the “icons” directory
  5. Copy the original “library.zip” archive to a new location as a backup
  6. Open the library zip archive as Administrator
  7. Open another Windows Explorer window and navigate to where you cloned the Reviewboard extension source
  8. Copy the contents of ‘tortoisehg_reviewboard\reviewboard’ into ‘library.zip\hgext\’
  9. Add ‘reviewboard =’ after ‘;mercurial_keyring =’ in ‘C:\Program Files (x86)\TortoiseHg\hgrc.d\Mercurial.rc’
  10. Navigate to “tortoisehg\hgtk\” within the archive and overide its contents with that of “tortoisehg_reviewboard\tortoisehg\hgtk” you just cloned
  11. Save and close the archive

Ubuntu Linux

  1. Install TortoiseHg via the Ubuntu Software Centre
  2. Clone the TortoiseHg with Reviewboard extension source from http://bitbucket.org/michaeldewildt/tortoisehg_reviewboard
  3. Open a terminal window an cd to where tortoisehg is installed – Eg. “/usr/lib/pymodules/python2.6/tortoisehg”
  4. Move the hgtk folder to a backup directory – Eg. ”sudo mv hgtk hgtk_bak”
  5. Create symbolic link or copy the hgtk directory to here from the location that you cloned the reviewboard extension above – Eg. “sudo ln -s hgtk ~/Documents/tortoisehg_reviewboard/tortoisehg/hgtk/”
  6. Cd to “/usr/lib/pymodules/python2.6/hgext” (Create hgext if it does not already exist)
  7. Create a symbolic link or copy the reviewboard directory to here from the location that you cloned directory – Eg. “sudo ln -s reviewboard ~/Documents/tortoisehg_reviewboard/reviewboard/”
  8. Add ‘reviewboard =’ after ‘;mercurial_keyring =’ in the default hgrc file.\

Issues

There are still a few bugs here and there that I am ironing out whileist using the feature during my daily tasks.

A major one is an issue that is also present in the reviewboard extension for which I based my code on. When selecting a change set from a non active branch sometimes the diff does not get created correctly and causes reviewboard to error when trying to display the diff.

If you notice any more issues or request please post them to http://bitbucket.org/michaeldewildt/tortoisehg_reviewboard/issues and I will look into them.

 
 

I’m hacking TortoiseHg to add a reviewboard interface

26 Aug

Righto I have officially started my first foray into Open Source Development!

Currently my company uses Mercurial for distributed source control.

So naturally I chose TortoiseHg manage my repositories because it is a fantastic tool for the job. My company also uses Reviewboard to review changesets before they are pushed to the main repository.

Now Mercurial has a nifty extension that allows you to post changesets to the reviewboard from the command line .

Since I use these four tools on a daily basis I want to streamline review posting process! So I have decided to add a GUI intergface to TortoiseHg that will allow me to post a review by right clicking on the changeset, branch or group of changesets I wish to get reviewed!

As far as I can tell from some Google searches there are no other projects doing the same thing…. So hey…. Why not give it a go myself?

I have forked a recent version of TortoiseHg and started a repository for my changes here – http://bitbucket.org/michaeldewildt/tortoisehg_reviewboard

So far I have only added the graphical menu items and am working on the post review dialog that, at the moment, does nothing. I am adding my changes to the hgtk version first then I will port the changes across to hgqt some time in the future.

Well there you have it, my first go at hacking an open source project.

Its a small change that shouldn’t take too long. It all depends on how much free time I can dedicate to the project.

This weekend is definitely going to be spent in the snow because for the first time in many years Australia is pushing a 2 meter base!

I will post regular updates on my progress here… project progress not snow that is!

 
Comments Off

Posted in Open Source, Python