Class: StoryCommit

Inherits:
Command show all
Defined in:
lib/pivotal-github/story_commit.rb

Instance Attribute Summary

Attributes inherited from Command

#args, #known_options, #options, #unknown_options

Instance Method Summary collapse

Methods inherited from Command

#initialize, #parse, run!, #story_branch, #story_id, #story_ids

Constructor Details

This class inherits a constructor from Command

Instance Method Details

#cmdObject

Returns a command appropriate for executing at the command line. We take care to insert the story number and, if necessary, an indication that the commit finishes the story.



54
55
56
57
58
59
60
# File 'lib/pivotal-github/story_commit.rb', line 54

def cmd
  c = ['git commit']
  c << '-a' if all?
  c << %(-m "#{message}") if message?
  c << argument_string(unknown_options) unless unknown_options.empty?
  c.join(' ')
end

#messageObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/pivotal-github/story_commit.rb', line 27

def message
  if story_ids.empty?
    # Arranges to fall through to regular 'git commit'
    options.message
  else
    if finish?
      label = "Finishes #{message_ids}"
    elsif deliver?
      label = "Delivers #{message_ids}"
    else
      label = message_ids
    end
    "[#{label}] #{options.message}"
  end
end

#message_idsObject

Returns the story ids formatted for story commits. For single-id stories, this is just the number preceded by ‘#’, as in ‘#6283185’. For multiple-id stories, each story id is precede by ‘#’, as in ‘#6283185 #3141592’



47
48
49
# File 'lib/pivotal-github/story_commit.rb', line 47

def message_ids
  story_ids.map { |id| "##{id}" }.join(' ')
end

#parserObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/pivotal-github/story_commit.rb', line 5

def parser
  OptionParser.new do |opts|
    opts.banner = "Usage: git story-commit [options]"
    opts.on("-m", "--message MESSAGE",
            "add a commit message (including story #)") do |opt|
      self.options.message = opt
    end
    opts.on("-f", "--finish", "mark story as finished") do |opt|
      self.options.finish = opt
    end
    opts.on("-d", "--deliver", "mark story as delivered") do |opt|
      self.options.deliver = opt
    end
    opts.on("-a", "--all", "commit all changed files") do |opt|
      self.options.all = opt
    end
    opts.on_tail("-h", "--help", "this usage guide") do
      puts opts.to_s; exit 0
    end
  end
end

#run!Object



62
63
64
# File 'lib/pivotal-github/story_commit.rb', line 62

def run!
  system cmd
end