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