class GitPivotalTracker::Story

Public Instance Methods

run!() click to toggle source
Calls superclass method GitPivotalTracker::Base#run!
# File lib/git_pivotal_tracker/story.rb, line 4
def run!
  return 1 if super

  puts "Retrieving latest #{type} from Pivotal Tracker"

  unless story = fetch_story
    puts "No #{type} available!"
    return 1
  end

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

  print "Enter branch name [#{branch_suffix story}]: "
  suffix = gets.chomp
  suffix = branch_suffix(story) if suffix == ""

  branch = "#{story.story_type}-#{story.id}-#{suffix}"
  puts "Checking out a new branch '#{branch}'"
  log repository.git.checkout({:b => true, :raise => true}, branch)

  puts "Updating #{type} status in Pivotal Tracker..."
  if story.update(:owned_by => options[:full_name], :current_state => :started)
    puts "Success"
    return 0
  else
    puts "Unable to mark #{type} as started"
    return 1
  end
end
type() click to toggle source
# File lib/git_pivotal_tracker/story.rb, line 35
def type
  self.class.name.downcase.split(/::/).last
end

Private Instance Methods

branch_suffix(story) click to toggle source
# File lib/git_pivotal_tracker/story.rb, line 49
def branch_suffix(story)
  story.name.sub(/^\W+/, '').sub(/\W+$/, '').gsub(/\W+/, '_').downcase
end
fetch_story() click to toggle source
# File lib/git_pivotal_tracker/story.rb, line 41
def fetch_story
  state = options[:include_rejected] ? "unstarted,rejected" : "unstarted"
  conditions = { :current_state => state, :limit => 1 }
  conditions[:owned_by] = "\"#{options[:full_name]}\"" if options[:only_mine]
  conditions[:story_type] = type unless type == 'story'
  project.stories.all(conditions).first
end