class Jira::Command::Comment::Update

Attributes

ticket[RW]

Public Class Methods

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

Public Instance Methods

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

Private Instance Methods

comments() click to toggle source
# File lib/jira/commands/comment/update.rb, line 64
def comments
  @comments ||= (
    comments = {}
    json.each do |comment|
      comments[description_for(comment)] = comment
    end
    comments
  )
end
comments?() click to toggle source
# File lib/jira/commands/comment/update.rb, line 35
def comments?
  if json.empty?
    puts "Ticket #{ticket} has no comments."
    return false
  end
  true
end
description_for(comment) click to toggle source
# File lib/jira/commands/comment/update.rb, line 74
def description_for(comment)
  author = comment['updateAuthor']['displayName']
  updated_at = Jira::Format.time(Time.parse(comment['updated']))
  body = comment['body'].split.join(" ")
  truncate("#{author} @ #{updated_at}: #{body}", 160)
end
endpoint() click to toggle source
# File lib/jira/commands/comment/update.rb, line 43
def endpoint
  "issue/#{ticket}/comment/#{to_update['id']}"
end
json() click to toggle source
# File lib/jira/commands/comment/update.rb, line 81
def json
  @json ||= api.get("issue/#{ticket}/comment")['comments']
end
on_failure() click to toggle source
# File lib/jira/commands/comment/update.rb, line 54
def on_failure
  ->{ puts "No comment updated." }
end
on_success() click to toggle source
# File lib/jira/commands/comment/update.rb, line 47
def on_success
  ->{
    puts "Successfully updated comment originally from"\
    " #{to_update['updateAuthor']['displayName']}."
  }
end
params() click to toggle source
# File lib/jira/commands/comment/update.rb, line 31
def params
  { body: body }
end
to_update() click to toggle source
# File lib/jira/commands/comment/update.rb, line 58
def to_update
  @to_update ||= comments[
    io.select("Select a comment to update:", comments.keys)
  ]
end