Skip to content

Instantly share code, notes, and snippets.

@eddanger
Forked from chip/basecamp2github.rb
Created December 8, 2011 05:23
Show Gist options
  • Save eddanger/1446198 to your computer and use it in GitHub Desktop.
Save eddanger/1446198 to your computer and use it in GitHub Desktop.
Convert Basecamp tasks to Github issues
require 'rubygems'
require 'active_resource'
require 'basecamp'
require 'httparty'
require 'json'
GITHUB_USERNAME = '__GITHUB_USERNAME__'
GITHUB_PASSWORD = '__GITHUB_PASSWORD__'
GITHUB_ORG = '__GITHUB_ORG__'
GITHUB_REPO = '__GITHUB_REPO__'
BASECAMP_DOMAIN = '__BASECAMP_DOMAIN__.basecamphq.com'
BASECAMP_TOKEN = '__BASECAMP_TOKEN__'
BASECAMP_PROJECT_ID = '__BASECAMP_TOKEN__'
class GithubIssues
include HTTParty
base_uri "https://api.github.com"
basic_auth GITHUB_USERNAME, GITHUB_PASSWORD
default_params :output => 'json'
format :json
def self.add(org, repo, title, body, labels=[])
options = {:body => {:title => title, :body => body, :labels => labels }.to_json}
resp = post "/repos/#{org}/#{repo}/issues", options
puts 'Created GitHub Issue #' + resp.parsed_response['number']
end
end
conn = Basecamp.establish_connection!(BASECAMP_DOMAIN, BASECAMP_TOKEN, 'X', true)
todo_lists = Basecamp::TodoList.all(BASECAMP_PROJECT_ID)
todo_lists.each do |todo_list|
puts todo_list.name + "\n"
todo_items = Basecamp::TodoItem.find(:all, :params => { :todo_list_id => todo_list.id })
todo_items.each do |item|
title = item.content
body = "https://#{BASECAMP_DOMAIN}/projects/#{BASECAMP_PROJECT_ID}/todo_items/#{item.id}/comments"
if item.completed == false
GithubIssues.add(GITHUB_ORG, GITHUB_REPO, title, body, ['Basecamp'])
else
puts "item #{item.id} was completed"
end
puts "\n"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment