From 5383c302a3dcf699ac57295681412bb5ac15e801 Mon Sep 17 00:00:00 2001 From: Robert Buels Date: Sun, 17 Apr 2011 17:54:49 -0700 Subject: [PATCH 1/5] suppress curl status output, instead printing the ticket that is being migrated, and print github's response if a curl req fails --- migrate-lh-to-gh.rb | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/migrate-lh-to-gh.rb b/migrate-lh-to-gh.rb index 8925a93..29bd1dc 100755 --- a/migrate-lh-to-gh.rb +++ b/migrate-lh-to-gh.rb @@ -7,6 +7,19 @@ require 'yaml' require 'uri' +# just pass the cmd string to curl, but run it silently and print the +# response if there was an error +def curl(cmd) + begin + gh_ret = `curl -s #{cmd}` + rescue Exception + warn "Request failed:\n" + warn gh_return_value + raise + end + return gh_ret +end + # ----------------------------------------------------------------------------------------------- # --- Lighthouse configuration LIGHTHOUSE_ACCOUNT = 'YOUR_ACCOUNT_NAME' @@ -63,6 +76,8 @@ assignee = versions.last.assigned_user_name unless versions.last.attributes["assigned_user_name"].nil? # why gsub? -> curl -F 'title=@xxx' -> 'title= @xxx' cause =@xxx means xxx is a file to upload http://curl.haxx.se/docs/manpage.html#-F--form + puts "migrating issue \##{ticket.id} '#{ticket.title}'\n"; + title = ticket.title.gsub(/^@/," @") body = versions.first.body.gsub(/^@/," @") unless versions.first.body.nil? body||="" @@ -81,16 +96,16 @@ versions.delete_at(0) # create the GH issue and get its newly created id - gh_return_value = `curl -F 'login=#{GITHUB_LOGIN}' -F 'token=#{GITHUB_API_TOKEN}' -F 'title=#{title}' -F 'body=#{body}' #{GITHUB_NEW_ISSUE_API_URL}` + gh_return_value = curl("-F 'login=#{GITHUB_LOGIN}' -F 'token=#{GITHUB_API_TOKEN}' -F 'title=#{title}' -F 'body=#{body}' #{GITHUB_NEW_ISSUE_API_URL}") gh_issue_id = YAML::load(gh_return_value)["issue"]["number"] - + # add comments to the newly created GH issue versions.each { |version| # add the LH comment title to the comment comment = "**#{version.title.gsub(/^@/," @").gsub(/'/,"’")}**\n\n" comment+=version.body.gsub(/^@/," @").gsub(/'/,"’") unless version.body.nil? comment+="\n\n by " + version.user_name.gsub(/^@/," @").gsub(/'/,"’") unless version.user_name.nil? - `curl -F 'login=#{GITHUB_LOGIN}' -F 'token=#{GITHUB_API_TOKEN}' -F 'comment=#{comment}' #{GITHUB_ADD_COMMENT_API_URL}/#{gh_issue_id}` + curl("-F 'login=#{GITHUB_LOGIN}' -F 'token=#{GITHUB_API_TOKEN}' -F 'comment=#{comment}' #{GITHUB_ADD_COMMENT_API_URL}/#{gh_issue_id}") } # here you can specify the labels you want to be applied to your newly created GH issue @@ -110,6 +125,6 @@ gh_labels.each { |label| # labels containing . do not work ... -> replace . by • label.gsub!(/\./,"•") - `curl -F 'login=#{GITHUB_LOGIN}' -F 'token=#{GITHUB_API_TOKEN}' #{GITHUB_ADD_LABEL_API_URL}/#{URI.escape(label)}/#{gh_issue_id}` + curl("-F 'login=#{GITHUB_LOGIN}' -F 'token=#{GITHUB_API_TOKEN}' #{GITHUB_ADD_LABEL_API_URL}/#{URI.escape(label)}/#{gh_issue_id}") } -} \ No newline at end of file +} From 4929877f60f3c8881c460d8a25b12bfb8d99e2ee Mon Sep 17 00:00:00 2001 From: Robert Buels Date: Sun, 17 Apr 2011 18:05:46 -0700 Subject: [PATCH 2/5] sleep a bit after every ticket to avoid going over api rate limit --- migrate-lh-to-gh.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/migrate-lh-to-gh.rb b/migrate-lh-to-gh.rb index 29bd1dc..1c17ceb 100755 --- a/migrate-lh-to-gh.rb +++ b/migrate-lh-to-gh.rb @@ -127,4 +127,6 @@ def curl(cmd) label.gsub!(/\./,"•") curl("-F 'login=#{GITHUB_LOGIN}' -F 'token=#{GITHUB_API_TOKEN}' #{GITHUB_ADD_LABEL_API_URL}/#{URI.escape(label)}/#{gh_issue_id}") } + + sleep 1.5 # avoid going over github API rate limit } From 5e1ce1ea080e4c7e93a4e23fc168c7193963b622 Mon Sep 17 00:00:00 2001 From: Robert Buels Date: Thu, 26 Jan 2012 12:19:56 -0500 Subject: [PATCH 3/5] add support for github orgs --- migrate-lh-to-gh.rb | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/migrate-lh-to-gh.rb b/migrate-lh-to-gh.rb index 1c17ceb..8c7582f 100755 --- a/migrate-lh-to-gh.rb +++ b/migrate-lh-to-gh.rb @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- # Created by Thomas Balthazar, Copyright 2009 # This script is provided as is, and is released under the MIT license : http://www.opensource.org/licenses/mit-license.php # more information here : http://suitmymind.com/2009/04/18/move-your-tickets-from-lighthouse-to-github/ @@ -35,12 +36,13 @@ def curl(cmd) GITHUB_LOGIN = "YOUR_ACCOUNT_NAME" GITHUB_API_TOKEN = "YOUR_API_TOKEN" GITHUB_PROJECT = "YOUR_GITHUB_PROJECT_NAME" +GITHUB_ORG = "YOUR_ORGANIZATION_NAME" # do not modify -GITHUB_NEW_ISSUE_API_URL = "https://github.com/api/v2/yaml/issues/open/#{GITHUB_LOGIN}/#{GITHUB_PROJECT}" -GITHUB_ADD_LABEL_API_URL = "https://github.com/api/v2/yaml/issues/label/add/#{GITHUB_LOGIN}/#{GITHUB_PROJECT}" -GITHUB_ADD_COMMENT_API_URL = "https://github.com/api/v2/yaml/issues/comment/#{GITHUB_LOGIN}/#{GITHUB_PROJECT}" +GITHUB_NEW_ISSUE_API_URL = "https://github.com/api/v2/yaml/issues/open/#{GITHUB_ORG}/#{GITHUB_PROJECT}" +GITHUB_ADD_LABEL_API_URL = "https://github.com/api/v2/yaml/issues/label/add/#{GITHUB_ORG}/#{GITHUB_PROJECT}" +GITHUB_ADD_COMMENT_API_URL = "https://github.com/api/v2/yaml/issues/comment/#{GITHUB_ORG}/#{GITHUB_PROJECT}" # ----------------------------------------------------------------------------------------------- From bfe8c3cbc904287661cd5b5743a438a1ae7967f1 Mon Sep 17 00:00:00 2001 From: Robert Buels Date: Thu, 26 Jan 2012 12:21:13 -0500 Subject: [PATCH 4/5] print github's response for diagnostics if we can't parse it --- migrate-lh-to-gh.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/migrate-lh-to-gh.rb b/migrate-lh-to-gh.rb index 8c7582f..cb9beba 100755 --- a/migrate-lh-to-gh.rb +++ b/migrate-lh-to-gh.rb @@ -99,7 +99,13 @@ def curl(cmd) # create the GH issue and get its newly created id gh_return_value = curl("-F 'login=#{GITHUB_LOGIN}' -F 'token=#{GITHUB_API_TOKEN}' -F 'title=#{title}' -F 'body=#{body}' #{GITHUB_NEW_ISSUE_API_URL}") - gh_issue_id = YAML::load(gh_return_value)["issue"]["number"] + + begin + gh_issue_id = YAML::load(gh_return_value)["issue"]["number"] + rescue Exception + warn "Failed to parse github result:\n#{gh_return_value}" + next + end # add comments to the newly created GH issue versions.each { |version| From bfabc8d2fc569d775ac06cc6407ddc260906a8ca Mon Sep 17 00:00:00 2001 From: Robert Buels Date: Thu, 26 Jan 2012 12:21:49 -0500 Subject: [PATCH 5/5] add even more delay to avoid the github rate limit --- migrate-lh-to-gh.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/migrate-lh-to-gh.rb b/migrate-lh-to-gh.rb index cb9beba..9a56f03 100755 --- a/migrate-lh-to-gh.rb +++ b/migrate-lh-to-gh.rb @@ -136,5 +136,5 @@ def curl(cmd) curl("-F 'login=#{GITHUB_LOGIN}' -F 'token=#{GITHUB_API_TOKEN}' #{GITHUB_ADD_LABEL_API_URL}/#{URI.escape(label)}/#{gh_issue_id}") } - sleep 1.5 # avoid going over github API rate limit + sleep 3 # avoid going over github API rate limit }