Class: Fresnel
- Inherits:
-
Object
- Object
- Fresnel
- Defined in:
- lib/fresnel.rb
Instance Attribute Summary collapse
-
#app_description ⇒ Object
readonly
Returns the value of attribute app_description.
-
#bin ⇒ Object
Returns the value of attribute bin.
-
#cache ⇒ Object
Returns the value of attribute cache.
-
#cache_timeout ⇒ Object
Returns the value of attribute cache_timeout.
-
#current_project_id ⇒ Object
Returns the value of attribute current_project_id.
-
#current_user_id ⇒ Object
Returns the value of attribute current_user_id.
-
#global_config_file ⇒ Object
readonly
Returns the value of attribute global_config_file.
-
#lighthouse ⇒ Object
Returns the value of attribute lighthouse.
-
#project_config_file ⇒ Object
readonly
Returns the value of attribute project_config_file.
Instance Method Summary collapse
- #account ⇒ Object
- #assign(options) ⇒ Object
- #change_state(options) ⇒ Object
- #claim(options) ⇒ Object
- #comment(number, state = nil) ⇒ Object
- #create ⇒ Object
- #create_extra_account ⇒ Object
- #create_project ⇒ Object
- #errors(number) ⇒ Object
- #get_bins(project_id = self.current_project_id) ⇒ Object
- #get_project(project_id = self.current_project_id) ⇒ Object
- #get_project_members(project_id = self.current_project_id) ⇒ Object
- #get_ticket(number) ⇒ Object
- #get_tickets_in_bin(bin) ⇒ Object
-
#initialize(options = Hash.new) ⇒ Fresnel
constructor
A new instance of Fresnel.
- #initialize_lighthouse ⇒ Object
- #links(number) ⇒ Object
- #load_global_config ⇒ Object
- #load_project_config ⇒ Object
- #open_browser_for_ticket(number) ⇒ Object
- #projects(options = Hash.new) ⇒ Object
- #show_ticket(number) ⇒ Object
- #tag(options) ⇒ Object
- #tickets(options = Hash.new) ⇒ Object
- #token ⇒ Object
Constructor Details
#initialize(options = Hash.new) ⇒ Fresnel
Returns a new instance of Fresnel.
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/fresnel.rb', line 31 def initialize(=Hash.new) @global_config_file="#{ENV['HOME']}/.fresnel" @project_config_file=File.('.fresnel') @app_description="A lighthouseapp console manager" @lighthouse=Lighthouse @cache=Cache.new Cache.clear_all load_global_config load_project_config end |
Instance Attribute Details
#app_description ⇒ Object (readonly)
Returns the value of attribute app_description.
28 29 30 |
# File 'lib/fresnel.rb', line 28 def app_description @app_description end |
#bin ⇒ Object
Returns the value of attribute bin.
29 30 31 |
# File 'lib/fresnel.rb', line 29 def bin @bin end |
#cache ⇒ Object
Returns the value of attribute cache.
29 30 31 |
# File 'lib/fresnel.rb', line 29 def cache @cache end |
#cache_timeout ⇒ Object
Returns the value of attribute cache_timeout.
29 30 31 |
# File 'lib/fresnel.rb', line 29 def cache_timeout @cache_timeout end |
#current_project_id ⇒ Object
Returns the value of attribute current_project_id.
29 30 31 |
# File 'lib/fresnel.rb', line 29 def current_project_id @current_project_id end |
#current_user_id ⇒ Object
Returns the value of attribute current_user_id.
29 30 31 |
# File 'lib/fresnel.rb', line 29 def current_user_id @current_user_id end |
#global_config_file ⇒ Object (readonly)
Returns the value of attribute global_config_file.
28 29 30 |
# File 'lib/fresnel.rb', line 28 def global_config_file @global_config_file end |
#lighthouse ⇒ Object
Returns the value of attribute lighthouse.
29 30 31 |
# File 'lib/fresnel.rb', line 29 def lighthouse @lighthouse end |
#project_config_file ⇒ Object (readonly)
Returns the value of attribute project_config_file.
28 29 30 |
# File 'lib/fresnel.rb', line 28 def project_config_file @project_config_file end |
Instance Method Details
#account ⇒ Object
105 106 107 |
# File 'lib/fresnel.rb', line 105 def account lighthouse.account end |
#assign(options) ⇒ Object
602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 |
# File 'lib/fresnel.rb', line 602 def assign() unless [:user_id] puts "should assign ticket #{[:ticket]} to someone :" members=get_project_members members_table = table do |t| t.headings = ['#', 'user_id', 'username'] members.each_with_index do |member,i| t << [i, member.user.id, member.user.name] end end puts members_table pick=InputDetector.new("Assign to user # : ",((0...members.size).to_a)).answer [:user_id]=members[pick.to_i].user.id end ticket=get_ticket([:ticket]) ticket.assigned_user_id=[:user_id] if ticket.save cache.clear(:name=>"fresnel_ticket_#{[:ticket]}") user_name = Lighthouse::User.find([:user_id]).name puts Frame.new(:header=>"Success",:body=>"Reassigned ticket ##{[:ticket]} to #{user_name} !") else puts Frame.new(:header=>"Error",:body=>"assigning failed !") end show_ticket([:ticket]) end |
#change_state(options) ⇒ Object
573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 |
# File 'lib/fresnel.rb', line 573 def change_state() puts "should change state to #{.inspect}" ticket=get_ticket([:ticket]) old_state=ticket.state [:state]="resolved" if [:state]=~/closed?/ if [:state]=~/resolved|invalid/ comment([:ticket],[:state]) else ticket.state=[:state] ticket.assigned_user_id=[:user_id] if [:user_id].present? if ticket.save cache.clear(:name=>"fresnel_ticket_#{[:ticket]}") if [:user_id].present? user_name = Lighthouse::User.find([:user_id]).name puts Frame.new(:header=>"Success",:body=>"State has changed from #{old_state} to #{[:state]} #{"and is reassigned to #{user_name}"}") end show_ticket([:ticket]) else puts Frame.new(:header=>"Error !",:body=>"Something went wrong ! #{$!}") end end end |
#claim(options) ⇒ Object
628 629 630 631 632 633 634 635 636 637 |
# File 'lib/fresnel.rb', line 628 def claim() puts "current user is : #{Lighthouse::User.find(self.current_user_id).name}" ticket=get_ticket([:ticket]) if ticket.state=="new" change_state(:ticket=>[:ticket], :state=>"open", :user_id=>self.current_user_id) #get around the cache ... else assign(:ticket=>[:ticket],:user_id=>self.current_user_id) end show_ticket([:ticket]) end |
#comment(number, state = nil) ⇒ Object
464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 |
# File 'lib/fresnel.rb', line 464 def comment(number,state=nil) puts "create comment for #{number}" ticket=get_ticket(number) File.open("/tmp/fresnel_ticket_#{number}_comment", "w") do |f| f.puts f.puts "# Please enter the comment for this ticket. Lines starting" f.puts "# with '#' will be ignored, and an empty message aborts the commit." `echo "q" | fresnel #{number}`.each{ |l| f.write "# #{l}" } end system("mate -w /tmp/fresnel_ticket_#{number}_comment") body=Array.new File.read("/tmp/fresnel_ticket_#{number}_comment").each do |l| body << l unless l=~/^#/ end body=body.to_s if body.blank? puts Frame.new(:header=>"Warning !", :body=>"Aborting comment because it was blank !") else ticket.body=body ticket.state=state unless state.nil? if ticket.save system("rm /tmp/fresnel_ticket_#{number}_comment") cache.clear(:name=>"fresnel_ticket_#{number}") show_ticket(number) else puts "something went wrong" puts $! end end end |
#create ⇒ Object
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 |
# File 'lib/fresnel.rb', line 520 def create system("mate -w /tmp/fresnel_new_ticket") if File.exists?("/tmp/fresnel_new_ticket") data=File.read("/tmp/fresnel_new_ticket") body=Array.new title="" if data.blank? puts Frame.new(:header=>"Warning !", :body=>"Aborting creation because the ticket was blank !") else data.each do |l| if title.blank? title=l next end body << l end body=body.to_s =ask("Tags #{@@tags.join(", ")} : ") =.split(" ") =[] .each do |tag| match=false if tag.length==1 @@tags.each do |predefined_tag| if predefined_tag=~/\[#{tag}\]/ match=true <<predefined_tag.gsub(/\[|\]/,"") end end end <<tag unless match end end puts "tags are #{.inspect}" puts "creating ticket..." ticket = Lighthouse::Ticket.new( :project_id=>self.current_project_id, :title=>title, :body=>body ) ticket.= if ticket.save File.delete("/tmp/fresnel_new_ticket") show_ticket(ticket.number) else puts "something went wrong !" puts $! end else puts Frame.new(:header=>"Warning !", :body=>"Aborting creation because the ticket was blank !") end end |
#create_extra_account ⇒ Object
639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 |
# File 'lib/fresnel.rb', line 639 def create_extra_account config=YAML::load_file(self.global_config_file) puts "should add an extra account !" config['account']=ask("My extra lighthouse account is : ") do |q| q.validate = /^\w+$/ q.responses[:not_valid]="\nError :\nThat seems to be incorrect, we would like to have the <account> part in\nhttp://<account>.lighthouseapp.com , please try again" q.responses[:ask_on_error]="My extra account is : " end config['accounts'][config['account']]={'account'=>config['account']} puts puts "what token would you like to use for the account : #{config['account']} ?" config['accounts'][config['account']]['token']=ask("My lighthouse token is : ") do |q| q.validate = /^[0-9a-f]{40}$/ q.responses[:not_valid]="\nError :\nThat seems to be incorrect, we would like to have your lighthouse token\n this looks something like : 1bd25cc2bab1fc4384b7edfe48433fba5f6ee43c" q.responses[:ask_on_error]="My lighthouse token is : " q.default=config['token'] if config['token'] end File.open(self.global_config_file,'w+'){ |f| f.write(YAML::dump(config)) } load_global_config end |
#create_project ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/fresnel.rb', line 113 def create_project name=ask("Name of this project : ") type=InputDetector.new("[p]rivate or [o]ss : ").answer if type=="o" row=Array.new license_table = table do |t| t.headings=['#' , 'license'] LICENSES.each_with_index do |lic,i| t<<[i, lic.last] end end puts license_table license=InputDetector.new("License # : ",(0...LICENSES.size).to_a).answer license=LICENSES[license.to_i].first end puts "collected :" puts "#{name} : #{license}" project = Lighthouse::Project.new(:name => name) if license.present? project.access = 'oss' project.license = license end puts "creating project on lighthouse..." project.save config=Hash.new config['project_id']=project.id File.open(self.project_config_file,'w+'){ |f| f.write(YAML::dump(config)) } load_project_config end |
#errors(number) ⇒ Object
440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 |
# File 'lib/fresnel.rb', line 440 def errors(number) ticket = get_ticket(number) errors = ticket.versions.map{ |version| version.body.to_s.scrape_textmate_links }.flatten if errors.size == 0 puts "No errors found" sleep 1 elsif errors.size == 1 error=errors.first error=~/(.*?):(\d+)/ `mate -l #{$2} #{File.(".")}#{$1.gsub(/^\./,"")}` else error_table=table do |t| t.headings=['#','error'] errors.each_with_index{|error,i|t << [i,error]} end puts error_table pick=InputDetector.new("open error # : ", (0...errors.size).to_a).answer error=errors[pick.to_i] error=~/(.*?):(\d+)/ `mate -l #{$2} #{File.(".")}#{$1.gsub(/^\./,"")}` end show_ticket(number) end |
#get_bins(project_id = self.current_project_id) ⇒ Object
292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 |
# File 'lib/fresnel.rb', line 292 def get_bins(project_id=self.current_project_id) system("clear") print "Fetching ticket bins..." STDOUT.flush bins=cache.load(:name=>"fresnel_project_#{project_id}_bins",:action=>"Lighthouse::Project.find(#{project_id}).bins") puts " [done] - data is #{bins.age}s old , max is #{@@cache_timeout}s" bins.reject!{|b|true unless b.user_id==self.current_user_id || b.shared} bins_table = table do |t| t.headings = ['#', 'bin', 'tickets', 'query'] bins.each_with_index do |bin,i| t << [i, bin.name,{:value=>bin.tickets_count, :alignment=>:right},bin.query] end end puts bins_table bin_id=InputDetector.new("[q]uit or Bin #: ",(0...bins.size).to_a).answer if bin_id=="q" exit(0) else puts "Fetching tickets in bin : #{bins[bin_id.to_i].name}" self.bin=bin_id.to_i data=bins[bin_id.to_i].tickets def data.age=(seconds) @age_in_seconds=seconds end def data.age @age_in_seconds end data.age=0 tickets(:tickets=>data) def tickets.age=(seconds) @age_in_seconds=seconds end def tickets.age @age_in_seconds end tickets.age=0 return tickets end end |
#get_project(project_id = self.current_project_id) ⇒ Object
355 356 357 |
# File 'lib/fresnel.rb', line 355 def get_project(project_id=self.current_project_id) cache.load(:name=>"fresnel_project_#{project_id}",:action=>"Lighthouse::Project.find(#{project_id})") end |
#get_project_members(project_id = self.current_project_id) ⇒ Object
359 360 361 |
# File 'lib/fresnel.rb', line 359 def get_project_members(project_id=self.current_project_id) cache.load(:name=>"fresnel_project_#{project_id}_members", :action=>"Lighthouse::Project.find(#{project_id}).memberships", :timeout=>1.day) end |
#get_ticket(number) ⇒ Object
351 352 353 |
# File 'lib/fresnel.rb', line 351 def get_ticket(number) cache.load(:name=>"fresnel_#{self.current_project_id}_ticket_#{number}",:action=>"Lighthouse::Ticket.find(#{number}, :params => { :project_id => #{self.current_project_id} })") end |
#get_tickets_in_bin(bin) ⇒ Object
334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 |
# File 'lib/fresnel.rb', line 334 def get_tickets_in_bin(bin) self.bin=bin.to_i bins=cache.load(:name=>"fresnel_project_#{self.current_project_id}_bins",:action=>"Lighthouse::Project.find(#{self.current_project_id}).bins") bins.reject!{|b|true unless b.user_id==self.current_user_id || b.shared} data=bins[bin.to_i].tickets def data.age=(seconds) @age_in_seconds=seconds end def data.age @age_in_seconds end data.age=0 tickets(:tickets=>data, :bin_name=>bins[bin.to_i].name) end |
#initialize_lighthouse ⇒ Object
72 73 74 75 76 |
# File 'lib/fresnel.rb', line 72 def initialize_lighthouse @lighthouse.account = @lighthouse_account @lighthouse.token = @lighthouse_token nil end |
#links(number) ⇒ Object
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 |
# File 'lib/fresnel.rb', line 416 def links(number) ticket = get_ticket(number) links = ticket.versions.map{ |version| version.body.to_s.scrape_urls }.flatten.uniq if links.size == 0 puts "No links found" sleep 1 elsif links.size == 1 url = links.first url="http://#{url}" unless url=~/^http/ `open '#{url}'` else link_table=table do |t| t.headings=['#','link'] links.each_with_index{|link,i|t << [i,link]} end puts link_table pick=InputDetector.new("open link # : ", (0...links.size).to_a).answer url=links[pick.to_i] url="http://#{url}" unless url=~/^http/ `open '#{url}'` end show_ticket(number) end |
#load_global_config ⇒ Object
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 |
# File 'lib/fresnel.rb', line 42 def load_global_config unless File.exists? self.global_config_file puts Frame.new(:header=>"Notice",:body=>"global config not found at #{self.global_config_file}, starting wizard") SetupWizard.global(self) return load_global_config end config = YAML.load_file(self.global_config_file) @@cache_timeout=config['cache_timeout'] if config.has_key?('cache_timeout') @@debug=config['debug'] if config.has_key?('debug') @@term_size=config['term_size'] if config.has_key?('term_size') @@tags=config['tags'] @@default_account=config['default_account'] @@accounts=config['accounts'] unless config && config.class==Hash && config.has_key?('default_account') && config.has_key?('user_id') && config.has_key?('tags') puts Frame.new(:header=>"Warning !",:body=>"global config did not validate , recreating") SetupWizard.global(self) return load_global_config end @lighthouse_account = config['accounts'][@@default_account]['account'] @lighthouse_token = config['accounts'][@@default_account]['token'] @current_user_id = config['user_id'] initialize_lighthouse nil end |
#load_project_config ⇒ Object
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 |
# File 'lib/fresnel.rb', line 78 def load_project_config unless File.exists? self.project_config_file puts Frame.new(:header=>"Notice",:body=>"project config not found at #{self.project_config_file}, starting wizard") SetupWizard.project(self) return load_project_config end config = YAML.load_file(self.project_config_file) || Hash.new unless config.has_key?('project_id') && config.has_key?('account_name') puts Frame.new(:header=>"Warning !",:body=>"project config found but did not validate, recreating ") SetupWizard.project(self) return load_project_config end if config.has_key?('account_name') @lighthouse_account = @@accounts[config['account_name']]['account'] @lighthouse_token = @@accounts[config['account_name']]['token'] end @current_project_id = config['project_id'] @@tags+=config['tags'] if config.has_key?('tags') @@tags.uniq! @@cache_timeout=config['cache_timeout'] if config.has_key?('cache_timeout') @@debug=config['debug'] if config.has_key?('debug') @@term_size=config['term_size'] if config.has_key?('term_size') initialize_lighthouse nil end |
#open_browser_for_ticket(number) ⇒ Object
596 597 598 599 600 |
# File 'lib/fresnel.rb', line 596 def open_browser_for_ticket(number) puts "opening ticket #{number}in browser" `open "#{get_ticket(number).url}"` show_ticket(number) end |
#projects(options = Hash.new) ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 |
# File 'lib/fresnel.rb', line 144 def projects(=Hash.new) system("clear") [:object]||=false system("clear") unless [:clear]==false || [:object] [:selectable]||false projects_data=Hash.new project_ids=Array.new print "Fetching projects from multiple accounts : " unless [:object] warnings = [] @@accounts.each do |key,value| print "#{key} " STDOUT.flush Lighthouse.account=value['account'] Lighthouse.token=value['token'] projects=Lighthouse::Project.find(:all).map {| project| begin project.nr_of_open_tickets_assigned_to_me = Lighthouse::Ticket.find(:all, :params=>{:project_id=>project.id, :q=>'responsible:me state:open'}).size rescue ActiveResource::UnauthorizedAccess => e warnings << [project.name, key] next nil end project }.compact projects_data[Lighthouse.account]=projects end puts " [done]" warnings.each do |project_name, account_name| puts "Warning:: Token does not give access to project #{project_name} on account #{account_name}." end #puts " [done] - data is #{projects_data.age}s old , max is #{@@cache_timeout}s" #no cache for now project_table = table do |t| t.headings=[] t.headings << '#' if [:selectable] t.headings += ["account"] if @@accounts.size>1 t.headings += [ 'project name', 'public', 'open tickets', 'assigned to you'] i=0 projects_data.each do |key,value| value.each do |project| row=Array.new row << i if [:selectable] project_ids<<"#{project.id};#{key}" row+=[key] if @@accounts.size>1 row+=[project.name, project.public, {:value=>project.open_tickets_count, :alignment=>:right}, {:value=>project.nr_of_open_tickets_assigned_to_me, :alignment=>:right}] t << row i+=1 end end end if [:object] projects_data[:project_ids]=project_ids return projects_data else puts(project_table) unless [:setup] action=InputDetector.new("[q]uit, [c]reate or project #",(0..project_ids.size).to_a).answer puts "action is #{action.inspect}" case action when "c" then create_project when /\d+/ then project_ids[action.to_i]=~/(\d+);(\w+)/ project_id=$1 account=$2 Lighthouse.account=@@accounts[account]["account"] Lighthouse.token=@@accounts[account]["token"] tickets(:project_id=>project_id) else exit(0) end end end end |
#show_ticket(number) ⇒ Object
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 |
# File 'lib/fresnel.rb', line 363 def show_ticket(number) system("clear") ticket = get_ticket(number) puts Frame.new( :header=>[ "Ticket ##{number} : #{ticket.title.chomp.truncate(@@term_size-5)}", "Date : #{DateParser.string(ticket.created_at.to_s)} by #{ticket.creator_name}", "Tags : #{ticket.tag}" ], :body=>ticket.versions.first.body ) ticket.versions.each_with_index do |v,i| next if i==0 if v.respond_to?(:diffable_attributes) && v.body.nil? puts "\nState changed #{DateParser.string(v.created_at.to_s)} from #{v.diffable_attributes.state} => #{v.state} by #{v.user_name}\n\n" if v.diffable_attributes.respond_to?(:state) puts "\nAssignment changed #{DateParser.string(v.created_at.to_s)} => #{v.assigned_user_name rescue "Nobody"} by #{v.user_name}\n\n" if v.diffable_attributes.respond_to?(:assigned_user) else user_date=v.user_name.capitalize date=DateParser.string(v.created_at.to_s) user_date=user_date.ljust((@@term_size-5)-date.size) user_date+=date =Array.new <<"State changed from #{v.diffable_attributes.state} => #{v.state}" if v.diffable_attributes.respond_to?(:state) <<"Assignment changed => #{v.assigned_user_name}" if v.diffable_attributes.respond_to?(:assigned_user) puts Frame.new(:header=>user_date,:body=>v.body,:footer=>) end end puts "Current state : #{ticket.versions.last.state}" choices = { :states => %w[open resolved invalid hold new], :actions => %w[quit tickets bins comments assign self web links errors Tag] } states = choices[:states] action=InputDetector.pretty_prompt(choices).answer case action when "T" then tag(:ticket=>number) when "t" then tickets when "b" then get_bins when "c" then comment(number) when "a" then assign(:ticket=>number) when "s" then claim(:ticket=>number) when "w" then open_browser_for_ticket(number) when "l" then links(number) when "e" then errors(number) when *(states.map{|state| state[0,1]}) change_state(:ticket=>number,:state=>states.find{|state| state[0,1] == action}) else exit(0) end end |
#tag(options) ⇒ Object
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 |
# File 'lib/fresnel.rb', line 496 def tag() ticket=get_ticket([:ticket]) =ask("Tags #{@@tags.join(", ")} : ") =.split(" ") =[] .each do |tag| match=false if tag.length==1 @@tags.each do |predefined_tag| if predefined_tag=~/\[#{tag}\]/ match=true <<predefined_tag.gsub(/\[|\]/,"") end end end <<tag unless match end puts "tags are #{.inspect}" ticket.= ticket.save tickets end |
#tickets(options = Hash.new) ⇒ Object
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
# File 'lib/fresnel.rb', line 220 def tickets(=Hash.new) system("clear") get_tickets_in_bin(self.bin) unless self.bin.blank? || [:tickets].present? [:all] ? print("Fetching all tickets#{" in bin #{[:bin_name]}" if [:bin_name].present?}...") : print("Fetching unresolved tickets#{" in bin #{[:bin_name]}" if [:bin_name].present?}...") STDOUT.flush @current_project_id=[:project_id]||self.current_project_id project_id=[:project_id]||self.current_project_id tickets=[:tickets]||cache.load(:name=>"fresnel_project_#{project_id}_tickets#{"_all" if [:all]}", :action=>"Lighthouse::Ticket.find(:all, :params=>{:project_id=>#{project_id} #{",:q=>'not-state:closed'" unless [:all]}})") puts " [done] - data is #{tickets.age}s old , max is #{@@cache_timeout}s" if tickets.any? tickets_table = table do |t| prepped_headings=[ {:value=>'#',:alignment=>:center}, {:value=>'state',:alignment=>:center}, {:value=>'title',:alignment=>:center}, ] prepped_headings << {:value=>'assigned to',:alignment=>:center} if @@term_size>=90 prepped_headings << {:value=>'by',:alignment=>:center} if @@term_size>=105 prepped_headings << {:value=>'tags',:alignment=>:center} if @@term_size>=120 prepped_headings << 'created at' if @@term_size>=140 prepped_headings << 'updated at' if @@term_size>=160 t.headings = prepped_headings #must assign the heading at once, else it will b0rk the output tickets.sort_by(&:number).reverse.each do |ticket| cols=[ {:value=>ticket.number, :alignment=>:right}, {:value=>ticket.state,:alignment=>:center}, "#{ticket.title.truncate(50)}" ] cols << (ticket.assigned_user_name.split(" ").first.truncate(10) rescue "nobody") if @@term_size>=90 cols << ticket.creator_name.split(" ").first.truncate(10) if @@term_size>=105 cols << (ticket.tag.truncate(9) rescue "") if @@term_size>=120 cols << {:value=>DateParser.string(ticket.created_at.to_s), :alignment=>:right} if @@term_size>=140 cols << {:value=>DateParser.string(ticket.updated_at.to_s), :alignment=>:right} if @@term_size>=160 t << cols #must assign the cols at once, else it will b0rk the output end end puts tickets_table action=InputDetector.new("[q]uit, [b]ins, [p]rojects, #{[:all] ? "[u]nresolved" : "[a]ll"}, [c]reate , [r]efresh/[t]ickets or ticket # : ",tickets.map(&:number)).answer case action when /t|r/ then cache.clear(:name=>"fresnel_project_#{project_id}_tickets") self.tickets when "b" then get_bins when "c" then create when "p" then projects(:selectable=>true) when "a" then tickets(:all=>true) when "u" then self.tickets when /\d+/ then show_ticket(action) else exit(0) end else puts Frame.new(:header=>"Notice",:body=>"no #{"unresolved " unless [:all]}tickets #{"in bin #{[:bin_name]}"}...") action=InputDetector.pretty_prompt(:actions => %w[quit bins projects unresolved all create]).answer case action when "b" then get_bins when "c" then create when "p" then projects(:selectable=>true) when "a" then tickets(:all=>true) when "u" then self.tickets else exit(0) end end end |
#token ⇒ Object
109 110 111 |
# File 'lib/fresnel.rb', line 109 def token lighthouse.token end |