Class: Commands::Finish

Inherits:
Base
  • Object
show all
Defined in:
lib/commands/finish.rb

Instance Attribute Summary

Attributes inherited from Base

#input, #options, #output

Instance Method Summary collapse

Methods inherited from Base

#get, #initialize, #put, #sys

Constructor Details

This class inherits a constructor from Commands::Base

Instance Method Details

#run!Object



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
# File 'lib/commands/finish.rb', line 6

def run!
  super
  
  # clunky way to get branch name... need better method
  current_branch = get('git status | head -1').gsub(/^.+On branch /, '').chomp
  story_id = current_branch[/\d+/]
  unless story_id
    put "Branch name must contain a Pivotal Tracker story id"
    return 1
  end

  api = Pivotal::Api.new(:api_token => options[:api_token])
  project = api.projects.find(:id => options[:project_id])
  story = project.stories.find(:id => story_id)
  
  put "Marking Story #{story_id} as finished..."
  if story.update_attributes(:current_state => :finished)
  
    target_branch = options[:target]
    put "Merging #{current_branch} into #{target_branch}"
    sys "git checkout #{target_branch}"
    sys "git merge --no-ff #{current_branch}"
  
    put "Removing #{current_branch} branch"
    sys "git branch -d #{current_branch}"

    return 0
  else
    put "Unable to mark Story #{story_id} as finished"
    
    return 1
  end
end