class PivotalIntegration::Command::Switch

The class that encapsulates assigning current Pivotal Tracker Story to a user

Public Instance Methods

run(*arguments) click to toggle source
# File lib/pivotal-integration/command/switch.rb, line 23
def run(*arguments)
  id = arguments.first

  if id == '-'
    previous_story = PivotalIntegration::Util::Git.get_config('pivotal.previous-story')
    abort "No previous story ID was set." unless previous_story.present?
    story = @configuration.project.stories.find(previous_story)
  else
    story = @configuration.project.stories.find(id)
    abort "A valid story ID must be provided." unless story
  end

  PivotalIntegration::Util::Git.set_config('pivotal.previous-story', @configuration.story.id)

  @configuration.story = story
  PivotalIntegration::Util::Story.pretty_print(story)

  # TODO: When switching stories, switch to the correct branch as well
  # TODO: Add post-checkout hook to switch to the correct story when changing branches
  # http://schacon.github.io/git/githooks.html#_post_checkout
end