-
Notifications
You must be signed in to change notification settings - Fork 0
/
traclight.rb
executable file
·128 lines (99 loc) · 3.3 KB
/
traclight.rb
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#!/usr/bin/env ruby
# Please see attached LICENSE and README.markdown
require 'rubygems'
require 'activerecord'
require 'activesupport'
require 'activeresource'
require 'lighthouse'
# Configure Me... #####################################################
# Enter your Lighthouse account and token. The token must have both
# read & write access.
Lighthouse.account = 'YOUR_ACCOUNT_NAME'
Lighthouse.token = 'YOUR_VERY_LONG_API_TOKEN'
# Your Lighthouse Project ID
PROJECT_ID = 12345
# A mapping of your Trac usernames to Lighthouse user ID's
USERS = { 'someone' => 12345,
'someone_else' => 23456 }
# A mapping of your Trac Milestones to Lighthouse milestone ID's
MILESTONES = { '1.0' => 1234,
'1.1' => 2345,
'Beta' => 3456 }
# Map your Trac state strings to Lighthouse state strings
STATES = { 'assigned' => 'open',
'fixed' => 'resolved',
'duplicate' => 'invalid',
'wontfix' => 'invalid',
'invalid' => 'invalid',
'new' => 'new',
'closed' => 'resolved',
'worksforme' => 'invalid',
'reopened' => 'open' }
# End of configuration... #############################################
class ActiveRecord::Base
def format_trac_text(text)
text.gsub(/([{}])\1{2}/, '@@@')
end
end
class TracMilestone < ActiveRecord::Base
set_table_name 'milestone'
set_primary_key :name
def save_to_lighthouse
Lighthouse::Milestone.new(:title => name, :goals => description, :project_id => PROJECT_ID, :due_on => Time.at(due))
end
end
class TracChange < ActiveRecord::Base
set_table_name 'ticket_change'
def to_s
"\n*#{author}* commented at #{Time.at(time).strftime('%c')}:\n\n#{format_trac_text(newvalue)}"
end
end
class TracTicket < ActiveRecord::Base
set_table_name 'ticket'
# only comments
has_many :comments, :class_name => 'TracChange', :foreign_key => 'ticket', :conditions => "field = 'comment' AND newvalue != ''", :order => 'time ASC'
# type column is used by trac
def self.inheritance_column
nil
end
def category
attributes['type']
end
def save_to_lighthouse
t = Lighthouse::Ticket.new(:project_id => PROJECT_ID,
:title => summary,
:body => format_trac_text(description),
:assigned_user_id => USERS[owner],
:state => STATES[resolution || status],
:milestone_id => MILESTONES[milestone] )
t.tags << taggify(component) unless component.nil?
t.tags << taggify(priority) unless priority.nil?
t.save
comments.each { |c|
t.body = format_trac_text(c.newvalue)
t.save
}
t
end
def save_comments_to_lighthouse
end
def formatted_comments
returning "h3. Trac Comments\n\n" do |txt|
txt<<comments.each{|c| c.to_s}.join("")
end
end
def taggify(s)
s.downcase.gsub(/ /,'_').gsub(/[^a-z0-9\-_@\!']/,'').strip
end
end
def convert(trac_db, opts=nil)
ActiveRecord::Base.establish_connection(:adapter => 'sqlite3', :database => trac_db)
opts ||= { :order => ('id ASC')}
TracTicket.find(:all, opts).each{|t| t.save_to_lighthouse; true}
end
unless ARGV.length > 0
puts "No trac sqlite database file specified."
Process.exit(1)
else
convert(ARGV[0])
end