Guest User

Untitled

a guest
Jul 16th, 2018
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. #!/usr/bin/env ruby
  2. # Bulk Lighthouse ticket import from a text file
  3. # Christopher Peplin, peplin@bueda.com
  4. #
  5. # Used this for taking a big Markdown file of tickets we discussed during a
  6. # meeting and importing them all into Lighthouse. No attempt to be flexible,
  7. # just useful in this one case. One ticket title per line, where headers and
  8. # subheaders are used as tags.
  9. #
  10. # Expects the following pseudo-Markdown text file format:
  11. #
  12. # - Blank lines are ignored
  13. # - Lines beginning with "# " are parent tags
  14. # - Lines beginning with "## " are child tags - i.e. tickets will have both that
  15. # and the parent tag
  16. # - Lines beginning with "* " are ticket titles to be created in the default
  17. # milestone
  18. # - Lines beginning with "!* " are tickets to be put into a "Future Work"
  19. # milestone (the ID of which is defined at the top of this script)
  20. #
  21. require 'lighthouse'
  22.  
  23. Lighthouse.account = YOUR-ACCOUNT
  24. Lighthouse.token = YOUR-TOKEN
  25. PROJECT_ID = your-project-id
  26. FUTURE_WORK_MILESTONE_ID = your-future-work-milestone-id
  27.  
  28. PROJECT = Lighthouse::Project.find(PROJECT_ID)
  29. future_work = Lighthouse::Milestone.find(FUTURE_WORK_MILESTONE_ID,
  30. :params => {:project_id => PROJECT.id})
  31. tags = []
  32.  
  33. def create_ticket(tags, title, milestone=nil)
  34. if milestone
  35. ticket = Lighthouse::Ticket.new(:project_id => PROJECT.id,
  36. :milestone_id => milestone.id)
  37. else
  38. ticket = Lighthouse::Ticket.new(:project_id => PROJECT.id)
  39. end
  40. ticket.title = title
  41. ticket.tags << tags
  42. ticket.save
  43. end
  44.  
  45. File.foreach(ARGV[0]) do |line|
  46. case line
  47. when /^# (.*)$/
  48. tags = [$1]
  49. puts "Tags: #{tags}"
  50. next
  51. when /^## (.*)$/
  52. tags.pop if tags.length > 1
  53. tags.push $1
  54. puts "Tags: #{tags}"
  55. next
  56. when /^\* (.*)$/
  57. puts "Active: #{$1}"
  58. create_ticket(tags, $1)
  59. next
  60. when /^!\* (.*)$/
  61. puts "Bumped: #{$1}"
  62. create_ticket(tags, $1, future_work)
  63. next
  64. else
  65. puts "unrecognized line: #{line}"
  66. end unless line.strip == ""
  67. end
Add Comment
Please, Sign In to add comment