Skip to content
Browse files

initial commit

  • Loading branch information...
0 parents commit f42b464c765ea54c361182e1aea777371b6be4a1 @leonid-shevtsov leonid-shevtsov committed Dec 2, 2010
3 .gitignore
@@ -0,0 +1,3 @@
+pkg/*
+*.gem
+.bundle
4 Gemfile
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in pivotal_shell.gemspec
+gemspec
29 Gemfile.lock
@@ -0,0 +1,29 @@
+PATH
+ remote: .
+ specs:
+ pivotal_shell (0.0.1)
+ pivotal-tracker (= 0.3)
+
+GEM
+ remote: http://rubygems.org/
+ specs:
+ builder (3.0.0)
+ happymapper (0.3.2)
+ libxml-ruby (~> 1.1.3)
+ libxml-ruby (1.1.4)
+ mime-types (1.16)
+ nokogiri (1.4.3.1)
+ pivotal-tracker (0.3.0)
+ builder
+ happymapper (>= 0.3.2)
+ nokogiri (~> 1.4.3.1)
+ rest-client (~> 1.6.0)
+ rest-client (1.6.1)
+ mime-types (>= 1.16)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ pivotal-tracker (= 0.3)
+ pivotal_shell!
32 README.markdown
@@ -0,0 +1,32 @@
+
+Examples
+
+ #~/.pivotalrc
+ api_key: abcdef0123456789
+
+ #project/.pivotalrc
+ project_id: 123456
+
+List all your unfinished stories
+
+ pivotal stories
+
+List all your stories
+
+ pivotal stories --status any
+
+List all finished stories for everyone
+
+ pivotal stories --status finished --for everyone
+
+Start story
+
+ pivotal start 123456
+
+Finish story
+
+ pivotal finish 123456
+
+Commit (with git, all comments after the story id go to git, story id gets appended to comments)
+
+ pivotal commit 123456 "some more comments"
2 Rakefile
@@ -0,0 +1,2 @@
+require 'bundler'
+Bundler::GemHelper.install_tasks
15 bin/pivotal
@@ -0,0 +1,15 @@
+#!/usr/bin/env ruby
+
+require 'pivotal_shell'
+require 'pivotal_shell/configuration'
+#require 'active_support/core_ext'
+
+PivotalShell::Configuration.load
+
+command = ARGV.shift
+
+require "pivotal_shell/commands/#{command}"
+
+command_class = PivotalShell::Commands.const_get(command[0,1].upcase+command[1..-1])
+
+command_class.new(ARGV).execute
25 lib/pivotal_shell.rb
@@ -0,0 +1,25 @@
+require 'pivotal_tracker'
+require 'pivotal_shell/command'
+
+module PivotalShell
+ class Exception < StandardError; end
+end
+
+module PivotalTracker
+ class <<self
+ def encode_options(options)
+ return nil if !options.is_a?(Hash) || options.empty?
+ options_strings = []
+ # remove options which are not filters, and encode them as such
+ [:limit, :offset].each do |o|
+ options_strings << "#{CGI.escape(o.to_s)}=#{CGI.escape(options.delete(o))}" if options[o]
+ end
+ # assume remaining key-value pairs describe filters, and encode them as such.
+ filters_string = options.map do |key, value|
+ "#{CGI.escape(key.to_s)}%3A#{CGI.escape([value].flatten.join(','))}"
+ end
+ options_strings << "filter=#{filters_string.join('+')}" unless filters_string.empty?
+ return "?#{options_strings.join('&')}"
+ end
+ end
+end
4 lib/pivotal_shell/command.rb
@@ -0,0 +1,4 @@
+class PivotalShell::Command
+ def initialize(options)
+ end
+end
15 lib/pivotal_shell/commands/stories.rb
@@ -0,0 +1,15 @@
+#<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
+ def initialize(options)
+
+ end
+
+ def execute
+ stories = PivotalShell::Configuration.project.stories.all(:owner => PivotalShell::Configuration.me, :state => %w(unestimated unstarted started))
+
+ puts stories.map{|s| "#{("[#{s.id}]").rjust 12} #{PivotalShell::Configuration.icon(s.current_state,s.estimate)} #{s.name}"}.join("\n")
+ end
+ end
+end
32 lib/pivotal_shell/commands/story.rb
@@ -0,0 +1,32 @@
+#<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">
+require 'optparse'
+
+module PivotalShell::Commands
+ class PivotalShell::Commands::Story < PivotalShell::Command
+ def initialize(options)
+ opts = OptionParser.new do |opts|
+ opts.banner = 'Usage: pivotal story STORY_ID'
+ end
+ opts.parse!(options)
+ if options.empty? || options.length>1
+ puts opts
+ exit
+ else
+ @story_id = options.first
+ end
+ end
+
+ def execute
+ @story = PivotalShell::Configuration.project.stories.find(@story_id)
+ puts ["[#{@story.id}] - #{@story.name}",
+ "State: #{@story.current_state}",
+ "Owner: #{@story.owned_by}",
+ "Creator: #{@story.requested_by}",
+ "URL: #{@story.url}",
+ "",
+ "#{@story.description.strip}",
+ "",
+ ""].join("\n")
+ end
+ end
+end
60 lib/pivotal_shell/configuration.rb
@@ -0,0 +1,60 @@
+require 'yaml'
+require 'pivotal_tracker'
+
+module PivotalShell::Configuration
+ def self.load
+ @global_config = YAML.load_file(global_config_path)
+ @project_config = YAML.load_file(project_config_path)
+ PivotalTracker::Client.token = @global_config['api_token']
+ end
+
+ def self.project
+ @project ||= PivotalTracker::Project.find(@project_config['project_id'])
+ end
+
+ def self.me
+ @me ||= @project_config['me']
+ end
+
+ def self.global_config_path
+ @global_config_path ||= File.expand_path('~/.pivotalrc')
+ end
+
+ def self.project_config_path
+ @project_config_path ||= find_project_config
+ end
+
+ def self.status_icon(status)
+ {
+ 'unscheduled' => ' ',
+ 'unstarted' => '.',
+ 'started' => 'S',
+ 'finished' => 'F',
+ 'delivered' => 'D',
+ 'accepted' => 'A',
+ 'rejected' => 'R'
+ }[status]
+ end
+
+ def self.estimate_icon(estimate)
+ estimate.nil? ? '*' : {-1 => '?', 1=>'1', 2=>'2', 3 => '3'}[estimate]
+ end
+
+ def self.icon(status,estimate)
+ estimate_icon(estimate)+status_icon(status)
+ end
+
+private
+
+ def self.find_project_config
+ dirs = File.split(Dir.pwd)
+ until dirs.empty? || File.exists?(File.join(dirs, '.pivotalrc'))
+ dirs.pop
+ end
+ if dirs.empty? || File.join(dirs, '.pivotalrc')==global_config_path
+ raise PivotalShell::Exception.new('No project .pivotalrc found')
+ else
+ File.join(dirs, '.pivotalrc')
+ end
+ end
+end
3 lib/pivotal_shell/version.rb
@@ -0,0 +1,3 @@
+module PivotalShell
+ VERSION = "0.0.1"
+end
21 pivotal_shell.gemspec
@@ -0,0 +1,21 @@
+# -*- encoding: utf-8 -*-
+$:.push File.expand_path("../lib", __FILE__)
+require "pivotal_shell/version"
+
+Gem::Specification.new do |s|
+ s.name = "pivotal_shell"
+ s.version = PivotalShell::VERSION
+ s.platform = Gem::Platform::RUBY
+ s.authors = ["Leonid Shevtsov"]
+ s.email = ["leonid@shevtsov.me"]
+ s.homepage = "http://rubygems.org/gems/pivotal_shell"
+ s.summary = %q{Pivotal shell}
+ s.description = %q{}
+
+ s.add_dependency 'pivotal-tracker', '=0.3'
+
+ s.files = `git ls-files`.split("\n")
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
+ s.require_paths = ["lib"]
+end

0 comments on commit f42b464

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