Software Quality Insights

A SearchSoftwareQuality.com blog

» VIEW ALL POSTS Feb 1 2010   6:07PM GMT

Converting subtasks in JIRA with a Watir script



Posted by: Michael Kelly

Whenever I do large data uploads into JIRA, I often find that I have a number of tickets that require a parent/child relationship. That is, some of my tickets get imported as tasks, and I want them to be subtasks. To solve this problem, I wrote a simple Watir script that will subtask out all my tickets for me after upload. There’s nothing that special about it, but it can be quite a time saver.

The only assumption I have in my script is that you’ll have a hyphen in your subtasks and no hyphens in your parent tasks. When I import data like this, I often following the pattern “<parent summary> - <child summary>” for my Summary fields when I import. For example, a parent ticket might be “Write a book on testing” and a couple of subtasks for that ticket might be “Write a book on testing - Chapter 1″ and “Write a book on testing - Chapter 2.”

The first step is to setup a query of only the tickets you want to task and subtask. Often, this is as simple as creating a query in the Issue Navigator where you select the project, Issue Type, and whatever other compoents/values uniquely identify that subset of data. I’ll then sort by Summary, so my parent tickets will always be before my child tickets — again because of my naming convention.

Below, the link to that filter is where you start your browser in the second line of code. In the third line, I simply click on the first result returned. Then the code loops through all the tickets and establishes the parent/child relationships as needed.

RUBY:
  1. require ‘watir’
  2. b = Watir::Browser.start(“http://jira..com/secure/IssueNavigator.jspa?reset=true&amp;jqlQuery=project…etc…+ORDER+BY+summary+ASC%2C+priority+DESC”)
  3. b.link(:text, “KEY-2332″).click
  4.  
  5. for i in (1..800)
  6. if b.table(:index, 9).table(:index, 2).cells[1].text.split(‘-’)[1] == nil then
  7. ticket = b.url.split(“/”)[-1]
  8. else
  9. b.link(:text, “Convert”).click
  10. b.text_field(:name, “parentIssueKey”).set ticket
  11. b.button(:name, “Next&gt;&gt;”).click
  12. b.button(:name, “Next&gt;&gt;”).click
  13. b.button(:name, “Finish”).click
  14. end
  15.  
  16. b.link(:text, “Next&gt;&gt;”).click
  17. end

Comment on this Post


You must be logged-in to post a comment. Log-in/Register