Class: Jira::Command::Assign

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(ticket) ⇒ Assign

Returns a new instance of Assign.



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

def initialize(ticket)
  self.ticket = ticket
end

Instance Attribute Details

#ticketObject

Returns the value of attribute ticket.



16
17
18
# File 'lib/jira/commands/assign.rb', line 16

def ticket
  @ticket
end

Instance Method Details

#assigneeObject



54
55
56
57
58
59
# File 'lib/jira/commands/assign.rb', line 54

def assignee
  @assignee ||= (
    assignee = io.ask('Assignee?', default: 'auto')
    assignee == 'auto' ? '-1' : assignee
  )
end

#nameObject



50
51
52
# File 'lib/jira/commands/assign.rb', line 50

def name
  assignee == '-1' ? 'default user' : "'#{assignee}'"
end

#on_failureObject



35
36
37
38
39
40
# File 'lib/jira/commands/assign.rb', line 35

def on_failure
  ->(json) do
    message = (json['errors'] || {})['assignee']
    puts message || "Ticket #{ticket} was not assigned."
  end
end

#on_successObject



29
30
31
32
33
# File 'lib/jira/commands/assign.rb', line 29

def on_success
  -> do
    puts "Ticket #{ticket} assigned to #{name}."
  end
end

#paramsObject



46
47
48
# File 'lib/jira/commands/assign.rb', line 46

def params
  { name: assignee }
end

#pathObject



42
43
44
# File 'lib/jira/commands/assign.rb', line 42

def path
  "issue/#{ticket}/assignee"
end

#runObject



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

def run
  api.patch path,
    params:  params,
    success: on_success,
    failure: on_failure
end