class Jira::Command::Log::Update

Attributes

ticket[RW]

Public Class Methods

new(ticket=Jira::Core.ticket) click to toggle source
# File lib/jira/commands/log/update.rb, line 17
def initialize(ticket=Jira::Core.ticket)
  self.ticket = ticket
end

Public Instance Methods

run() click to toggle source
# File lib/jira/commands/log/update.rb, line 21
def run
  return unless logs?
  api.patch endpoint,
    params:  params,
    success: on_success,
    failure: on_failure
end

Private Instance Methods

description_for(log) click to toggle source
# File lib/jira/commands/log/update.rb, line 75
def description_for(log)
  author = log['updateAuthor']['displayName']
  updated_at = Jira::Format.time(Time.parse(log['updated']))
  time_spent = log['timeSpent']
  "#{author} @ #{updated_at}: #{time_spent}"
end
endpoint() click to toggle source
# File lib/jira/commands/log/update.rb, line 47
def endpoint
  "issue/#{ticket}/worklog/#{to_update['id']}"
end
json() click to toggle source
# File lib/jira/commands/log/update.rb, line 82
def json
  @json ||= api.get("issue/#{ticket}/worklog")['worklogs']
end
logs() click to toggle source
# File lib/jira/commands/log/update.rb, line 65
def logs
  @logs ||= (
    logs = {}
    json.each do |log|
      logs[description_for(log)] = log
    end
    logs
  )
end
logs?() click to toggle source
# File lib/jira/commands/log/update.rb, line 39
def logs?
  if json.empty?
    puts "Ticket #{ticket} has no work logged."
    return false
  end
  true
end
on_failure() click to toggle source
# File lib/jira/commands/log/update.rb, line 55
def on_failure
  ->{ puts "No logged work updated." }
end
on_success() click to toggle source
# File lib/jira/commands/log/update.rb, line 51
def on_success
  ->{ puts "Successfully updated #{to_update['timeSpent']}." }
end
params() click to toggle source
# File lib/jira/commands/log/update.rb, line 31
def params
  { timeSpent: updated_time_spent }
end
to_update() click to toggle source
# File lib/jira/commands/log/update.rb, line 59
def to_update
  @to_delete ||= logs[
    io.select("Select a worklog to update:", logs.keys)
  ]
end
updated_time_spent() click to toggle source
# File lib/jira/commands/log/update.rb, line 35
def updated_time_spent
  io.ask('Updated time spent?')
end