Skip to content
Browse files

working on the commit hook

  • Loading branch information...
1 parent 25b1989 commit f1691e28a406165f34d4b96b0d14da91db9174bb @leonid-shevtsov committed Jul 29, 2011
View
1 .gitignore
@@ -3,3 +3,4 @@ pkg/*
.bundle
.pivotalrc
.pivotal_cache
+.rvmrc
View
18 Gemfile.lock
@@ -1,7 +1,8 @@
PATH
remote: .
specs:
- pivotal_shell (0.2.0)
+ pivotal_shell (0.2.1)
+ highline
pivotal-tracker (> 0.3)
sqlite3
@@ -11,17 +12,22 @@ GEM
builder (3.0.0)
happymapper (0.3.2)
libxml-ruby (~> 1.1.3)
+ highline (1.6.2)
libxml-ruby (1.1.4)
mime-types (1.16)
- nokogiri (1.4.3.1)
- pivotal-tracker (0.3.1)
+ nokogiri (1.5.0)
+ pivotal-tracker (0.4.1)
builder
+ builder
+ happymapper (>= 0.3.2)
happymapper (>= 0.3.2)
- nokogiri (~> 1.4.3.1)
+ nokogiri (>= 1.4.3)
+ nokogiri (~> 1.4)
+ rest-client (~> 1.6.0)
rest-client (~> 1.6.0)
- rest-client (1.6.1)
+ rest-client (1.6.3)
mime-types (>= 1.16)
- sqlite3 (1.3.3)
+ sqlite3 (1.3.4)
PLATFORMS
ruby
View
2 bin/pivotal
@@ -4,6 +4,7 @@ require 'optparse'
require 'pivotal_shell'
require 'pivotal_shell/configuration'
require 'pivotal_shell/cache'
+require 'highline/import'
#require 'active_support/core_ext'
PivotalShell::Configuration.load
@@ -15,6 +16,7 @@ commands = [
['finish', 'finish a story'],
['update', 'update stories status from the server'],
['reload', 'reload entire project from the server'],
+ ['commithook', 'commit hook for git']
]
banner = "Pivotal command-line client #{PivotalShell::VERSION}\nUsage: pivotal COMMAND PARAMS\n\nAvailable commands:\n\n#{commands.map{|c, d| "#{c} - #{d}"}.join("\n")}\n\nRun pivotal COMMAND --help for more info on a specific command\n\n"
View
69 lib/pivotal_shell/commands/commithook.rb
@@ -0,0 +1,69 @@
+module PivotalShell::Commands
+ class PivotalShell::Commands::Commithook < PivotalShell::Command
+ def initialize(options)
+ end
+
+ def execute
+ begin
+ @stories = PivotalShell::Cache::Story.all(:owner => PivotalShell::Configuration.me, :state => %w(unstarted started))
+ @stories.each do |story|
+ puts "#{highlighted_id(story.id).rjust(12)} #{story.name}"
+ end
+ puts @error_message if @error_message
+ print 'RACBF>'
+ response = gets.chomp
+ case response
+ when 'R', 'r':
+ puts 'Refreshing list of stories from server...'
+ PivotalShell::Configuration.cache.refresh
+ when 'A', 'a':
+ @exit = true
+ when /(\d+)(!?)/
+ @bang = $2=='!'
+ selected_stories = find_stories_by_id_fragment($1)
+ if selected_stories.empty?
+ @error_message = 'No story matches this ID'
+ elsif selected_stories.length==1
+ @story = selected_stories.first
+ @exit = true
+ else
+ @error_message = 'More than one matching story. Print at least the highlighted part of the ID, please'
+ end
+ end
+ puts
+ end while !@exit
+
+ if @story
+ print %Q{Confirm attaching commit to story "#{@story.name}" [Yn]:}
+ answer = gets.chomp
+ if answer=='' || (answer[0,1].downcase == 'y')
+ puts "COMMIT MESSAGE"
+ end
+ end
+ end
+
+ protected
+ def unique_fragment_length(id)
+ ids = @stories.map(&:id).map(&:to_s)
+ 1.upto(id.length) { |i|
+ fragment = id[-i..-1]
+ if @stories.select{|s| s.id.to_s[-i..-1]==fragment}.length==1
+ return i
+ end
+ }
+ return id.length
+ end
+
+ def find_stories_by_id_fragment(id)
+ @stories.select{|story| story.id.to_s =~ /#{id}\Z/}
+ end
+
+ def highlighted_id(id)
+ id = id.to_s
+ length = unique_fragment_length(id)
+ '['+id[0..-(length-1)] +
+ $terminal.color(id[-length..-1], :yellow) +
+ ']'
+ end
+ end
+end
View
20 lib/pivotal_shell/commands/stories.rb
@@ -1,4 +1,22 @@
-#<PivotalTracker::Story:0x90b74f4 @jira_url=nil, @requested_by="Pavel Pavlovsky", @name="Add titles for the pages", @attachments=[], @project_id=110960, @jira_id=nil, @id=5952583, @current_state="accepted", @integration_id=nil, @accepted_at=#<DateTime: 212157861559/86400,1/12,2299161>, @labels="ui", @url="http://www.pivotaltracker.com/story/show/5952583", @estimate=nil, @description="so they are identified correctly by user.\nto clarify", @other_id=nil, @created_at=#<DateTime: 5303878313/2160,1/8,2299161>, @owned_by="Leonid Shevtsov", @story_type="chore">
+#<PivotalTracker::Story:0x90b74f4
+# @jira_url=nil,
+# @requested_by="Pavel Pavlovsky",
+# @name="Add titles for the pages",
+# @attachments=[],
+# @project_id=110960,
+# @jira_id=nil,
+# @id=5952583,
+# @current_state="accepted",
+# @integration_id=nil,
+# @accepted_at=#<DateTime: 212157861559/86400,1/12,2299161>,
+# @labels="ui",
+# @url="http://www.pivotaltracker.com/story/show/5952583",
+# @estimate=nil,
+# @description="so they are identified correctly by user.\nto clarify",
+# @other_id=nil,
+# @created_at=#<DateTime: 5303878313/2160,1/8,2299161>,
+# @owned_by="Leonid Shevtsov",
+# @story_type="chore">
module PivotalShell::Commands
class PivotalShell::Commands::Stories < PivotalShell::Command
View
18 lib/pivotal_shell/configuration.rb
@@ -41,20 +41,24 @@ def self.status_icon(status)
{
'unscheduled' => ' ',
'unstarted' => '.',
- 'started' => 'S',
- 'finished' => 'F',
- 'delivered' => 'D',
- 'accepted' => 'A',
- 'rejected' => 'R'
+ 'started' => $terminal.color('S', :white),
+ 'finished' => $terminal.color('F', :yellow),
+ 'delivered' => $terminal.color('D', :yellow),
+ 'accepted' => $terminal.color('A', :green),
+ 'rejected' => $terminal.color('R', :red)
}[status]
end
def self.estimate_icon(estimate)
- estimate.nil? ? '*' : ({-1 => '?', 0 => '0', 1=>'1', 2=>'2', 3 => '3'}[estimate] || "[#{estimate.inspect}]")
+ (estimate.nil? ? ' ' : ({-1 => '?', 0 => '0', 1=>'1', 2=>'2', 3 => '3'}[estimate] || estimate.to_s)).rjust 2
end
def self.type_icon(type)
- {'feature' => 'F', 'chore' => 'C', 'bug' => 'B'}[type]
+ {
+ 'feature' => $terminal.color('F', :yellow),
+ 'chore' => $terminal.color('C', :white),
+ 'bug' => $terminal.color('B', :red)
+ }[type]
end
def self.icon(type, status, estimate)
View
1 pivotal_shell.gemspec
@@ -13,6 +13,7 @@ Gem::Specification.new do |s|
s.add_dependency 'pivotal-tracker', '>0.3'
s.add_dependency 'sqlite3'
+ s.add_dependency 'highline'
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")

0 comments on commit f1691e2

Please sign in to comment.
Something went wrong with that request. Please try again.