Trac2Unfuddle: TRAC Import Script

The Trac2Unfuddle Ruby script makes it very simple to import your existing TRAC project into your Unfuddle account using the Unfuddle API.

To use the script, you must have Ruby and RubyGems installed. You may also need to install some prerequisite gems, if you do not already have them installed:

sudo gem install sqlite3-ruby xml-simple

or if you are using MySQL as the database engine for your trac project:

sudo gem install mysql2 xml-simple

Some TRAC installations use the older Sqlite2 database format. If this is true for your project, then you will need to convert your TRAC database to Sqlite3 first. To do this, you must install both sqlite2 and sqlite3 for your platform and then do the following:

cd /path/to/trac_project/db/
mv trac.db trac.v2.db
sqlite trac.v2.db .dump | sqlite3 trac.db

Finally, you just need to modify the very top of the trac2unfuddle.rb script with some very basic information about Unfuddle account and TRAC project.

NOTE: If the usernames in your Unfuddle account are different than they were in your TRAC project, you must modify the USERNAME_MAP variable to indicate how the usernames should be translated over.

Now, run the script:

ruby trac2unfuddle.rb

That's it! You should now see a running log of each object being created within your Unfuddle account.

Download trac2unfuddle.rb now and start Unfuddling that TRAC project!

Pop2Ticket: Tickets from Email

Pop2Ticket.rb is a very basic Ruby script that, when run routinely from a cron job, will convert emails from a POP email account (like bugs@mycompany.com) into Unfuddle tickets.

This script is an excellent starting point for integrating Unfuddle more deeply with your existing support processes. It should be customized as needed.

Thanks to loesol from the Unfuddle Community for putting this script together.

# pop emails off of a mail server and create a ticket in
# an unfuddle project for each one
# requires the 'tmail' gem to be installed
require 'rubygems'
require 'net/https'
require 'net/pop'
require 'tmail'

UNFUDDLE_SETTINGS = {
  :subdomain  => 'mysubdomain',
  :username   => 'username',
  :password   => 'password',
  :ssl        => true,
  :project_id => 1234
}

POP3_SETTINGS = {
  :server     => 'pop.myserver.com',
  :port       => 110,
  :username   => 'myusername',
  :password   => 'mypassword',
  :delete     => false
}

def xml_escape(s); s.gsub('&', '&amp;').gsub('<','&lt;').gsub('>', '&gt;'); end

http = Net::HTTP.new("#{UNFUDDLE_SETTINGS[:subdomain]}.unfuddle.com", UNFUDDLE_SETTINGS[:ssl] ? 443 : 80)

# if using ssl, then set it up
if UNFUDDLE_SETTINGS[:ssl]
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end

# connect to the pop3 server and create a ticket per email
# then optionally delete the message off the server
# the format of the xml could get a lot more robust (components, severities, more info from the tmail object, etc.)
Net::POP3.start(POP3_SETTINGS[:server], POP3_SETTINGS[:port], POP3_SETTINGS[:username], POP3_SETTINGS[:password]) do |pop|
  pop.each_mail { |message|
    email = TMail::Mail.parse(message.pop)
    request = Net::HTTP::Post.new("/api/v1/projects/#{UNFUDDLE_SETTINGS[:project_id]}/tickets", {'Content-type' => 'application/xml'})
    request.basic_auth UNFUDDLE_SETTINGS[:username], UNFUDDLE_SETTINGS[:password]
    request.body = "<ticket><priority>1</priority><summary>#{xml_escape(email.subject)}</summary><description>From: #{xml_escape(email.from.join(','))}\n\n#{xml_escape(email.body)}</description></ticket>"
    response = http.request(request)
    message.delete if POP3_SETTINGS[:delete]
  }
end