edmz / csv2lighthouse

Import tickets to Lighthouse from a basic CSV file

This URL has Read+Write access

csv2lighthouse / csv2lighthouse.rb
100644 47 lines (38 sloc) 0.996 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env ruby
 
require 'rubygems'
require 'activerecord'
require 'activesupport'
require 'activeresource'
require 'lighthouse'
require 'fastercsv'
 
# Configure Me... #####################################################
 
# Enter your Lighthouse account and token. The token must have both
# read & write access.
Lighthouse.account = ''
Lighthouse.token = ''
 
# Your Lighthouse Project ID
PROJECT_ID = 12345
 
def save_to_lighthouse(record)
  t = Lighthouse::Ticket.new(:project_id => PROJECT_ID,
                             :title => record['title'],
                             :body => record['description'])
  p record['title']
  t.tags << taggify(record['tags'])
  t.save
  t
end
 
def taggify(s)
  return "" if s.nil?
  s.downcase.gsub(/[^a-z0-9\-_@\!' ]/,'').strip
end
 
def import(fname)
  FasterCSV.foreach(fname, :headers => :first_row) do |row|
    save_to_lighthouse(row)
  end
end
 
unless ARGV.length > 0
  puts "No file specified."
  Process.exit(1)
else
  import(ARGV[0])
end