Skip to content

Instantly share code, notes, and snippets.

@tjchambers
Created July 7, 2013 20:57
Show Gist options
  • Save tjchambers/5944920 to your computer and use it in GitHub Desktop.
Save tjchambers/5944920 to your computer and use it in GitHub Desktop.
Convert Omnifocus Export to GitHub issues with labels
# uses gem github_api
# http://peter-murach.github.com/github (thanks!)
#
require 'github_api'
require 'csv'
class OmniGitHub
# converts OmniFocus export to issues with labels in GutHub repository
def initialize (user,password,target_user,target_repo)
@target_user = target_user
@target_repo = target_repo
@github = Github.new basic_auth: "#{user}:#{password}", repo: "#{@target_user}/#{@target_repo}"
@labels = []
@new_labels = {}
@pass = 1
end
def alternate_labels(label_replacement_hash)
@new_labels = label_replacement_hash
end
def publish (file)
@file_name = file
process
make_labels
process
end
def make_labels
puts 'adding labels ',@labels.to_s
@labels.each do |label|
@github.issues.labels.create @target_user, @target_repo, name: label, color:'FFFFFF'
end
end
def process
CSV.foreach(@file_name) do |row|
@line = row
@pass == 1 ? add_label : add_issue
end
@pass = @pass+1
end
def add_label
content = @line
return unless content[1] == 'Action'
try_label content[3]
try_label content[4]
end
def try_label(label)
return if label.nil? || label.empty?
# convert certain labels
test_label = convert_label(label)
@labels << test_label
@labels.flatten!
@labels.uniq!
@labels.map {|l| l.downcase}
end
def convert_label(label)
return label.downcase unless @new_labels.include? label
@new_labels[label]
end
def add_issue
content = @line
return unless content[1] == 'Action'
text = cleanup(content[2])
note = expand(content[10])
@labels = []
try_label content[3]
try_label content[4]
@github.issues.create @target_user, @target_repo, 'title' => text, 'body' => note, 'labels' => @labels
end
def expand(text)
return '' if text.nil? || text.empty?
# get more lines
return text if text[0] != '"'
end
# performs any text cleanup for example stripping off leading '- '
def cleanup(text)
# text = text[2..-1]if text.start_with?('- ')
text
end
end
# usage - setup object , add any label conversions, and process
o = OmniGitHub.new('user','password','user','repo')
o.alternate_labels ({'old'=>['new1','new2']} )
o.publish("Omnifocus.csv")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment