Skip to content

Commit

Permalink
Move current_branch into Base class
Browse files Browse the repository at this point in the history
  • Loading branch information
trydionel committed Apr 10, 2011
1 parent ff2546d commit 55374c8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
16 changes: 10 additions & 6 deletions lib/commands/base.rb
Expand Up @@ -6,16 +6,16 @@ module Commands
class Base

attr_accessor :input, :output, :options

def initialize(input=STDIN, output=STDOUT, *args)
@input = input
@output = output
@options = {}

parse_gitconfig
parse_argv(*args)
end

def put(string, newline=true)
@output.print(newline ? string + "\n" : string) unless options[:quiet]
end
Expand All @@ -29,20 +29,24 @@ def get(cmd)
put cmd if options[:verbose]
`#{cmd}`
end

def run!
unless options[:api_token] && options[:project_id]
put "Pivotal Tracker API Token and Project ID are required"
return 1
end

PivotalTracker::Client.token = options[:api_token]

return 0
end

protected

def current_branch
@current_branch ||= get('git symbolic-ref HEAD').chomp.split('/').last
end

def project
@project ||= PivotalTracker::Project.find(options[:project_id])
end
Expand Down
12 changes: 4 additions & 8 deletions lib/commands/finish.rb
Expand Up @@ -2,10 +2,10 @@

module Commands
class Finish < Base

def run!
super

unless story_id
put "Branch name must contain a Pivotal Tracker story id"
return 1
Expand All @@ -23,13 +23,13 @@ def run!
return 0
else
put "Unable to mark Story #{story_id} as finished"

return 1
end
end

protected

def finished_state
if story.story_type == "chore"
"accepted"
Expand All @@ -38,10 +38,6 @@ def finished_state
end
end

def current_branch
@current_branch ||= get('git symbolic-ref HEAD').chomp.split('/').last
end

def story_id
current_branch[/\d+/].to_i
end
Expand Down
4 changes: 0 additions & 4 deletions lib/commands/info.rb
Expand Up @@ -20,10 +20,6 @@ def run!

protected

def current_branch
@current_branch ||= get('git symbolic-ref HEAD').chomp.split('/').last
end

def story_id
current_branch[/\d+/].to_i
end
Expand Down

0 comments on commit 55374c8

Please sign in to comment.