Class: Commands::Pick

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

Direct Known Subclasses

Bug, Card, Chore, Feature

Instance Attribute Summary

Attributes inherited from Base

#input, #options, #output

Instance Method Summary collapse

Methods inherited from Base

#get, #initialize, #put, #sys, #with

Constructor Details

This class inherits a constructor from Commands::Base

Instance Method Details

#branch_suffixObject



14
15
16
# File 'lib/commands/pick.rb', line 14

def branch_suffix
  raise Error("must define in subclass")
end

#plural_typeObject



10
11
12
# File 'lib/commands/pick.rb', line 10

def plural_type
  raise Error("must define in subclass")
end

#run!Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/commands/pick.rb', line 18

def run!
  response = super
  return response if response > 0

  msg = "Retrieving latest #{plural_type} from Pivotal Tracker"
  if options[:only_mine]
    msg += " for #{options[:full_name]}"
  end
  put "#{msg}..."

  unless story
    put "No #{plural_type} available!"
    return 0
  end

  put "Story: #{story.name}"
  put "URL:   #{story.url}"

  put "Updating #{type} status in Pivotal Tracker..."
  story.update(:owned_by => options[:full_name], :current_state => :started)

  if story.errors.empty?
    suffix_or_prefix = ""
    unless options[:quiet] || options[:defaults]
      put "Enter branch name (will be #{options[:append_name] ? 'appended' : 'prepended'} by #{story.id}) [#{suffix_or_prefix}]: ", false
      suffix_or_prefix = input.gets.chomp
    end
    suffix_or_prefix = branch_suffix if suffix_or_prefix == ""

    if options[:append_name]
      branch = "#{suffix_or_prefix}-#{story.id}"
    else
      branch = "#{story.id}-#{suffix_or_prefix}"
    end
    if get("git branch").match(branch).nil?
      put "Switched to a new branch '#{branch}'"
      sys "git checkout -b #{branch}"
    end

    return 0
  else
    put "Unable to mark #{type} as started"
    put "\t" + story.errors.to_a.join("\n\t")

    return 1
  end
end

#typeObject



6
7
8
# File 'lib/commands/pick.rb', line 6

def type
  raise Error("must define in subclass")
end