class Jira::Command::Delete

Attributes

force[RW]
ticket[RW]

Public Class Methods

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

Public Instance Methods

run() click to toggle source
# File lib/jira/commands/delete.rb, line 22
def run
  return if ticket.empty?
  return if metadata.empty?
  return if metadata['fields'].nil?
  return if subtasks_failure?

  api.delete "issue/#{ticket}?deleteSubtasks=#{force}",
    success: on_success,
    failure: on_failure
end

Private Instance Methods

branches() click to toggle source
# File lib/jira/commands/delete.rb, line 46
def branches
  branches = `git branch --list 2> /dev/null`.split(' ')
  branches.delete("*")
  branches.delete(ticket.to_s)
  branches
end
create_branch?() click to toggle source
# File lib/jira/commands/delete.rb, line 53
def create_branch?
  response = io.yes?("Create branch?")

  if branches.count == 1 or response
    io.say("Creating a new branch.")
    new_branch = io.ask("Branch?").strip
    new_branch.delete!(" ")
    on_failure and return false if new_branch.empty?
    `git branch #{new_branch} 2> /dev/null`
  end
  true
end
delete_branch?() click to toggle source
# File lib/jira/commands/delete.rb, line 66
def delete_branch?
  response = self.io.select("Select a branch:", branches)
  `git checkout #{response} 2> /dev/null`
  `git branch -D #{ticket} 2> /dev/null`
  true
end
metadata() click to toggle source
# File lib/jira/commands/delete.rb, line 86
def metadata
  @metadata ||= api.get("issue/#{ticket}")
end
on_failure() click to toggle source
# File lib/jira/commands/delete.rb, line 42
def on_failure
  -> { puts "No change made to ticket #{ticket}." }
end
on_success() click to toggle source
# File lib/jira/commands/delete.rb, line 35
def on_success
  -> do
    on_failure and return unless create_branch?
    on_failure and return unless delete_branch?
  end
end
subtask?() click to toggle source
# File lib/jira/commands/delete.rb, line 82
def subtask?
  metadata['fields']['issuetype']['subtask']
end
subtasks_failure?() click to toggle source
# File lib/jira/commands/delete.rb, line 73
def subtasks_failure?
  return false unless subtask?
  if !metadata['fields']['subtasks'].empty? && !force
    self.force = io.yes?("Delete all sub-tasks for ticket #{ticket}?")
    return true unless force
  end
  false
end