Class: PivotalIntegration::Command::Switch

Inherits:
Base
  • Object
show all
Defined in:
lib/pivotal-integration/command/switch.rb

Overview

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

Instance Method Summary collapse

Methods inherited from Base

desc, #initialize, #story

Constructor Details

This class inherits a constructor from PivotalIntegration::Command::Base

Instance Method Details

#run(*arguments) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# 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