Last active
October 23, 2015 19:00
-
-
Save deanpcmad/4f3174ae582adf5d5f5e to your computer and use it in GitHub Desktop.
Codebase to Bitbucket
This file contains 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 | |
# Install codebase_api & bitbucket_rest_api gems | |
# Edit as required | |
# Run this file | |
# Sit back and watch it do its thing! | |
require "rubygems" | |
require "codebase_api" | |
require "bitbucket_rest_api" | |
CodebaseApi.account_user = "account/user" | |
CodebaseApi.api_key = "apikey" | |
bitbucket = BitBucket.new basic_auth: "username:password" | |
@account = "" | |
@username = "" | |
# PROJECTS = [""] | |
projects = CodebaseApi::Project.all | |
projects.each do |project| | |
proj = project["project"]["name"].downcase.gsub(/\s+/, "-") | |
# next if PROJECTS.include? proj | |
begin | |
bitbucket.repos.get @account, proj | |
puts "√ - Project/Repo #{proj} found. Importing tickets...".green | |
pages = 12 | |
alltickets = [] | |
begin | |
pages.times do |p| | |
alltickets.push(*CodebaseApi::Request.request("#{proj}/tickets?page=#{p}")) | |
end | |
rescue | |
end | |
alltickets.reverse.each do |t| | |
user = begin | |
if @username.empty? | |
if t["ticket"]["assignee"] == "dean" | |
"deanperry" | |
elsif t["ticket"]["assignee"] == "dannymcc" | |
"dannymcclelland" | |
end | |
else | |
@username | |
end | |
end | |
status = begin | |
if !t["ticket"]["status"].empty? | |
if t["ticket"]["status"]["name"] == "New" | |
"new" | |
elsif t["ticket"]["status"]["name"] == "Completed" | |
"resolved" | |
elsif t["ticket"]["status"]["name"] == "On Hold" | |
"on-hold" | |
elsif t["ticket"]["status"]["name"] == "Invalid" | |
"invalid" | |
else | |
"resolved" | |
end | |
end | |
end | |
i = bitbucket.issues.create(@account, proj, { | |
title: t["ticket"]["summary"], | |
content: t["ticket"][""], | |
responsible: user, | |
priority: "minor", | |
status: status, | |
kind: "task" | |
}) | |
notes = CodebaseApi::Ticket.show proj, t["ticket"]["ticket_id"] | |
notes.each do |n| | |
bitbucket.issues.comments.create(@account, proj, i.local_id, { content: n["ticket_note"]["content"] }) unless n["ticket_note"]["content"].empty? | |
end | |
end | |
rescue BitBucket::Error::NotFound | |
puts "x - Project/Repo #{proj} not found. Skipping...".red | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment