Sunday, September 4, 2011

Custom Actions - Adding Menu Actions (part 1 of 2)

A recent update of Worklog Assistant added the ability to export your JIRA worklogs using a custom script. The documentation however, is a bit terse. If you are interested in extending Worklog Assistant generally, this will give you a good introduction. You must speak geek to read this blog post. If you cannot speak geek, find a geek. If you cannot find a geek, try and follow along anyway :)
You have been warned.

Custom Scripts

Custom scripts in Worklog Assistant are a set of commands interpreted by your computer to accomplish some goal. The general workflow of a custom script is:
  • Workog Assistant sets up a bunch of environment variables depending on the task you're trying to accomplish.
  • Your script is called using the operating system's command interpreter.
  • If your script returns with a non-zero exit code, Worklog Assistant assumes that the script failed.
As of this writing, there are two extension points to Worklog Assistant:
  • Menu actions.
  • Worklog export.
Both of these utilize the same one-way workflow as above. Let's try a simple example where we add a menu action.

Adding Menu Actions

  1. Go to Worklog Assistant's configuration dialog (⌘+, on Mac, Application->Configuration otherwise).
  2. Choose the "Custom Scripts" tab and click "Add". Mine is pictured below:Screen Shot 2011 09 04 at 12 08 30 PM
  3. Select the "New script" entry and change the text in the Description field to "Hello World"
  4. Leave the "Type" as "Context Menu"
  5. Type in the following in the "Script" section:
    • Windows: echo Hello World  %JIRA_Summary% && exit 1
    • Mac/Linux: echo "Hello World ${JIRA_Summary}" && exit 1
    • It should now look like the followingScreen Shot 2011 09 04 at 12 42 30 PM
  6. Click "Save"
Now when you right-click any issue, you should see a "Custom" entry as shown below:
Screen Shot 2011 09 04 at 12 19 41 PM
If you then click on the "Hello World" entry, you should see the following dialog:
Screen Shot 2011 09 04 at 12 43 48 PM
And there you have it! You have created a custom menu action. To find out all the variables that are available to you, you can use the following custom script:
  • Windows: (set | findstr JIRA_) && exit 1
  • Mac/Linux: (set | grep JIRA_) && exit 1
Let's make use of this information to open a Google search. This example will run only on Mac but you should be able to follow along on Windows and Ubuntu as well.
Change the "Hello World" script to the following:
open "http://www.google.com/search?q=${JIRA_Summary}&sclient=psy&hl=en&noj=1&site=webhp&source=hp"
This script searches Google for the summary of your JIRA issue when clicked! Note that I did not include the "exit 1" because I don't want Worklog Assistant to assume the custom script failed.
In the next part, I'll talk about utilizing the same custom scripts workflow to export your JIRA time tracking information.
Update: For convenience, I've included the main environment variables below along with sample output. The full list can be found here.
JIRA_Assignee=sohail
JIRA_Created='Tue Dec 30 17:56:26 2008'
JIRA_Description=-
JIRA_Due_date=
JIRA_Global_Rank=46
JIRA_ID=10124
JIRA_Key=TRACKER-51
JIRA_Original_estimate=0m
JIRA_Priority=Major
JIRA_Project=TRACKER
JIRA_Remaining_estimate=0m
JIRA_Reporter=sohail
JIRA_Resolution=
JIRA_Status='In Progress'
JIRA_Summary=Blogging
JIRA_Time_spent='36h 50m'
JIRA_Type=Task
JIRA_Updated='Sun Sep 4 15:39:52 2011'
JIRA_Votes=0

About this blog

We strongly believe that tracking your time properly is the first step to deterministic software development. If you feel that you have been guessing or you can't be bothered to remember to log time, Worklog Assistant might be for you!

Give it a try!

Please download a free 30-day trial today by clicking on the link below: Download