MediaWiki Dradis Import

For quite a while now I've been planning to import all my Dradis issues into MediaWiki to make reusing issues easier. Till now, each time I wanted to reuse an issue I've had to open a new browser and go back to find the old project where the issue was used then copy and paste it into the new project, that is a real pain to do. So I finally bit the bullet and created a MediaWiki VM, set up is easy, I'm not going to talk you through it, see their install notes. Next I created a few entries and set up Dradis to make sure it could talk to it, again, this is fully documented in the Dradis guides section so I'll not cover that.

I then had a fully working Wiki and communication between it and Dradis, the problem then was that I had a whole load of issues I'd already written which were tucked away in many projects in Dradis, how was I going to get them out? That is where this script comes in.

This script opens your Dradis database, finds all the issues, de-duplicates them and then inserts them into MediaWiki in the right format. As I didn't want to mess with the Dradis VM I decided the easiest way to get remote access to the database was to use ssh port forwarding, that let me access the database from my dev machine as though it was local without having to alter anything on the VM. The second problem was talking to MediaWiki. My initial thought was to just drop the entries directly into its database but doing that turned out to be harder than I thought as it isn't as simple as adding an entry to a single table. The next option was to look for a gem to do it for me and lo and behold I found one, mediawiki-gateway. I tried to install this from the standard gem command line but unfortunately this failed due to it seeming to depend on itself so I had to install it from source from GitHub - This may be fixed now but haven't tried the updated gem. It also appeared to only work with Ruby < 2 so I used 1.9.3.

After this it was a fairly simple case of working out where the issues were stored in the Dradis database, grabbing them, reformatting them and pushing them through the gem. After each issue I successfully import I generate a hash of it and compare that to a hash of each new page to check for, and reject, duplicates. Some still slipped through, I think that may have been due to extra whitespace at the end of some of the duplicates but there weren't enough for me to worry about debugging it.

I title the MediaWiki article based on the issue title, this is taken from a field in the issue tagged, initially, as #[Title]#, if you use a different tag for your titles then simply edit line 10 and change the value to whatever you use.

A couple of other things I had to straighten out, MediaWiki caps titles at 255 characters so I trim titles down to that. MediaWiki then doesn't allow duplicated titles so to remove these I started adding random numbers at the end, this means I have to strip a few more characters off the title but that should be OK. This worked fine till I got a title that ended in a number. Adding a new number on to the end of it still got it rejected as a duplicate. I tried to fight this but gave up and tried pre-pending the number instead, this worked so I stuck with it.

This script was written as a one off hack to get my data imported, it isn't something I'm planning to maintain but if you do find a problem with it let me know and I'll see what I can do to fix it up.

Usage

Once you've got the gateway gem installed the script just needs configuring, these are the fields from the top of the script which you should edit:

TITLE_FIELD = "#[Title]#"
DB_NAME = "dradispro"
DB_USER = "dradispro_db"
DB_PASSWORD = "dradispro_db_pass"
DB_PORT = 3307

MEDIAWIKI_URL = 'http://192.168.0.1/api.php'
MEDIAWIKI_USER = "robin"
MEDIAWIKI_PASSWORD = "x"

You then do an ssh port forward from your local machine to the Dradis box:

ssh -L 3307:localhost:3306 dradispro@dradispro.local

You can check this worked by:

mysql --port=3307 -h 127.0.0.1 -u dradispro_db -pdradispro_db_pass -D dradispro

If you get a connection it worked.

It should now just be a case of running the script

./mediawiki_import.rb

It gives a load of output about what it is doing and at the end gives a count of the number of issues imported.

If you want to import from multiple copies of Dradis then have a look at line 31 in the script, it will tell you want to do to allow this.

Download

Download mediawiki_dradis_import_1.0.tar.bz2

Change Log

Version 1.0

First release

Support The Site

I don't get paid for any of the projects on this site so if you'd like to support my work you can do so by using the affiliate links below where I either get account credits or cash back. Usually only pennies, but they all add up.