Sha256: 6e7b21af271c269b702c8e64fb08e039b388a9abc9053ffe5170eabb9be1b33a

Contents?: true

Size: 1.62 KB

Versions: 1

Compression:

Stored size: 1.62 KB

Contents

module GitPivotalTracker
  class Story < Base

    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
    rescue Grit::Git::CommandFailed => e
      puts "git error: #{e.err}"
      return 1
    end

    def type
      self.class.name.downcase.split(/::/).last
    end

    private

    def fetch_story
      state = options[:include_rejected] ? "unstarted,rejected" : "unstarted"
      conditions = { :current_state => state, :limit => 1 }
      conditions[:story_type] = type == 'story' ? 'bug,chore,feature' : type
      conditions[:owned_by] = "\"#{options[:full_name]}\"" if options[:only_mine]
      project.stories.all(conditions).first
    end

    def branch_suffix(story)
      story.name.sub(/^\W+/, '').sub(/\W+$/, '').gsub(/\W+/, '_').downcase
    end
  end

  class Bug < Story; end

  class Feature < Story; end

  class Chore < Story; end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
git_pivotal_tracker-0.0.9 lib/git_pivotal_tracker/story.rb