Class: GitPivotalTracker::Base

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

Direct Known Subclasses

Finish, Info, Story

Constant Summary collapse

GIT_DIR =
ENV['GIT_DIR'] || '.git'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Base

Returns a new instance of Base.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/git_pivotal_tracker/base.rb', line 7

def initialize(*args)
  directories = Dir.pwd.split(::File::SEPARATOR)
  begin
    break if File.directory?(File.join(directories, GIT_DIR))
  end while directories.pop

  raise "No #{GIT_DIR} directory found" if directories.empty?
  root = File.join(directories, GIT_DIR)
  @repository = Grit::Repo.new(root)

  new_hook_path = File.join(root, 'hooks', 'commit-msg')
  unless File.executable?(new_hook_path)
    puts "Installing commit-msg hook..."
    old_hook_path = File.join(File.dirname(__FILE__), '..', '..', 'bin', 'commit-msg')
    FileUtils.cp(old_hook_path, new_hook_path, :preserve => true)
  end

  @options = {}
  parse_gitconfig
  parse_argv(*args)
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/git_pivotal_tracker/base.rb', line 5

def options
  @options
end

#repositoryObject (readonly)

Returns the value of attribute repository.



5
6
7
# File 'lib/git_pivotal_tracker/base.rb', line 5

def repository
  @repository
end

Instance Method Details

#run!Object



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/git_pivotal_tracker/base.rb', line 29

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

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

  nil
end