class Agile::Tickets
Public Instance Methods
archive()
click to toggle source
# File lib/agile/commands/tickets.rb, line 73 def archive error_checking_tickets response = RestClient.get "#{CONFIG['current_remote']}/api/v1/tickets/" info = JSON.parse(response) info.each do |ticket| archive_ticket(ticket) if ticket["project_id"] == CONFIG["current_project_id"] && ticket["status"] == "archived" end end
create(ticket)
click to toggle source
# File lib/agile/commands/tickets.rb, line 6 def create(ticket) error_checking_tickets ticket_name = ticket cli = HighLine.new ticket_description = cli.ask("description for ticket: ", String) RestClient.post"#{CONFIG['current_remote']}/api/v1/tickets/", project_id: CONFIG["current_project_id"], name: ticket_name, user: CONFIG["current_user"], desc: ticket_description, status: ticket_status say "Successfully added new ticket!" end
list()
click to toggle source
# File lib/agile/commands/tickets.rb, line 18 def list error_checking_tickets response = RestClient.get "#{CONFIG['current_remote']}/api/v1/tickets/" info = JSON.parse(response) print_tickets_list(info) end
my_list()
click to toggle source
# File lib/agile/commands/tickets.rb, line 26 def my_list error_checking_tickets response = RestClient.get "#{CONFIG['current_remote']}/api/v1/tickets/" owner = [] JSON.parse(response).each { |ticket| owner << ticket if ticket["owner"] == CONFIG["current_user"] } print_tickets_list(owner) end
show(ticket)
click to toggle source
# File lib/agile/commands/tickets.rb, line 35 def show(ticket) error_checking_tickets response = RestClient.get "#{CONFIG['current_remote']}/api/v1/tickets/#{ticket}" row = JSON.parse(response) output_ticket(row["data"]["attributes"]) end
status(ticket)
click to toggle source
# File lib/agile/commands/tickets.rb, line 65 def status(ticket) error_checking_tickets RestClient.put "#{CONFIG['current_remote']}/api/v1/tickets/#{ticket}", name: ticket, status: ticket_status, type: 3, project_id: CONFIG["current_project_id"] say "You take ticket #{ticket}" end
take(ticket)
click to toggle source
# File lib/agile/commands/tickets.rb, line 57 def take(ticket) error_checking_tickets RestClient.put "#{CONFIG['current_remote']}/api/v1/tickets/#{ticket}", name: ticket, user: CONFIG["current_user"], type: 2 say "You take ticket #{ticket}" end
update(ticket)
click to toggle source
# File lib/agile/commands/tickets.rb, line 43 def update(ticket) error_checking_tickets choice = HighLine.new answer = choice.ask("Choose what you need to edit : name or description (N or D): ", String) if answer == "N" update_name(ticket) elsif answer == "D" update_description(ticket) else say "Try again" end end
Private Instance Methods
archive_ticket(ticket)
click to toggle source
# File lib/agile/commands/tickets.rb, line 97 def archive_ticket(ticket) say ticket["name"] end
error_checking_tickets()
click to toggle source
# File lib/agile/commands/tickets.rb, line 84 def error_checking_tickets abort "You haven't done init yet!" unless CONFIG["current_remote"] abort "Please, log in!" unless CONFIG["current_user"] abort "Please, choose a project to work with!" unless CONFIG["current_project"] end
output_ticket(row)
click to toggle source
# File lib/agile/commands/tickets.rb, line 90 def output_ticket(row) say "Ticket: #{row['name']}" say "Description: #{row['description']}" say "Status: #{row['status']}" say "Owner: #{row['owner']}" end
parse_tickets(all_tickets)
click to toggle source
rubocop:enable Metrics/MethodLength
# File lib/agile/commands/tickets.rb, line 185 def parse_tickets(all_tickets) my_tickets = [] all_tickets.each { |ticket| my_tickets << ticket if ticket["project_id"] == CONFIG["current_project_id"] } tickets_to_arrays(my_tickets) end
print_all_arrays()
click to toggle source
# File lib/agile/commands/tickets.rb, line 191 def print_all_arrays print_arr_to_do(@to_do) print_arr_review(@review) print_arr_merged(@merged) print_arr_in_progress(@in_progress) print_arr_done(@done) end
print_arr_done(arr)
click to toggle source
# File lib/agile/commands/tickets.rb, line 153 def print_arr_done(arr) @s_done = "" arr.each do |element| @s_done += element.to_s + "\n" end end
print_arr_in_progress(arr)
click to toggle source
# File lib/agile/commands/tickets.rb, line 146 def print_arr_in_progress(arr) @s_in_progress = "" arr.each do |element| @s_in_progress += element.to_s + "\n" end end
print_arr_merged(arr)
click to toggle source
# File lib/agile/commands/tickets.rb, line 139 def print_arr_merged(arr) @s_merged = "" arr.each do |element| @s_merged += element.to_s + "\n" end end
print_arr_review(arr)
click to toggle source
# File lib/agile/commands/tickets.rb, line 132 def print_arr_review(arr) @s_review = "" arr.each do |element| @s_review += element.to_s + "\n" end end
print_arr_to_do(arr)
click to toggle source
# File lib/agile/commands/tickets.rb, line 125 def print_arr_to_do(arr) @s_to_do = "" arr.each do |element| @s_to_do += element.to_s + "\n" end end
print_tickets_list(all_tickets)
click to toggle source
# File lib/agile/commands/tickets.rb, line 199 def print_tickets_list(all_tickets) parse_tickets(all_tickets) print_all_arrays table = Terminal::Table.new do |tbl| tbl.title = CONFIG["current_project"] tbl.headings = %w[todo review merged in_progress done] tbl.rows = [[@s_to_do, @s_review, @s_merged, @s_in_progress, @s_done]] end say table end
ticket_status()
click to toggle source
# File lib/agile/commands/tickets.rb, line 101 def ticket_status cli = HighLine.new puts "0 - ToDo\n1 - Review\n2 - Merged\n3 - In progress\n4 - Done\n5 - Archived" cli.ask("Choose status of ticket (select number): ", Integer) end
tickets_to_arrays(my_tickets)
click to toggle source
rubocop:disable Metrics/MethodLength
# File lib/agile/commands/tickets.rb, line 161 def tickets_to_arrays(my_tickets) @to_do = [] @review = [] @merged = [] @in_progress = [] @done = [] my_tickets.each do |ticket| case ticket["status"] when "todo" @to_do.push(ticket["name"]) when "review" @review.push(ticket["name"]) when "merged" @merged.push(ticket["name"]) when "in_progress" @in_progress.push(ticket["name"]) when "done" @done.push(ticket["name"]) end end end
update_description(ticket)
click to toggle source
# File lib/agile/commands/tickets.rb, line 116 def update_description(ticket) choice = HighLine.new new_description = choice.ask("Enter new description of ticket: ", String) RestClient.put "#{CONFIG['current_remote']}/api/v1/tickets/#{ticket}", name: ticket, new_description: new_description, user: CONFIG["current_user"] say "Updated description to #{new_description}" end
update_name(ticket)
click to toggle source
# File lib/agile/commands/tickets.rb, line 107 def update_name(ticket) choice = HighLine.new new_ticket = choice.ask("Enter new name of ticket: ", String) RestClient.put "#{CONFIG['current_remote']}/api/v1/tickets/#{ticket}", name: ticket, new_name: new_ticket, type: 1, user: CONFIG["current_user"], project_id: CONFIG["current_project_id"] say "Updated from #{ticket} to #{new_ticket}" end