Class: Toolshed::Commands::CreateTicketComment

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

Instance Method Summary collapse

Methods inherited from Base

#read_user_input, #read_user_input_body, #read_user_input_title, #use_project_id, #use_ticket_tracker_by_type, #use_ticket_tracker_project_id, #use_ticket_tracker_project_name

Constructor Details

#initialize(options = {}) ⇒ CreateTicketComment

Returns a new instance of CreateTicketComment.



7
8
9
# File 'lib/toolshed/commands/create_ticket_comment.rb', line 7

def initialize(options={})
  super(options)
end

Instance Method Details

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



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/create_ticket_comment.rb', line 11

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

  options = use_ticket_tracker_project_id(options)
  options = use_ticket_tracker_project_name(options)

  default_ticket_id = Toolshed::TicketTracking::story_id_from_branch_name(Toolshed::Git::Base.branch_name)
  ticket_id = read_user_input("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)

  puts "Using Project: #{ticket_tracker_project_id}" if use_project_id
  puts "Using Ticket: #{ticket_id}"

  puts "Note? "
  note_text = $stdin.gets.chomp.strip

  begin
    result = ticket_tracker.add_note(note_text)
    if (result)
      puts "Comment has been added to ticket"
    else
      puts "Unable to add comment #{result.inspect}"
    end
  rescue => e
    puts e.message
    exit
  end
end