-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathwatchtower.rb
executable file
·104 lines (82 loc) · 2.58 KB
/
watchtower.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/env ruby
# starts a sinatra based web server that provides an interface to
# your ticgit tickets
#
# author : K. Adam Christensen
%w(rubygems sinatra git ticgit haml gravatar set redcloth).each do |dependency|
begin
require dependency
rescue LoadError => e
puts "You need to install #{dependency} before we can proceed"
end
end
unless ARGV[0]
$stderr.puts "You must specify a path to a git repository"
Process.exit
end
$ticgit = TicGit.open(ARGV[0].chomp)
$yui_version = '2.5.1'
get('/screen.css') do
header 'Content-Type' => 'text/css; charset=utf-8'
sass :screen
end
before do
@saved = $ticgit.config['list_options'].keys rescue []
end
get('/') do
@title = "All Tickets"
@tickets = $ticgit.ticket_list(:order => 'date.desc')
haml :list
end
get('/tickets/state/:state') do
@title = "#{params[:state].capitalize} Tickets"
@tickets = $ticgit.ticket_list(:state => params[:state], :order => 'date.desc')
haml :list
end
get('/tickets/tags/:tag') do
@title = "#{params[:tag].capitalize} Tickets"
@tickets = $ticgit.ticket_list(:tag => params[:tag], :order => 'date.desc')
haml :list
end
get('/tickets/saved_views/:view') do
@tickets = $ticgit.ticket_list(:saved => params[:saved_view])
@title = "#{params[:view].capitalize} View"
haml :list
end
get('/tickets/new') do
@title = 'New Ticket'
haml :new
end
post('/tickets') do
title = params[:ticket_title].to_s.strip
if title.size > 1
tags = params[:ticket_tags].split(',').map { |t| t.strip } rescue nil
comment = params[:ticket_comment].strip rescue nil
comment = nil if comment.empty?
t = $ticgit.ticket_new(title, {:comment => comment, :tags => tags})
redirect '/tickets/' + t.ticket_id.to_s
else
redirect '/tickets/new'
end
end
get('/tickets/:id') do
@ticket = $ticgit.ticket_show(params[:id])
@title = @ticket.title
haml :show
end
put('/tickets/:id') do
@ticket = $ticgit.ticket_show(params[:id])
comment = params[:ticket_comment].strip rescue ""
unless comment.empty?
$ticgit.ticket_comment(comment, params[:id])
end
$ticgit.ticket_assign(params[:ticket_assigned], params[:id])
original_tags = @ticket.tags.to_set
updated_tags = params[:ticket_tags].split(',').map { |t| t.strip }.to_set rescue Set.new
tags_to_remove = (original_tags - updated_tags).to_a.join(',')
$ticgit.ticket_tag(tags_to_remove, params[:id], :remove => true)
tags_to_add = (updated_tags - original_tags).to_a.join(',')
$ticgit.ticket_tag(tags_to_add, params[:id])
$ticgit.ticket_change(params[:ticket_state], params[:id])
redirect "/tickets/#{@ticket.ticket_id}"
end