[前][次][番号順一覧][スレッド一覧]

ruby-changes:33055

From: usa <ko1@a...>
Date: Sat, 22 Feb 2014 20:29:25 +0900 (JST)
Subject: [ruby-changes:33055] usa:r45134 (trunk): * tool/redmine-backporter.rb: more friendly.

usa	2014-02-22 20:29:21 +0900 (Sat, 22 Feb 2014)

  New Revision: 45134

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45134

  Log:
    * tool/redmine-backporter.rb: more friendly.

  Modified files:
    trunk/ChangeLog
    trunk/tool/redmine-backporter.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 45133)
+++ ChangeLog	(revision 45134)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Feb 22 20:28:47 2014  NAKAMURA Usaku  <usa@r...>
+
+	* tool/redmine-backporter.rb: more friendly.
+
 Sat Feb 22 20:24:43 2014  Kouhei Sutou  <kou@c...>
 
 	* test/rexml/test_xpath*.rb: Move to ...
Index: tool/redmine-backporter.rb
===================================================================
--- tool/redmine-backporter.rb	(revision 45133)
+++ tool/redmine-backporter.rb	(revision 45134)
@@ -1,20 +1,40 @@ https://github.com/ruby/ruby/blob/trunk/tool/redmine-backporter.rb#L1
 #!/usr/bin/env ruby
 require 'open-uri'
+require 'openssl'
 require 'net/http'
 require 'json'
 require 'io/console'
 require 'stringio'
 require 'strscan'
+require 'optparse'
 require 'pp'
 
-TARGET_VERSION = ENV['TARGET_VERSION']
-RUBY_REPO_PATH = ENV['RUBY_REPO_PATH']
+VERSION = '0.0.1'
+
+opts = OptionParser.new
+target_version = nil
+repo_path = nil
+api_key = nil
+ssl_verify = true
+opts.on('-k REDMINE_API_KEY', '--key=REDMINE_API_KEY', 'specify your REDMINE_API_KEY') {|v| api_key = v}
+opts.on('-t TARGET_VERSION', '--target=TARGET_VARSION', /\A\d(?:\.\d)+\z/, 'specify target version (ex: 2.1)') {|v| target_version = v}
+opts.on('-r RUBY_REPO_PATH', '--repository=RUBY_REPO_PATH', 'specify repository path') {|v| repo_path = v}
+opts.on('--[no-]ssl-verify', TrueClass, 'use / not use SSL verify') {|v| ssl_verify = v}
+opts.version = VERSION
+opts.parse!(ARGV)
+
+http_options = {use_ssl: true}
+http_options[:verify_mode] = OpenSSL::SSL::VERIFY_NONE unless ssl_verify
+openuri_options = {}
+openuri_options[:ssl_verify_mode] = OpenSSL::SSL::VERIFY_NONE unless ssl_verify
+
+TARGET_VERSION = target_version || ENV['TARGET_VERSION'] || (raise 'need to specify TARGET_VERSION')
+RUBY_REPO_PATH = repo_path || ENV['RUBY_REPO_PATH']
 BACKPORT_CF_KEY = 'cf_5'
 STATUS_CLOSE = 5
-REDMINE_API_KEY = ENV['REDMINE_API_KEY']
+REDMINE_API_KEY = api_key || ENV['REDMINE_API_KEY'] || (raise 'need to specify REDMINE_API_KEY')
 REDMINE_BASE = 'https://bugs.ruby-lang.org'
 
-VERSION = '0.0.1'
 @query = {
   'f[]' => BACKPORT_CF_KEY,
   "op[#{BACKPORT_CF_KEY}]" => '~',
@@ -219,7 +239,7 @@ while true https://github.com/ruby/ruby/blob/trunk/tool/redmine-backporter.rb#L239
   when 'ls'
     uri = URI(REDMINE_BASE+'/projects/ruby-trunk/issues.json?'+URI.encode_www_form(@query))
     # puts uri
-    res = JSON(uri.read)
+    res = JSON(uri.read(openuri_options))
     @issues = issues = res["issues"]
     from = res["offset"] + 1
     total = res["total_count"]
@@ -235,7 +255,7 @@ while true https://github.com/ruby/ruby/blob/trunk/tool/redmine-backporter.rb#L255
     @issue = id
     uri = "#{REDMINE_BASE}/issues/#{id}"
     uri = URI(uri+".json?include=children,attachments,relations,changesets,journals")
-    res = JSON(uri.read)
+    res = JSON(uri.read(openuri_options))
     i = res["issue"]
     id = "##{i["id"]}".color(*PRIORITIES[i["priority"]["name"]])
     sio = StringIO.new
@@ -270,24 +290,32 @@ eom https://github.com/ruby/ruby/blob/trunk/tool/redmine-backporter.rb#L290
     more(sio)
 
   when 's'
+    unless @issue
+      puts "ticket not selected"
+      next
+    end
     puts backport_command_string
 
   when /\Adone(?: +(\d+))?(?: -- +(.*))?\z/
     notes = $2
     if $1
-      i = issue.to_i
+      i = $1.to_i
       i = @issues[i]["id"] if @issues && i < @issues.size
       @issue = i
     end
+    unless @issue
+      puts "ticket not selected"
+      next
+    end
 
     uri = URI("#{REDMINE_BASE}/issues/#{@issue}.json")
-    Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
+    Net::HTTP.start(uri.host, uri.port, http_options) do |http|
       res = http.get(uri.path)
       data = JSON(res.body)
       h = data["issue"]["custom_fields"].find{|x|x["id"]==5}
       if h and val = h["value"]
         case val[/(?:\A|, )#{Regexp.quote TARGET_VERSION}: ([^,]+)/, 1]
-        when 'REQUIRED', 'UNKNOWN', 'DONTNEED'
+        when 'REQUIRED', 'UNKNOWN', 'DONTNEED', 'REJECTED'
           val[*$~.offset(1)] = 'DONE'
         when 'DONE' # , /\A\d+\z/
           puts 'already backport is done'
@@ -316,9 +344,13 @@ eom https://github.com/ruby/ruby/blob/trunk/tool/redmine-backporter.rb#L344
       i = @issues[i]["id"] if @issues && i < @issues.size
       @issue = i
     end
+    unless @issue
+      puts "ticket not selected"
+      next
+    end
 
     uri = URI("#{REDMINE_BASE}/issues/#{@issue}.json")
-    Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
+    Net::HTTP.start(uri.host, uri.port, http_options) do |http|
       data = { "issue" => { "status_id" => STATUS_CLOSE } }
       res = http.put(uri.path, JSON(data),
                      'X-Redmine-API-Key' => REDMINE_API_KEY,
@@ -333,14 +365,25 @@ eom https://github.com/ruby/ruby/blob/trunk/tool/redmine-backporter.rb#L365
       i = @issues[i]["id"] if @issues && i < @issues.size
       @issue = i
     end
+    unless @issue
+      puts "ticket not selected"
+      next
+    end
 
     uri = URI("#{REDMINE_BASE}/issues/#{@issue}.json")
-    Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
+    Net::HTTP.start(uri.host, uri.port, http_options) do |http|
       show_last_journal(http, uri)
     end
   when ''
   when nil, 'quit', 'exit'
     exit
+  when 'help'
+    puts 'ls                     '.color(bold: true) + ' show all required tickets'
+    puts 'show TICKET            '.color(bold: true) + ' show the detail of the TICKET, and select it'
+    puts 'TICKET                 '.color(bold: true) + ' show the backport option of the selected ticket for merger.rb'
+    puts 'done [TICKET] [-- NOTE]'.color(bold: true) + ' set Backport field of the TICKET to DONE'
+    puts 'close [TICKET]         '.color(bold: true) + ' close the TICKET'
+    puts 'last [TICKET]          '.color(bold: true) + ' show the last journal of the TICKET'
   else
     puts "error #{l.inspect}"
   end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]