Class: Jira::Command::Rename

Inherits:
Base
  • Object
show all
Defined in:
lib/jira/commands/rename.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ticket, options) ⇒ Rename

Returns a new instance of Rename.



17
18
19
20
# File 'lib/jira/commands/rename.rb', line 17

def initialize(ticket, options)
  self.ticket = ticket
  self.options = options
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



15
16
17
# File 'lib/jira/commands/rename.rb', line 15

def options
  @options
end

#ticketObject

Returns the value of attribute ticket.



15
16
17
# File 'lib/jira/commands/rename.rb', line 15

def ticket
  @ticket
end

Instance Method Details

#on_failureObject



43
44
45
# File 'lib/jira/commands/rename.rb', line 43

def on_failure
  ->{ puts "No change made to ticket #{ticket}." }
end

#on_successObject



39
40
41
# File 'lib/jira/commands/rename.rb', line 39

def on_success
  ->{ puts "Successfully updated ticket #{ticket}'s summary." }
end

#paramsObject



31
32
33
34
35
36
37
# File 'lib/jira/commands/rename.rb', line 31

def params
  {
    fields: {
      summary: summary
    }
  }
end

#runObject



22
23
24
25
26
27
28
29
# File 'lib/jira/commands/rename.rb', line 22

def run
  return if ticket.empty?
  return if summary.empty?
  api.patch "issue/#{ticket}",
    params:  params,
    success: on_success,
    failure: on_failure
end

#summaryObject



47
48
49
# File 'lib/jira/commands/rename.rb', line 47

def summary
  @summary ||= options['summary'] || io.ask("New summary for ticket #{ticket}:", default: '')
end