0
@@ -6,7 +6,7 @@ require 'optparse'
0
# The array of (unparsed) command-line options
0
- attr_reader :action, :options, :args
0
+ attr_reader :action, :options, :args
, :tic0
@@ -20,7 +20,7 @@ module TicGit
0
- @tic = TicGit.open('.'
)
0
+ @tic = TicGit.open('.'
, :keep_state => true)
0
$stdout.sync = true # so that Net::SSH prompts show up
0
@@ -28,30 +28,189 @@ module TicGit
0
+ handle_ticket_checkout
0
+ OptionParser.new do |opts|
0
+ opts.banner = "Usage: ti tag [tic_id] [options] [tag_name] "
0
+ opts.on("-d", "Remove this tag from the ticket") do |v|
0
+ tic.ticket_tag(ARGV[2].chomp, tid, options)
0
+ tic.ticket_tag(ARGV[1], nil, options)
0
+ puts 'You need to at least specify one tag to add'
0
+ def parse_ticket_comment
0
+ OptionParser.new do |opts|
0
+ opts.banner = "Usage: ti comment [tic_id] [options]"
0
+ opts.on("-m MESSAGE", "--message MESSAGE", "Message you would like to add as a comment") do |v|
0
+ @options[:message] = v
0
+ def handle_ticket_comment
0
+ tid = ARGV[1].chomp if ARGV[1]
0
+ if(m = options[:message])
0
+ tic.ticket_comment(m, tid)
0
+ if message = get_editor_message
0
+ tic.ticket_comment(message.join(''), tid)
0
+ def handle_ticket_checkout
0
+ tic.ticket_checkout(tid)
0
+ def handle_ticket_state
0
+ new_state = ARGV[2].chomp
0
+ if valid_state(new_state)
0
+ tic.ticket_change(new_state, tid)
0
+ puts 'Invalid State - please choose from : ' + tic.tic_states.join(", ")
0
+ new_state = ARGV[1].chomp
0
+ if valid_state(new_state)
0
+ tic.ticket_change(new_state)
0
+ puts 'Invalid State - please choose from : ' + tic.tic_states.join(", ")
0
+ puts 'You need to at least specify a new state for the current ticket'
0
+ def valid_state(state)
0
+ tic.tic_states.include?(state)
0
- @tic.ticket_list.each do |t|
0
+ puts [' ', just('#', 4, 'r'),
0
+ just('Tags', 20) ].join(" ")
0
+ tic.ticket_list.each do |t|
0
- puts [counter, t.ticket_id[0,6], "\t", t.ticket_name].join(" ")
0
+ tic.current_ticket == t.ticket_name ? add = '*' : add = ' '
0
+ puts [add, just(counter, 4, 'r'),
0
+ t.opened.strftime("%m/%d"),
0
+ just(t.assigned_name, 8),
0
+ just(t.tags.join(','), 20) ].join(" ")
0
+ def handle_ticket_show
0
+ if t = @tic.ticket_show(ARGV[1])
0
+ days_ago = ((Time.now - t.opened) / (60 * 60 * 24)).round.to_s
0
+ puts just('Title', 10) + ': ' + t.title
0
+ puts just('TicId', 10) + ': ' + t.ticket_id
0
+ puts just('Assigned', 10) + ': ' + t.assigned.to_s
0
+ puts just('Opened', 10) + ': ' + t.opened.to_s + ' (' + days_ago + ' days)'
0
+ puts just('State', 10) + ': ' + t.state.upcase
0
+ puts just('Tags', 10) + ': ' + t.tags.join(', ')
0
+ puts 'Comments (' + t.comments.size.to_s + '):'
0
+ t.comments.reverse.each do |c|
0
+ puts ' * Added ' + c.added.strftime("%m/%d %H:%M") + ' by ' + c.user
0
+ wrapped = c.comment.split("\n").collect do |line|
0
+ line.length > 80 ? line.gsub(/(.{1,80})(\s+|$)/, "\\1\n").strip : line
0
+ wrapped = wrapped.split("\n").map { |line| "\t" + line }
0
+ puts wrapped[0, 6].join("\n")
0
+ puts "\t** more... **"
0
+ puts wrapped.join("\n")
0
OptionParser.new do |opts|
0
opts.banner = "Usage: ti new [options]"
0
opts.on("-t TITLE", "--title TITLE", "Title to use for the name of the new ticket") do |v|
0
@@ -61,18 +220,74 @@ module TicGit
0
if(t = options[:title])
0
- puts @tic.ticket_new(t, options)
0
+ ticket_show(@tic.ticket_new(t, options))
0
+ message_file = Tempfile.new('ticgit_message').path
0
+ File.open(message_file, 'w') do |f|
0
+ f.puts "# first line will be the title of the tic, the rest will be the first comment"
0
+ f.puts "# if you would like to add initial tags, put them on the 'tags:' line, comma delim"
0
+ if message = get_editor_message(message_file)
0
+ if title && title.chomp.length > 0
0
+ if message.last[0, 5] == 'tags:'
0
+ tags = tags.gsub('tags:', '')
0
+ tags = tags.split(',').map { |t| t.strip }
0
+ comment = message.join("\n")
0
+ ticket_show(@tic.ticket_new(title, :comment => comment, :tags => tags))
0
+ puts "You need to at least enter a title"
0
+ puts "It seems you wrote nothing"
0
+ def get_editor_message(message_file = nil)
0
+ message_file = Tempfile.new('ticgit_message').path if !message_file
0
+ editor = ENV["EDITOR"] || 'vim'
0
+ system("#{editor} #{message_file}");
0
+ message = File.readlines(message_file)
0
+ message = message.select { |line| line[0, 1] != '#' } # removing comments
0
def parse_options! #:nodoc:
0
warn "Please specify at least one action to execute."
0
+ puts " list state show new checkout comment tag "
0
+ def just(value, size, side = 'l')
0
+ value = value[0, size]
0
+ return value.rjust(size)
0
+ return value.ljust(size)
0
\ No newline at end of file
Comments
No one has commented yet.