class Jira::Command::Comment::Delete
Attributes
ticket[RW]
Public Class Methods
new(ticket)
click to toggle source
# File lib/jira/commands/comment/delete.rb, line 17 def initialize(ticket) self.ticket = ticket end
Public Instance Methods
run()
click to toggle source
# File lib/jira/commands/comment/delete.rb, line 21 def run return unless comments? api.delete endpoint, success: on_success, failure: on_failure end
Private Instance Methods
comments()
click to toggle source
# File lib/jira/commands/comment/delete.rb, line 56 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/delete.rb, line 30 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/delete.rb, line 66 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/delete.rb, line 38 def endpoint "issue/#{ticket}/comment/#{to_delete['id']}" end
json()
click to toggle source
# File lib/jira/commands/comment/delete.rb, line 73 def json @json ||= api.get("issue/#{ticket}/comment")['comments'] || {} end
on_failure()
click to toggle source
# File lib/jira/commands/comment/delete.rb, line 46 def on_failure ->{ puts "No comment deleted." } end
on_success()
click to toggle source
# File lib/jira/commands/comment/delete.rb, line 42 def on_success ->{ puts "Successfully deleted comment from #{to_delete['updateAuthor']['displayName']}" } end
to_delete()
click to toggle source
# File lib/jira/commands/comment/delete.rb, line 50 def to_delete @to_delete ||= comments[ io.select("Select a comment to delete:", comments.keys) ] end