Created
December 9, 2010 02:55
-
-
Save peplin/734269 to your computer and use it in GitHub Desktop.
Bulk Lighthouse ticket import from a text file
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env ruby | |
| # Bulk Lighthouse ticket import from a text file | |
| # Christopher Peplin, [email protected] | |
| # | |
| # Used this for taking a big Markdown file of tickets we discussed during a | |
| # meeting and importing them all into Lighthouse. No attempt to be flexible, | |
| # just useful in this one case. One ticket title per line, where headers and | |
| # subheaders are used as tags. | |
| # | |
| # Expects the following pseudo-Markdown text file format: | |
| # | |
| # - Blank lines are ignored | |
| # - Lines beginning with "# " are parent tags | |
| # - Lines beginning with "## " are child tags - i.e. tickets will have both that | |
| # and the parent tag | |
| # - Lines beginning with "* " are ticket titles to be created in the default | |
| # milestone | |
| # - Lines beginning with "!* " are tickets to be put into a "Future Work" | |
| # milestone (the ID of which is defined at the top of this script) | |
| # | |
| require 'lighthouse' | |
| Lighthouse.account = YOUR-ACCOUNT | |
| Lighthouse.token = YOUR-TOKEN | |
| PROJECT_ID = your-project-id | |
| FUTURE_WORK_MILESTONE_ID = your-future-work-milestone-id | |
| PROJECT = Lighthouse::Project.find(PROJECT_ID) | |
| future_work = Lighthouse::Milestone.find(FUTURE_WORK_MILESTONE_ID, | |
| :params => {:project_id => PROJECT.id}) | |
| tags = [] | |
| def create_ticket(tags, title, milestone=nil) | |
| if milestone | |
| ticket = Lighthouse::Ticket.new(:project_id => PROJECT.id, | |
| :milestone_id => milestone.id) | |
| else | |
| ticket = Lighthouse::Ticket.new(:project_id => PROJECT.id) | |
| end | |
| ticket.title = title | |
| ticket.tags << tags | |
| ticket.save | |
| end | |
| File.foreach(ARGV[0]) do |line| | |
| case line | |
| when /^# (.*)$/ | |
| tags = [$1] | |
| puts "Tags: #{tags}" | |
| next | |
| when /^## (.*)$/ | |
| tags.pop if tags.length > 1 | |
| tags.push $1 | |
| puts "Tags: #{tags}" | |
| next | |
| when /^\* (.*)$/ | |
| puts "Active: #{$1}" | |
| create_ticket(tags, $1) | |
| next | |
| when /^!\* (.*)$/ | |
| puts "Bumped: #{$1}" | |
| create_ticket(tags, $1, future_work) | |
| next | |
| else | |
| puts "unrecognized line: #{line}" | |
| end unless line.strip == "" | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment