mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* tool/redmine-backporter.rb: now can specify shorten form of commands.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49830 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d1d5264c6c
commit
6aff861d60
2 changed files with 78 additions and 24 deletions
|
@ -1,3 +1,7 @@
|
||||||
|
Wed Mar 4 00:29:18 2015 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||||
|
|
||||||
|
* tool/redmine-backporter.rb: now can specify shorten form of commands.
|
||||||
|
|
||||||
Tue Mar 3 23:41:42 2015 NAKAMURA Usaku <usa@ruby-lang.org>
|
Tue Mar 3 23:41:42 2015 NAKAMURA Usaku <usa@ruby-lang.org>
|
||||||
|
|
||||||
* tool/redmine-backporter.rb (Readline.readline): drop untreated control
|
* tool/redmine-backporter.rb (Readline.readline): drop untreated control
|
||||||
|
|
|
@ -7,6 +7,7 @@ require 'io/console'
|
||||||
require 'stringio'
|
require 'stringio'
|
||||||
require 'strscan'
|
require 'strscan'
|
||||||
require 'optparse'
|
require 'optparse'
|
||||||
|
require 'abbrev'
|
||||||
require 'pp'
|
require 'pp'
|
||||||
begin
|
begin
|
||||||
require 'readline'
|
require 'readline'
|
||||||
|
@ -316,17 +317,10 @@ row, col = console.winsize
|
||||||
@query['limit'] = row - 2
|
@query['limit'] = row - 2
|
||||||
puts "Backporter #{VERSION}".color(bold: true) + " for #{TARGET_VERSION}"
|
puts "Backporter #{VERSION}".color(bold: true) + " for #{TARGET_VERSION}"
|
||||||
|
|
||||||
@issues = nil
|
class CommandSyntaxError < RuntimeError; end
|
||||||
@issue = nil
|
commands = {
|
||||||
@changesets = nil
|
"ls" => proc{|args|
|
||||||
while true
|
raise CommandSyntaxError unless /\A(\d+)?\z/ =~ args
|
||||||
begin
|
|
||||||
l = Readline.readline "#{'#' + @issue.to_s if @issue}> "
|
|
||||||
rescue Interrupt
|
|
||||||
break
|
|
||||||
end
|
|
||||||
case l
|
|
||||||
when /\Als(?: +(\d+))?\z/
|
|
||||||
uri = URI(REDMINE_BASE+'/projects/ruby-trunk/issues.json?'+URI.encode_www_form(@query.dup.merge('page' => ($1 ? $1.to_i : 1))))
|
uri = URI(REDMINE_BASE+'/projects/ruby-trunk/issues.json?'+URI.encode_www_form(@query.dup.merge('page' => ($1 ? $1.to_i : 1))))
|
||||||
# puts uri
|
# puts uri
|
||||||
res = JSON(uri.read(openuri_options))
|
res = JSON(uri.read(openuri_options))
|
||||||
|
@ -339,7 +333,10 @@ while true
|
||||||
id = "##{x["id"]}".color(*PRIORITIES[x["priority"]["name"]])
|
id = "##{x["id"]}".color(*PRIORITIES[x["priority"]["name"]])
|
||||||
puts "#{'%2d' % i} #{id} #{x["priority"]["name"][0]} #{status_char(x["status"])} #{x["subject"][0,80]}"
|
puts "#{'%2d' % i} #{id} #{x["priority"]["name"][0]} #{status_char(x["status"])} #{x["subject"][0,80]}"
|
||||||
end
|
end
|
||||||
when /\A(?:show +)?(\d+)\z/
|
},
|
||||||
|
|
||||||
|
"show" => proc{|args|
|
||||||
|
raise CommandSyntaxError unless /\A(\d+)\z/ =~ args
|
||||||
id = $1.to_i
|
id = $1.to_i
|
||||||
id = @issues[id]["id"] if @issues && id < @issues.size
|
id = @issues[id]["id"] if @issues && id < @issues.size
|
||||||
@issue = id
|
@issue = id
|
||||||
|
@ -383,9 +380,15 @@ eom
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
more(sio)
|
more(sio)
|
||||||
|
},
|
||||||
|
|
||||||
when /\Arel +(\d+)\z/
|
"rel" => proc{|args|
|
||||||
# this feature requires custom redmine which allows add_related_issue API
|
# this feature requires custom redmine which allows add_related_issue API
|
||||||
|
raise CommandSyntaxError unless /\A(\d+)\z/ =~ args
|
||||||
|
unless @issue
|
||||||
|
puts "ticket not selected"
|
||||||
|
next
|
||||||
|
end
|
||||||
rev = $1.to_i
|
rev = $1.to_i
|
||||||
uri = URI("#{REDMINE_BASE}/projects/ruby-trunk/repository/revisions/#{rev}/issues.json")
|
uri = URI("#{REDMINE_BASE}/projects/ruby-trunk/repository/revisions/#{rev}/issues.json")
|
||||||
Net::HTTP.start(uri.host, uri.port, http_options) do |http|
|
Net::HTTP.start(uri.host, uri.port, http_options) do |http|
|
||||||
|
@ -393,16 +396,20 @@ eom
|
||||||
'X-Redmine-API-Key' => REDMINE_API_KEY)
|
'X-Redmine-API-Key' => REDMINE_API_KEY)
|
||||||
puts res.body
|
puts res.body
|
||||||
end
|
end
|
||||||
|
},
|
||||||
|
|
||||||
when 'b'
|
"backport" => proc{|args|
|
||||||
# this feature implies backport command which wraps tool/merger.rb
|
# this feature implies backport command which wraps tool/merger.rb
|
||||||
|
raise CommandSyntexError unless args.empty?
|
||||||
unless @issue
|
unless @issue
|
||||||
puts "ticket not selected"
|
puts "ticket not selected"
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
puts backport_command_string
|
puts backport_command_string
|
||||||
|
},
|
||||||
|
|
||||||
when /\Adone(?: +(\d+))?(?: -- +(.*))?\z/
|
"done" => proc{|args|
|
||||||
|
raise CommandSyntaxError unless /\A(\d+)?(?: -- +(.*))?\z/ =~ args
|
||||||
notes = $2
|
notes = $2
|
||||||
notes.strip! if notes
|
notes.strip! if notes
|
||||||
if $1
|
if $1
|
||||||
|
@ -461,7 +468,10 @@ eom
|
||||||
|
|
||||||
show_last_journal(http, uri)
|
show_last_journal(http, uri)
|
||||||
end
|
end
|
||||||
when /\Aclose(?: +(\d+))?\z/
|
},
|
||||||
|
|
||||||
|
"close" => proc{|args|
|
||||||
|
raise CommandSyntaxError unless /\A(\d+)?\z/ =~ args
|
||||||
if $1
|
if $1
|
||||||
i = $1.to_i
|
i = $1.to_i
|
||||||
i = @issues[i]["id"] if @issues && i < @issues.size
|
i = @issues[i]["id"] if @issues && i < @issues.size
|
||||||
|
@ -482,7 +492,10 @@ eom
|
||||||
|
|
||||||
show_last_journal(http, uri)
|
show_last_journal(http, uri)
|
||||||
end
|
end
|
||||||
when /\last(?: +(\d+))?\z/
|
},
|
||||||
|
|
||||||
|
"last" => proc{|args|
|
||||||
|
raise CommandSyntaxError unless /\A(\d+)?\z/ =~ args
|
||||||
if $1
|
if $1
|
||||||
i = $1.to_i
|
i = $1.to_i
|
||||||
i = @issues[i]["id"] if @issues && i < @issues.size
|
i = @issues[i]["id"] if @issues && i < @issues.size
|
||||||
|
@ -497,21 +510,58 @@ eom
|
||||||
Net::HTTP.start(uri.host, uri.port, http_options) do |http|
|
Net::HTTP.start(uri.host, uri.port, http_options) do |http|
|
||||||
show_last_journal(http, uri)
|
show_last_journal(http, uri)
|
||||||
end
|
end
|
||||||
when /\A!\s*(.*)\s*\z/
|
},
|
||||||
system($1)
|
|
||||||
when ''
|
"!" => proc{|args|
|
||||||
when nil, 'quit', 'exit'
|
system(args.strip)
|
||||||
|
},
|
||||||
|
|
||||||
|
"quit" => proc{|args|
|
||||||
|
raise CommandSyntaxError unless args.empty?
|
||||||
exit
|
exit
|
||||||
when 'help'
|
},
|
||||||
|
"exit" => "quit",
|
||||||
|
|
||||||
|
"help" => proc{|args|
|
||||||
puts 'ls [PAGE] '.color(bold: true) + ' show all required tickets'
|
puts 'ls [PAGE] '.color(bold: true) + ' show all required tickets'
|
||||||
puts '[show] TICKET '.color(bold: true) + ' show the detail of the TICKET, and select it'
|
puts '[show] TICKET '.color(bold: true) + ' show the detail of the TICKET, and select it'
|
||||||
puts 'b '.color(bold: true) + ' show the backport option of selected ticket for merger.rb'
|
puts 'backport '.color(bold: true) + ' show the option of selected ticket for merger.rb'
|
||||||
puts 'rel REVISION '.color(bold: true) + ' add the selected ticket as related to the REVISION'
|
puts 'rel REVISION '.color(bold: true) + ' add the selected ticket as related to the REVISION'
|
||||||
puts 'done [TICKET] [-- NOTE]'.color(bold: true) + ' set Backport field of the TICKET to DONE'
|
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 'close [TICKET] '.color(bold: true) + ' close the TICKET'
|
||||||
puts 'last [TICKET] '.color(bold: true) + ' show the last journal of the TICKET'
|
puts 'last [TICKET] '.color(bold: true) + ' show the last journal of the TICKET'
|
||||||
puts '! COMMAND '.color(bold: true) + ' execute COMMAND'
|
puts '! COMMAND '.color(bold: true) + ' execute COMMAND'
|
||||||
else
|
}
|
||||||
|
}
|
||||||
|
list = Abbrev.abbrev(commands.keys)
|
||||||
|
|
||||||
|
@issues = nil
|
||||||
|
@issue = nil
|
||||||
|
@changesets = nil
|
||||||
|
while true
|
||||||
|
begin
|
||||||
|
l = Readline.readline "#{('#' + @issue.to_s).color(bold: true) if @issue}> "
|
||||||
|
rescue Interrupt
|
||||||
|
break
|
||||||
|
end
|
||||||
|
break unless l
|
||||||
|
cmd, args = l.strip.split(/\s+/, 2)
|
||||||
|
next unless cmd
|
||||||
|
if (!args || args.empty?) && /\A\d+\z/ =~ cmd
|
||||||
|
args = cmd
|
||||||
|
cmd = "show"
|
||||||
|
end
|
||||||
|
if commands[cmd].is_a? String
|
||||||
|
cmd = list[cmd]
|
||||||
|
end
|
||||||
|
cmd = list[cmd]
|
||||||
|
begin
|
||||||
|
if cmd
|
||||||
|
commands[cmd].call(args.to_s)
|
||||||
|
else
|
||||||
|
raise CommandSyntaxError
|
||||||
|
end
|
||||||
|
rescue CommandSyntaxError
|
||||||
puts "error #{l.inspect}"
|
puts "error #{l.inspect}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue