Skip to content

Commit

Permalink
added recent command, which was way cooler and easier than I thought
Browse files Browse the repository at this point in the history
  • Loading branch information
schacon committed Mar 22, 2008
1 parent 49fadb4 commit c1c3407
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 39 deletions.
28 changes: 25 additions & 3 deletions lib/ticgit/base.rb
Expand Up @@ -76,6 +76,7 @@ def ticket_comment(comment, ticket_id = nil)
def ticket_list(options = {})
ts = []
@last_tickets = []
@config['list_options'] ||= {}

@tickets.to_a.each do |name, t|
ts << TicGit::Ticket.open(self, name, t)
Expand All @@ -85,7 +86,14 @@ def ticket_list(options = {})
if c = config['list_options'][name]
options = c.merge(options)
end
end
end

if options[:list]
config['list_options'].each do |name, opts|
puts name + "\t" + opts.inspect
end
return false
end

# SORTING
if field = options[:order]
Expand All @@ -99,6 +107,8 @@ def ticket_list(options = {})
ts = ts.sort { |a, b| a.opened <=> b.opened }
end
ts = ts.reverse if type == 'desc'
else
ts = ts.sort { |a, b| a.opened <=> b.opened }
end

# :tag, :state, :assigned
Expand All @@ -114,7 +124,6 @@ def ticket_list(options = {})

if save = options[:save]
options.delete(:save)
@config['list_options'] ||= {}
@config['list_options'][save] = options
end

Expand All @@ -133,12 +142,25 @@ def ticket_show(ticket_id = nil)
end
end

# returns single Ticket
def ticket_recent(ticket_id = nil)
if ticket_id
t = ticket_revparse(ticket_id)
return git.log.object('ticgit').path(t)
else
return git.log.object('ticgit')
end
end

def ticket_revparse(ticket_id)
if ticket_id
if t = @last_tickets[ticket_id.to_i - 1]
return t
else
# !! TODO: check for (partial) sha in @tickets
# partial or full sha
if ch = @tickets.select { |name, t| t['files'].assoc('TICKET_ID')[1] =~ /#{ticket_id}/ }
return ch.first[0]
end
end
elsif(@current_ticket)
return @current_ticket
Expand Down
59 changes: 36 additions & 23 deletions lib/ticgit/cli.rb
Expand Up @@ -40,11 +40,18 @@ def execute!
handle_ticket_comment
when 'tag'
handle_ticket_tag
when 'recent'
handle_ticket_recent
else
puts 'not a command'
end
end

def handle_ticket_recent
tic.ticket_recent(ARGV[1]).each do |commit|
puts commit.sha[0, 7] + " " + commit.date.strftime("%m/%d %H:%M") + "\t" + commit.message
end
end


def parse_ticket_tag
Expand Down Expand Up @@ -152,39 +159,45 @@ def parse_ticket_list
opts.on("-S SAVENAME", "--saveas SAVENAME", "Save this list as a saved name") do |v|
@options[:save] = v
end
opts.on("-l", "--list", "Show the saved queries") do |v|
@options[:list] = true
end
end.parse!
end

def handle_ticket_list
parse_ticket_list

counter = 0
if tickets = tic.ticket_list(options)
counter = 0

puts
puts [' ', just('#', 4, 'r'),
just('TicId', 6),
just('Title', 25),
just('State', 5),
just('Date', 5),
just('Assgn', 8),
just('Tags', 20) ].join(" ")
puts
puts [' ', just('#', 4, 'r'),
just('TicId', 6),
just('Title', 25),
just('State', 5),
just('Date', 5),
just('Assgn', 8),
just('Tags', 20) ].join(" ")

a = []
80.times { a << '-'}
puts a.join('')
a = []
80.times { a << '-'}
puts a.join('')

tic.ticket_list(options).each do |t|
counter += 1
tic.current_ticket == t.ticket_name ? add = '*' : add = ' '
puts [add, just(counter, 4, 'r'),
t.ticket_id[0,6],
just(t.title, 25),
just(t.state, 5),
t.opened.strftime("%m/%d"),
just(t.assigned_name, 8),
just(t.tags.join(','), 20) ].join(" ")
tickets.each do |t|
counter += 1
tic.current_ticket == t.ticket_name ? add = '*' : add = ' '
puts [add, just(counter, 4, 'r'),
t.ticket_id[0,6],
just(t.title, 25),
just(t.state, 5),
t.opened.strftime("%m/%d"),
just(t.assigned_name, 8),
just(t.tags.join(','), 20) ].join(" ")
end
puts
end
puts

end

## SHOW TICKETS ##
Expand Down
2 changes: 1 addition & 1 deletion lib/ticgit/ticket.rb
Expand Up @@ -106,7 +106,7 @@ def save_new
end

def self.clean_string(string)
string.downcase.gsub(/[^a-z0-9]+/i, '_')
string.downcase.gsub(/[^a-z0-9]+/i, '-')
end

def add_comment(comment)
Expand Down
20 changes: 8 additions & 12 deletions note/TODO
@@ -1,15 +1,3 @@
Find
* sort by assigned, state
* filter by tag, date, state
* save named searches

rev-parse partial ticket id

Tags
* show all tags
* rename tag
* delete tag
* tag multiple tics

Recent (use git-log)

Expand All @@ -21,9 +9,17 @@ Milestones

Merge

Tags
* show all tags
* rename tag
* delete tag
* tag multiple tics

Ticket
- remove ticket ( git.remove(ticket_dir, :recursive => true) )

Color Output + Paging long results

TicGit goes up directories until it finds .git dir

Web UI

0 comments on commit c1c3407

Please sign in to comment.