<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array">
    <added>
      <filename>LICENSE</filename>
    </added>
  </added>
  <modified type="array">
    <modified>
      <diff>@@ -1,58 +1,32 @@
-Trachouse v1.0.0 fork (adds basic authentication support)
-Author: Maxim Chernyak
-Email: max@bitsonnet.com
+Trac to Lighthouse ticket importer
 
-This fork adds a simple trac basic authentication support.
+Original Author: Shay Arnett &lt;shayarnett@gmail.com&gt;
 
-USE:
-	Follow instructions in the original README below
-	There are 3 more commented sections you need to edit:
-		- set @trac_basic_auth to true
-		- set @trac_http_user to your basic auth username
-		- set @trac_http_pass to your basic auth password
+Contributions by :
+    Maxim Chernyak &lt;max@bitsonnet.com&gt;
+    Jo&#227;o Abecasis &lt;joao@abecasis.name&gt;
 
 
+NOTES
+-----
 
-Original README
--------------------------------
+You'll need to get lighthouse.rb from
+http://ar-code.svn.engineyard.com/lighthouse-api/lib
+
+Enter Lighthouse and Trac configuration data in the ###marked### sections.
+
+Usage:
+
+    require 'trachouse'
+
+    t = Ticket.new
+
+    # grabs all tickets from trac
+    tickets = t.populate_tickets
+    # import tickets to lighthouse
+    t.import_tickets(tickets)
+    # profit
+
+You may want to inspect tickets and import a subset for testing, before
+bulk processing all tickets.
 
-Trachouse v1.0.0
-Trac to Lighthouse ticket importer
-Author: Shay Arnett 
-Website: http://shayarnett.com/trachouse (soonish)
-Email: shayarnett@gmail.com
-
-You will need to obtain a copy of lighthouse.rb from the Lighthouse API
-http://forum.activereload.net/forums/6/topics/44
-
-Please read all commented sections, as most have something you will need to change directly below it
-
-USE:
-
-  @tickets = populate_tickets # grabs all tickets from trac
-  import_tickets(@tickets) # import tickets to lighthouse
-  # profit
-  # you may want to inspect @tickets or only import a couple of tickets to verify format before processing all tickets
-
-Copyright (c) 2008 Shay Arnett
-
-Permission is hereby granted, free of charge, to any person
-obtaining a copy of this software and associated documentation
-files (the &quot;Software&quot;), to deal in the Software without
-restriction, including without limitation the rights to use,
-copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the
-Software is furnished to do so, subject to the following
-conditions:
-
-The above copyright notice and this permission notice shall be
-included in all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND,
-EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
-OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
-HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
-WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
-FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
-OTHER DEALINGS IN THE SOFTWARE.</diff>
      <filename>README</filename>
    </modified>
    <modified>
      <diff>@@ -1,41 +1,39 @@
-# Trachouse v1.0.0 fork (adds basic authentication support)
-# Author: Maxim Chernyak
-# Email: max@bitsonnet.com
-# 
-# This fork adds a simple trac basic authentication support.
-# 
-# USE:
-#   Follow instructions in the original README below
-#   There are 3 more commented sections you need to edit:
-#     - set @trac_basic_auth to true
-#     - set @trac_http_user to your basic auth username
-#     - set @trac_http_pass to your basic auth password
-# 
-# 
-# 
-# Original README
-# -------------------------------
-# 
-# Trachouse v1.0.0
-# Trac to Lighthouse ticket importer
-# Author: Shay Arnett 
-# Website: http://shayarnett.com/trachouse (soonish)
-# Email: shayarnett@gmail.com
-# 
-# You will need to obtain a copy of lighthouse.rb from the Lighthouse API
-# http://forum.activereload.net/forums/6/topics/44
-# 
-# Please read all commented sections, as most have something you will need to change directly below it
-# 
-# USE:
-# 
-#   @tickets = populate_tickets # grabs all tickets from trac
-#   import_tickets(@tickets) # import tickets to lighthouse
-#   # profit
-#   # you may want to inspect @tickets or only import a couple of tickets to verify format before processing all tickets
-# 
+#
+#   Trac to Lighthouse ticket importer
+#
+#   Original Author: Shay Arnett &lt;shayarnett@gmail.com&gt;
+#
+#   Contributions by :
+#       Maxim Chernyak &lt;max@bitsonnet.com&gt;
+#       Jo&#227;o Abecasis &lt;joao@abecasis.name&gt;
+#
+#
+#   NOTES
+#   -----
+#
+#   You'll need to get lighthouse.rb from
+#   http://ar-code.svn.engineyard.com/lighthouse-api/lib
+#
+#   Enter Lighthouse and Trac configuration data in the ###marked### sections.
+#
+#   Usage:
+#
+#       require 'trachouse'
+#
+#       t = Ticket.new
+#
+#       # grabs all tickets from trac
+#       tickets = t.populate_tickets
+#       # import tickets to lighthouse
+#       t.import_tickets(tickets)
+#       # profit
+#
+#   You may want to inspect tickets and import a subset for testing, before
+#   bulk processing all tickets.
+
+
 # Copyright (c) 2008 Shay Arnett
-# 
+#
 # Permission is hereby granted, free of charge, to any person
 # obtaining a copy of this software and associated documentation
 # files (the &quot;Software&quot;), to deal in the Software without
@@ -44,10 +42,10 @@
 # copies of the Software, and to permit persons to whom the
 # Software is furnished to do so, subject to the following
 # conditions:
-# 
+#
 # The above copyright notice and this permission notice shall be
 # included in all copies or substantial portions of the Software.
-# 
+#
 # THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND,
 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 # OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -57,65 +55,72 @@
 # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 # OTHER DEALINGS IN THE SOFTWARE.
 
+
 require 'hpricot'
 require 'net/http'
 require 'activeresource'
 require 'lighthouse'
 
-
 class Ticket &lt; ActiveResource::Base
   include Lighthouse
-  # Lighthouse Account Name - Not your username
+
+  ############
+  ### Lighthouse configuration
+  ###
+
+  # Lighthouse Account Name -- NOT your username!
   Lighthouse.account = 'foo_bar'
-  # Lighthouse api token 
+  # Lighthouse API token
   Lighthouse.token = 'xxxxxxxxx'
 
+  ###
+  ### END of Lighthouse configuration
+  ############
+
   def initialize
 
-    @tickets = []
-    @ticket = {}
-    @ticket_list = []
-    @useragent = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-us) AppleWebKit/523.10.6 (KHTML, like Gecko) Version/3.0.4 Safari/523.10.6'
+    ############
+    ### Trac configuration
+    ###
+
+    # URL pointing to root of Trac installation. Don't include '/wiki/WikiStart'
+    # and such. Don't include trailing slash...
+    @trac_url = 'http://trac.example.com/myproject/trac'
 
-    # hostname and port for webserver serving Trac
-    @domain = 'trac.domain.com'
-    @port = '80'
+    # Credentials are required to access user data.
+    # Does Trac use basic http authentication?
+    @trac_basic_auth = true
+    @trac_username = 'tracuser@email.com'
+    @trac_password = 'password'
 
-    # The root of Trac in your webserver
-    @trac_root = ''
+    ###
+    ### END of Trac configuration
+    ############
 
-    @http_address = 'http://' + @domain + ':' + @port
-    @base_url = @http_address + @trac_root
+    @tickets = []
+    @ticket = {}
+    @ticket_list = []
 
-    # trac users e-mail - needed to pull full email address on ticket creator
-    @username = 'tracuser@email.com'
+    @useragent = 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-us) AppleWebKit/523.10.6 (KHTML, like Gecko) Version/3.0.4 Safari/523.10.6'
 
-    # trac users password
-    @password = 'users_password'
+    trac_uri = URI.parse(@trac_url)
+    @trac_host = trac_uri.host
+    @trac_port = trac_uri.port
+    @trac_path = trac_uri.path
 
-    # @base_url + @login is the url for logging into track
-    @login = '/login'
-    
-    # set to true if your trac is using basic http authentication (provide credentials below)
-    @trac_basic_auth = false
-    
-    # trac http username for trac's basic authentication
-    @trac_http_user = 'http_user'
-    
-    # trac http password for trac's basic authentication
-    @trac_http_pass = 'http_password'
+    @trac_address = &quot;http://#{@trac_host}:#{@trac_port}/&quot;
 
     # setup headers for grabbing cookie and tiket info
     @headers = {
-      'Referer' =&gt; @base_url,
+      'Referer' =&gt; @trac_url,
       'User-Agent' =&gt; @useragent
     }
-    
+
     # setup connection
-    @http = Net::HTTP.new(@domain,@port)
-    
+    @http = Net::HTTP.new(@trac_host, @trac_port)
+
     #setup project_ids and associated trac components
-    # :project_id should be the lighthouse id of the project 
+    # :project_id should be the lighthouse id of the project
     #  you want to import the tickets to
     #
     # :components should be an array of the trac components you wish
@@ -124,7 +129,7 @@ class Ticket &lt; ActiveResource::Base
     # project_1 = { :project_id =&gt; 1234,
     #               :components =&gt; ['Core','Module 1', 'etc']}
     # project_2 = { etc }
-    
+
     merb_core = { :project_id =&gt; 7433,
                   :components =&gt; [ 'Merb',
                                    'Web Site',
@@ -146,7 +151,7 @@ class Ticket &lt; ActiveResource::Base
                    }
     # add all your project hashes to @projects
     #
-    # this could have been combined with above, but tended to be less readable 
+    # this could have been combined with above, but tended to be less readable
     # after adding a couple projects
     @projects = [ merb_core, merb_more, merb_plugins ]
   end
@@ -181,10 +186,10 @@ class Ticket &lt; ActiveResource::Base
     # this is all based on a pretty standard trac template
     # if you have done any customizing you will need to check your html
     # and change the necessary Hpricot searches to pull the correct data
-    
+
     # build the base ticket
     ticket = { :title =&gt; (doc/&quot;h2.summary&quot;).inner_html,
-               :trac_url =&gt; '&quot;Original Trac Ticket&quot;:' + @base_url + '/ticket/' + ticket_num,
+               :trac_url =&gt; '&quot;Original Trac Ticket&quot;:' + @trac_url + '/ticket/' + ticket_num,
                :reporter =&gt; (doc/&quot;//td[@headers='h_reporter']&quot;).inner_html,
                :priority =&gt; (doc/&quot;//td[@headers='h_priority']&quot;).inner_html,
                :component =&gt; (doc/&quot;//td[@headers='h_component']&quot;).inner_html,
@@ -194,13 +199,13 @@ class Ticket &lt; ActiveResource::Base
                :comments =&gt; [],
                :attachments =&gt; []
              }
-             
+
     # clean up the description
     Hpricot(ticket[:description]).search(&quot;h3&quot;).remove
     ticket[:description].gsub!(/&lt;\/?pre( class=\&quot;wiki\&quot;)?&gt;/,&quot;@@@\n&quot;)
     ticket[:description].gsub!(/&lt;\/?[^&gt;]*&gt;/, &quot;&quot;)
     ticket[:description] = unescapeHTML(ticket[:description].gsub!(/\n\s*\n\s*\n/,&quot;\n\n&quot;))
-    
+
     # gather and clean up the ticket changes
     changes = []
     (doc/&quot;div.change&quot;).each do |c|
@@ -216,13 +221,13 @@ class Ticket &lt; ActiveResource::Base
     end
     ticket[:comments] = unescapeHTML(ticket[:comments].join(&quot;\n&quot;))
     ticket[:comments].gsub!(/\((follow|in)[^\)]*\)/,'')
-    
+
     # gather and cleanup the attachments
     (doc/&quot;dl.attachments/dt/a&quot;).each do |a|
-      ticket[:attachments] &lt;&lt; + @http_address + &quot;#{a.attributes['href']}&quot;
+      ticket[:attachments] &lt;&lt; + &quot;#{@trac_address}#{a.attributes['href']}&quot;
     end
     ticket[:attachments] = unescapeHTML(ticket[:attachments].join(&quot;\n&quot;))
-    
+
     # put together the final body
     ticket[:body] = [ &quot;Originally posted on Trac by #{ticket[:reporter]}&quot;, ticket[:trac_url], ticket[:description], &quot;h3. Trac Attachments&quot;, ticket[:attachments], &quot;h3. Trac Comments&quot;, ticket[:comments]].join(&quot;\n&quot;)
     ticket[:tags] = [ticket[:priority],ticket[:component]]
@@ -236,7 +241,7 @@ class Ticket &lt; ActiveResource::Base
     if string == nil
       return ''
     end
-    
+
     string.gsub(/&amp;(.*?);/n) do
       match = $1.dup
       case match
@@ -272,17 +277,17 @@ class Ticket &lt; ActiveResource::Base
 
   def steal_cookie
     # get request to gather tokens needed to hijack cookie
-    resp = @http.request_get(@trac_root + @login, {'User-Agent' =&gt; @useragent})
+    resp = @http.request_get(@trac_path + '/login', {'User-Agent' =&gt; @useragent})
     cookie = resp.response['Set-Cookie']
     resp.body.match(/TOKEN\&quot; value\=\&quot;(\w+)\&quot;/)
-    url_params = &quot;user=#{@username}&amp;password=#{@password}&amp;__FORM_TOKEN=#{$1}&quot;
+    url_params = &quot;user=#{@trac_username}&amp;password=#{@trac_password}&amp;__FORM_TOKEN=#{$1}&quot;
     @headers = {
       'Cookie' =&gt; cookie,
-      'Referer' =&gt; @base_url + @login,
+      'Referer' =&gt; @trac_url + '/login',
       'Content-Type' =&gt; 'application/x-www-form-urlencoded'
     }
     # post to login and grab cookie for later
-    resp = @http.request_post(@trac_root + @login, url_params, @headers)
+    resp = @http.request_post(@trac_path + '/login', url_params, @headers)
     cookie = resp.response['Set-Cookie']
 
     @headers = {
@@ -292,16 +297,16 @@ class Ticket &lt; ActiveResource::Base
 
   def get_html_for_ticket(ticket)
     #change url if you go somewhere other than /ticket/1 to pull up ticket #1
-    ticket_url = @trac_root + &quot;/ticket/#{ticket}&quot;
-    
+    ticket_url = @trac_path + &quot;/ticket/#{ticket}&quot;
+
     if @trac_basic_auth
-      resp = Net::HTTP.start(@domain,@port) do |http|
+      resp = Net::HTTP.start(@trac_host, @trac_port) do |http|
         req = Net::HTTP::Get.new(ticket_url)
-        req.basic_auth @trac_http_user, @trac_http_pass
+        req.basic_auth @trac_username, @trac_password
         resp = http.request(req)
       end
       data = resp.body
-    else  
+    else
       # change url in get2() if you go somewhere other than /ticket/1 to pull up ticket #1
       resp, data = @http.get2(ticket_url, @headers)
     end
@@ -315,12 +320,12 @@ class Ticket &lt; ActiveResource::Base
     ticket.body = trac_ticket[:body].to_s
     ticket.save
   end
-  
+
   def import_tickets(tickets)
     if not @trac_basic_auth
       steal_cookie
     end
-    
+
     new_tickets = []
     tickets.each do |ticket|
       # grab the page for this ticket
@@ -330,7 +335,7 @@ class Ticket &lt; ActiveResource::Base
       # add to @tickets[]
       new_tickets &lt;&lt; new_ticket
     end
-    
+
     # create and save to lighthouse
     new_tickets.each do |ticket|
       create_ticket(ticket)
@@ -340,13 +345,13 @@ class Ticket &lt; ActiveResource::Base
   def populate_tickets
     # url should be the path to a trac report that shows you all tickets from
     # all components
-    url = @trac_root + &quot;/report/3&quot;
+    url = @trac_path + &quot;/report/3&quot;
     ticket_list = []
-    
+
     if @trac_basic_auth
-      resp = Net::HTTP.start(@domain,@port) do |http|
+      resp = Net::HTTP.start(@trac_host, @trac_port) do |http|
         req = Net::HTTP::Get.new(url)
-        req.basic_auth @trac_http_user, @trac_http_pass
+        req.basic_auth @trac_username, @trac_password
         resp = http.request(req)
       end
       html = resp.body</diff>
      <filename>trachouse.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>c04e92a1df66cb6551dfb5327ce8efc0d2aa10a3</id>
    </parent>
  </parents>
  <author>
    <name>Jo&#227;o Abecasis</name>
    <email>joao@abecasis.name</email>
  </author>
  <url>http://github.com/shayarnett/trachouse/commit/7e071846ab2ab49f1b1f49f40d70271b7e0cea60</url>
  <id>7e071846ab2ab49f1b1f49f40d70271b7e0cea60</id>
  <committed-date>2008-07-23T02:39:57-07:00</committed-date>
  <authored-date>2008-07-23T02:34:23-07:00</authored-date>
  <message>Consolidated user configuration.

Also, updated README and initial comment blurb with usage instructions.
Moved License from README to LICENSE
Whitespace cleanup.</message>
  <tree>baa478c3f74a4bd2d16b31a43df1eede5eb7e949</tree>
  <committer>
    <name>Jo&#227;o Abecasis</name>
    <email>joao@abecasis.name</email>
  </committer>
</commit>
