Sunday, September 4, 2011

Custom Actions - Exporting Worklogs (part 2 of 2)

In the previous post, I gave a couple of examples of customizing the Worklog Assistant context menu items to script actions for a given issue. In this post, I'm going to talk about how to export JIRA worklogs using the same functionality. Geek credentials are still recommended, by the way.

At the moment, Worklog Assistant only stores worklogs for the current user to simplify storage requirements. So when we are talking about exporting worklogs, we are talking about exporting them only for you.

The general algorithm for exporting worklogs goes is as follows:

script = getUserScript()
worklogs = getWorklogsForDisplayedPeriodInTimesheet()
for worklog in worklogs:
	if not worklogHasBeenExportedByScript(worklog,script):
		env = getEnvironment(worklog) # also issue
		executeScript(script,env)

The key things about this algorithm:

  1. You have to choose the script you want to use.
  2. Worklogs are only exported for the displayed time period.
  3. A worklog is only exported if it has not already been exported by this script.

So let's define a custom script that creates a new file: ~/worklogs.csv. The script defined here will work on Mac and Linux so Windows users will have to translate. What we want to do is create a report that collects all our worklogs for a given time period.

The script itself is quite simple and is shown below:

if [ ! -f ~/worklogs.csv ]; then
echo "Key,Summary,Start date,Time spent (seconds)" > ~/worklogs.csv
fi; 

cat >> ~/worklogs.csv << END_WORKLOGS
${JIRA_Key},${JIRA_Summary},${JIRA_WorklogStartDate},${JIRA_WorklogTimeSpentInSeconds}
END_WORKLOGS

If we add this to our custom script configuration, this time changing the type to "Worklog Export", it should look something like this. I named it "Export to CSV":

Screen Shot 2011 09 04 at 11 14 30 PM

To use this new script:

  1. Navigate to the "Timesheet" tab.
  2. [Optional] Import -> Import Worklogs. I like to use the query "jql: updated >= -4w" to make sure I have the latest data.
  3. Export -> Export worklogs using custom scripts
  4. Choose "Export to CSV"

Your file will be located at ~/worklogs.csv. Open it now. You should see all the worklogs for the issues you worked on that week, along with the worklog comments.

Try exporting and reopening the file again. You will notice that the file has not changed. This is deliberate. When Worklog Assistant exports a worklog, a note is made that the worklog has been exported. This way, if you are exporting worklogs for reporting purposes, you do not need to worry about accidentally including double entries.

If you would like to delete the notes on exported worklogs, navigate to:

  • Windows: %APPDATA%\Worklog Assistant for JIRA
  • Mac: ~/Library/Preferences/Application Support/Worklog Assistant for JIRA
  • Linux: ~/.config/Somani Software/Worklog Assistant for JIRA

Then, navigate to the "Exported Worklogs" directory and delete the "Export to CSV" folder. That will get rid of the notes and you can run the script again.

Just as before, there are a set of available fields for each worklog. For convenience, I've included the list as well as example values below.

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='40h 1m'

JIRA_Type=Task

JIRA_Updated='Sun Sep 4 23:15:24 2011'

JIRA_Votes=0

JIRA_WorklogAuthor=sohail

JIRA_WorklogComment=

JIRA_WorklogCreated='Sun Sep 4 12:27:55 2011'

JIRA_WorklogGroupLevel=

JIRA_WorklogID=14933

JIRA_WorklogIssueID=10124

JIRA_WorklogRoleLeveLID=

JIRA_WorklogStartDate='Sun Sep 4 11:28:08 2011'

JIRA_WorklogStartDate_TimeT=1315150088

JIRA_WorklogTimeSpent='1 hour'

JIRA_WorklogTimeSpentInSeconds=3600

JIRA_WorklogUpdateAuthor=sohail

JIRA_WorklogUpdated='Sun Sep 4 12:27:55 2011'

That's all for custom scripts for now! Please feel free to contact me at support@worklogassistant.com or comment below if you have any questions!

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