Created
October 15, 2010 19:39
-
-
Save jschairb/628801 to your computer and use it in GitHub Desktop.
Simple script to paginate issues in Redmine and load them into Pivotal Tracker.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'active_resource' | |
require 'redmine_client' | |
require 'pivotal-tracker' | |
require 'yaml' | |
ActiveResource::Base.logger = Logger.new(STDOUT) | |
ActiveResource::Base.logger.level = Logger::DEBUG | |
# Ensure that you have the active_resource gem installed on your local system: | |
# gem install active_resource redmine_client pivotal-tracker | |
# Change the script by filling in your credentials. Grab your key from Redmine | |
# under the 'My Account' section in the top right-hand portion. | |
# Create a file called 'credentials.yml' in the same directory as this script. | |
# Make sure it has the following keys: | |
# project_id, project_name, site, user, password, token | |
# Usage: ruby pivotmine.rb | |
# This should output an issue, change the output at the bottom to get it in a format | |
# you want. | |
config = YAML.load_file("credentials.yml") | |
RedmineClient::Base.configure do | |
self.site = config["site"] | |
self.user = config["user"] | |
self.password = config["password"] | |
end | |
PivotalTracker::Client.token = config["token"] | |
PivotalTracker::Client.use_ssl = true | |
projects = PivotalTracker::Project.all | |
pivotal_project = projects.select { |p| p.name == config["project_name"] }.first | |
@page = 1 | |
@per_page = 25 | |
@issue_ids = [] | |
def get_issues(config) | |
ActiveResource::Base.logger.debug("Getting issues") | |
@issues = RedmineClient::Issue.find(:all, | |
:params => { :project_id => config["project_id"], :per_page => @per_page, :page => @page } | |
) | |
ActiveResource::Base.logger.debug("Found #{@issues.count} issues") | |
end | |
get_issues(config) | |
while @issues.count <= @per_page && !@issue_ids.include?(@issues.first.id) | |
@issues.each do |issue| | |
next if @issue_ids.include?(issue.id) | |
@issue_ids << issue.id | |
project = RedmineClient::Project.find(issue.project.id) | |
points = issue.respond_to?(:spent_hours) ? issue.spent_hours : nil | |
addendum = "\n\nhttps://redmine.rackspace.com/issues/#{issue.id}" | |
description = [issue.description.to_s, addendum].join("") | |
issue_hash = { :name => issue.subject, :story_type => "feature", :estimate => points, | |
:description => description, :labels => "[#{project.identifier}]" | |
} | |
begin | |
pivotal_project.stories.create(issue_hash) | |
rescue RestClient::InternalServerError | |
ActiveResource::Base.logger.debug("Error: #{issue_hash.inspect}") | |
next | |
end | |
end | |
# start it all over again | |
@page += 1 | |
get_issues(config) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment