From 50de4e2d61acfd3e494690f0a8d2daf18c18f54d Mon Sep 17 00:00:00 2001 From: katsuyan Date: Fri, 28 Dec 2018 16:02:33 +0900 Subject: [PATCH 1/2] my redmine --- .gitignore | 1 + redmine2github.rb | 54 +++++++++++++++++++++++++++++------------------ 2 files changed, 34 insertions(+), 21 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..72eb7c8 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +issues.csv diff --git a/redmine2github.rb b/redmine2github.rb index 6854072..a63c009 100644 --- a/redmine2github.rb +++ b/redmine2github.rb @@ -1,3 +1,5 @@ +# -*- encoding: utf-8 -*- + require "rubygems" require "highline/import" require "rest-client" @@ -9,6 +11,7 @@ require "reverse-markdown" require "nokogiri" require "json" +require "openssl" options = {} @@ -32,7 +35,7 @@ opt.on("-m", "--convert-to-markdown", "Convert comment to markdown") do options[:convert_markdown] = true end - + opt.on("-s", "--skip-ssl-cert") do OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE end @@ -45,14 +48,14 @@ opt.on("-v","--verbose", "Turn on verbose output") do options[:verbose] = true end - + opt.on("-h", "--help", "help") do puts opt_parser exit end - + end opt_parser.parse! @@ -74,7 +77,7 @@ puts "Authenticating..." begin - res = RestClient.get api_uri + res = RestClient.get api_uri rescue Exception => e puts "Could not connect " + e.message exit @@ -84,7 +87,7 @@ repo = ARGV[1] csv_file = ARGV[2] -if options[:user_file] +if options[:user_file] users = YAML.load_file(options[:user_file]) end @@ -92,7 +95,7 @@ redmine_issues = [] -CSV.foreach(csv_file, :headers => true) do |row| +CSV.foreach(csv_file, :headers => true, :encoding => "Shift_JIS:UTF-8") do |row| redmine_issues.push(row) end @@ -100,21 +103,25 @@ redmine_issues.reverse! redmine_issues.each do |row| + puts '++++++++++++++++++++++++++++++++++++++++++++' + p row + puts '++++++++++++++++++++++++++++++++++++++++++++' + issue_num = row[0] - tracker = row['Tracker'] - priority = row['Priority'] - subject = row['Subject'] - assigned_to = row['Assignee'] || row['Assigned to'] - description = row['Description'] - status = row['Status'] + tracker = row['トラッカー'] + priority = row['カテゴリ'] + subject = row['題名'] + assigned_to = row['担当者'] || row['作成者'] + description = row['説明'] + status = row['ステータス'] # check for exporting commit if options[:redmine] r = options[:redmine] - url = "#{r[1]}/issues/show/#{issue_num}?format=atom&key=#{r[0]}" - + url = "#{r[1]}/issues/#{issue_num}?format=atom&key=#{r[0]}" + comments = [] - + # parse comment doc = Nokogiri::XML(open(url)) doc.css('entry').each do |entry| @@ -139,7 +146,11 @@ 'date' => fdate, 'content' => content }) - end + end + end + + if description.nil? + description = '' end # verbose output @@ -151,14 +162,14 @@ puts "Assignee: #{assigned_to}" puts "Status: #{status}" puts "Description: #{description.strip}" - puts - + puts + if !comments.empty? puts "Comments (#{comments.size})" puts i=0 comments.each do |comment| - puts "Comment ##{i=i+1}" + puts "Comment ##{i=i+1}" puts "author: #{comment['name']}" puts "date: #{comment['date']}" puts "content: #{comment['content'].strip}" @@ -217,7 +228,7 @@ body = body + "#{comment['content'].strip}" params = {"body" => body} comment_uri = "#{api_uri}/repos/#{repo_user}/#{repo}/issues/#{github_issue_num}/comments" - + res = RestClient.post comment_uri, params.to_json, :content_type => :json end @@ -230,8 +241,9 @@ params = {state: 'closed'} res = RestClient.patch update_issue_uri, params.to_json, :content_type => :json, :accept => :json end - + rescue Exception => e + p e puts "Could not connect " + e.message puts e.backtrace.join("\n") exit From 231963660b9308cd7801ad497ec3ab174a2f977c Mon Sep 17 00:00:00 2001 From: katsuyan Date: Fri, 28 Dec 2018 18:16:33 +0900 Subject: [PATCH 2/2] fix --- .gitignore | 1 + redmine2github.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 72eb7c8..f55cc2f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ issues.csv +issues-utf8.csv diff --git a/redmine2github.rb b/redmine2github.rb index a63c009..aa533ce 100644 --- a/redmine2github.rb +++ b/redmine2github.rb @@ -95,7 +95,7 @@ redmine_issues = [] -CSV.foreach(csv_file, :headers => true, :encoding => "Shift_JIS:UTF-8") do |row| +CSV.foreach(csv_file, :headers => true) do |row| redmine_issues.push(row) end