Class: GitPivotalTracker::Story

Inherits:
Base
  • Object
show all
Defined in:
lib/git_pivotal_tracker/story.rb

Direct Known Subclasses

Bug, Chore, Feature

Constant Summary

Constants inherited from Base

Base::GIT_DIR

Instance Attribute Summary

Attributes inherited from Base

#options, #repository

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from GitPivotalTracker::Base

Instance Method Details

#run!Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/git_pivotal_tracker/story.rb', line 4

def run!
  return 1 if super

  puts "Retrieving latest #{type} from Pivotal Tracker"
  story = nil
  if options[:interactive]
    stories = fetch_stories(10)
    stories.each_with_index do |s, i|
      puts "#{i}) #{s.story_type} #{s.id} #{s.name}"
    end
    print "Pick a story: "
    story = stories[STDIN.gets.chomp.to_i]
  else
    story = fetch_stories.first
  end

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

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

  print "Enter branch name [#{branch_suffix story}]: "
  suffix = STDIN.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

#typeObject



49
50
51
# File 'lib/git_pivotal_tracker/story.rb', line 49

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