Class: Cargo::Commands::Hack

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

Instance Attribute Summary collapse

Attributes inherited from Base

#current_project

Instance Method Summary collapse

Methods inherited from Base

#check_git_ver, #checkout_branch, #cmd, #compare_git_ver, #current_branch, #get_config, #grab_project_id_from_user, #initialize, #merge_with_master, #refresh_master, #setup

Constructor Details

This class inherits a constructor from Cargo::Commands::Base

Instance Attribute Details

#storyObject

Returns the value of attribute story.



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

def story
  @story
end

Instance Method Details

#escape(name) ⇒ Object



38
39
40
41
42
43
# File 'lib/cargo/commands/hack.rb', line 38

def escape(name)
  name.gsub!(/\W+/, ' ') # all non-word chars to spaces
  name.strip!            # ohh la la
  name.downcase!         #
  name.gsub!(/\ +/, '_')
end

#fetch_storiesObject



28
29
30
31
32
33
34
35
36
# File 'lib/cargo/commands/hack.rb', line 28

def fetch_stories
  puts "Fetching tracker stories"
  stories = current_project.stories('state:unstarted')
  puts "Choose a story"
  stories.each_with_index do |story, i|
    puts "#{i+1}) #{story.name}"
  end
  stories
end

#get_story(story_id) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/cargo/commands/hack.rb', line 15

def get_story(story_id)
  if story_id.nil?
    stories = fetch_stories
    choice = Readline.readline "Enter story number: "
    if !choice.empty? && choice.to_i.to_s == choice
      story_id = stories[choice.to_i - 1].id
    end
  end  
  
  raise 'Invalid story' if story_id.blank?
  self.story = Pickler::Tracker::Story.new(@current_project,@current_project.tracker.get_xml("/projects/#{@current_project.id}/stories/#{story_id}")["story"])      
end

#run(args) ⇒ Object



8
9
10
11
12
13
# File 'lib/cargo/commands/hack.rb', line 8

def run(args)
  refresh_master
  get_story(args[0])
  cmd "git checkout -b #{escape(self.story.name)}-#{self.story.id}"
  self.story.transition!('started')
end