Class: Toolshed::Commands::UpdateTicketStatus

Inherits:
Object
  • Object
show all
Defined in:
lib/toolshed/commands/update_ticket_status.rb

Instance Method Summary collapse

Instance Method Details

#branchObject



6
7
8
# File 'lib/toolshed/commands/update_ticket_status.rb', line 6

def branch
  @branch ||= Toolshed::Git::Branch.new
end

#execute(args, options = {}) ⇒ Object



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
# File 'lib/toolshed/commands/update_ticket_status.rb', line 10

def execute(args, options = {})
  ticket_tracker_class =  Object.const_get("Toolshed::TicketTracking::#{Toolshed::Client.instance.ticket_tracking_tool.camel_case}")

  use_project_id = Object.const_get("#{ticket_tracker_class}::USE_PROJECT_ID") rescue false
  if use_project_id
    ticket_tracker_project_id = read_user_input_project("Project ID (Default: #{Toolshed::Client.instance.default_pivotal_tracker_project_id}):", options.merge!({ default: Toolshed::Client.instance.default_pivotal_tracker_project_id }))
    options.merge!({ project_id: ticket_tracker_project_id })
  end

  use_project_name = Object.const_get("#{ticket_tracker_class}::USE_PROJECT_NAME") rescue false
  if use_project_name
    ticket_tracker_project_name = read_user_input_project("Project Name (Default: #{Toolshed::Client.instance.default_ticket_tracker_project}):", options.merge!({ default: Toolshed::Client.instance.default_ticket_tracker_project }))
    options.merge!({ project: ticket_tracker_project_name })
  end

  default_ticket_id = Toolshed::TicketTracking::story_id_from_branch_name(branch.name)
  ticket_id = read_user_input_ticket_id("Ticket ID (Default: #{default_ticket_id}):", options.merge!({ default: default_ticket_id }))
  options.merge!({ ticket_id: ticket_id })

  ticket_tracker = ticket_tracker_class.create_instance(options)

  status = read_user_input_status("Status:")

  begin
    result = ticket_tracker.update_ticket_status(status)
    puts result
  rescue => e
    puts e.message
    exit
  end
end

#read_user_input_project(message, options) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/toolshed/commands/update_ticket_status.rb', line 42

def read_user_input_project(message, options)
  return options[:default] if (options.has_key?(:use_defaults))

  puts message
  value = $stdin.gets.chomp

  if (value.empty?)
    value = options[:default]
  end

  value
end

#read_user_input_status(message) ⇒ Object



68
69
70
71
72
73
74
75
76
77
# File 'lib/toolshed/commands/update_ticket_status.rb', line 68

def read_user_input_status(message)
  puts message
  value = $stdin.gets.chomp

  until !value.nil? && !value.empty?
    puts "Status must be passed in"
    puts message
    value = $stdin.gets.chomp
  end
end

#read_user_input_ticket_id(message, options) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/toolshed/commands/update_ticket_status.rb', line 55

def read_user_input_ticket_id(message, options)
  return options[:default] if (options.has_key?(:use_defaults))

  puts message
  value = $stdin.gets.chomp

  if (value.empty?)
    value = options[:default]
  end

  value
end