pivo_flow 0.3.0 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ notifications:
6
+ email:
7
+ recipients:
8
+ - lubieniebieski@gmail.com
data/README.md CHANGED
@@ -1,18 +1,12 @@
1
1
  # PivoFlow
2
2
 
3
- TODO: Write a gem description
3
+ [![Build Status](https://secure.travis-ci.org/hybridgroup/taskmapper.png?branch=master)](http://travis-ci.org/hybridgroup/taskmapper)
4
4
 
5
- ## Installation
6
-
7
- Add this line to your application's Gemfile:
8
-
9
- gem 'pivo_flow'
5
+ PivoFlow let's you choose the story from Pivotal Tracker you are currently working on. Intended for all the people, who doesn't like feature-branch approach or are "merdżuj - nie pier*ol"-theory enthusiasts.
10
6
 
11
- And then execute:
12
-
13
- $ bundle
7
+ ## Installation
14
8
 
15
- Or install it yourself as:
9
+ Install it yourself as:
16
10
 
17
11
  $ gem install pivo_flow
18
12
 
@@ -39,10 +33,42 @@ Clear current story without notifying Pivotal
39
33
 
40
34
  pf clear
41
35
 
36
+ Display current gem version
37
+
38
+ pf version
39
+
42
40
  ## Git-hooks
43
41
 
44
42
  This gem installs a `pepare-commit-msg` hook by adding a reference to `pf-prepare-commit-msg` file. In short: you shouldn't be worried about your own `prepare-commit-msg` hook, the one added by `pivo_flow` will be added in the last line of original hook file.
45
43
 
44
+ ## Roadmap
45
+
46
+ ### Incoming releases
47
+
48
+ * story statistics
49
+ * colorized output
50
+
51
+ ### 0.3 Current release
52
+
53
+ * single-story view
54
+ * flow:
55
+ * select story
56
+ * read the story description
57
+ * accept or back to story selection
58
+ * **TODO** `pf info` displaying info about current task, it's comments and all the available data
59
+ * **TODO** `pf help`
60
+
61
+ ### 0.2
62
+
63
+ * git hoook
64
+ * formatted output
65
+ * bugfixes
66
+
67
+ ### before 0.2
68
+
69
+ * gem basic structure
70
+ * git config read/write
71
+
46
72
  ## Contributing
47
73
 
48
74
  1. Fork it
@@ -50,3 +76,7 @@ This gem installs a `pepare-commit-msg` hook by adding a reference to `pf-prepar
50
76
  3. Commit your changes (`git commit -am 'Added some feature'`)
51
77
  4. Push to the branch (`git push origin my-new-feature`)
52
78
  5. Create new Pull Request
79
+
80
+ ## Thanks
81
+
82
+ This gem is inspired by https://github.com/blindsey/git_pivotal_tracker. Thanks to it's author for the inspiration and idea. If you would like to use Pivotal with feature-branch-based flow, `git_pivotal_tracker` is the way you should proably go.
data/Rakefile CHANGED
@@ -1,2 +1,5 @@
1
1
  #!/usr/bin/env rake
2
2
  require "bundler/gem_tasks"
3
+ require "rspec/core/rake_task"
4
+ RSpec::Core::RakeTask.new(:spec)
5
+ task :default => :spec
data/bin/pf CHANGED
@@ -4,5 +4,5 @@ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
4
4
 
5
5
  require 'pivo_flow'
6
6
 
7
- exit PivoFlow::Cli.new(*ARGV)
7
+ exit PivoFlow::Cli.new(*ARGV).go!
8
8
 
@@ -1,13 +1,24 @@
1
1
  module PivoFlow
2
+
3
+ # This class is responsible for setting up the project environment
4
+ #
5
+ # * saving Pivotal Tracker API token and project ID in git repository config
6
+ # * installing git hook
7
+
2
8
  class Base
9
+
10
+ # Git repository directory
3
11
  GIT_DIR = '.git'
12
+ # Keys used by gem in git config, with corresponding questions which are
13
+ # used during project setup
4
14
  KEYS_AND_QUESTIONS = {
5
15
  "pivo-flow.project-id" => "Pivotal: what is your project's ID?",
6
16
  "pivo-flow.api-token" => "Pivotal: what is your pivotal tracker api-token?"
7
17
  }
8
18
 
9
- def initialize(*args)
10
- @options = {}
19
+ # Basic initialize method
20
+ def initialize(options={})
21
+ @options = options
11
22
  @current_dir = Dir.pwd
12
23
 
13
24
  # exit if no git repo found
@@ -29,10 +40,16 @@ module PivoFlow
29
40
  run
30
41
  end
31
42
 
43
+ # Check if git hook is already installed
32
44
  def git_hook_needed?
33
45
  !File.executable?(@git_hook_path) || !File.read(@git_hook_path).match(/#{@pf_git_hook_name} \$1/)
34
46
  end
35
47
 
48
+ # Install git hook
49
+ # Copy hook to <tt>.git/hooks</tt> directory and add a reference to this
50
+ # executable file within <tt>prepare-commit-msg</tt> hook (it may be
51
+ # helpful if user has his custom hooks)
52
+
36
53
  def install_git_hook
37
54
  puts "Installing prepare-commit-msg hook..."
38
55
  hook_path = File.join(File.dirname(__FILE__), '..', '..', 'bin', @pf_git_hook_name)
@@ -50,22 +67,30 @@ module PivoFlow
50
67
  puts "Success!\n"
51
68
  end
52
69
 
70
+ # This method is fired after initialization and should be overwritten by
71
+ # subclasses
53
72
  def run
54
73
  end
55
74
 
75
+ # Get full user name from git config, i.e. Adam Newman
56
76
  def user_name
57
77
  @options[:user_name] ||= @options[:repository].config['pivotal.full-name'] || @options[:repository].config['user.name']
58
78
  end
59
79
 
80
+ # Setup project by entering Pivotal <tt>api-token</tt> and Pivotal Tracker <tt>project_id</tt>
60
81
  def reconfig
61
82
  KEYS_AND_QUESTIONS.each do |key, question|
62
83
  ask_question_and_force_update_config(question, key)
63
84
  end
64
- puts "[SUCCESS] Pivotal Tracker configuration has been updated."
85
+ config_update_success
65
86
  end
66
87
 
67
88
  private
68
89
 
90
+ def config_update_success
91
+ puts "[SUCCESS] Pivotal Tracker configuration has been updated."
92
+ end
93
+
69
94
  def git_config_ok?
70
95
  !KEYS_AND_QUESTIONS.keys.any? { |key| @options[:repository].config[key].nil? }
71
96
  end
@@ -92,6 +117,13 @@ module PivoFlow
92
117
  @options[:repository].config[variable] = ask_question(question)
93
118
  end
94
119
 
120
+ def update_config_from_options
121
+ KEYS_AND_QUESTIONS.keys.each do |key|
122
+ @options[:repository].config[key] = @options[key.gsub(/-/, "_")]
123
+ end
124
+ config_update_success
125
+ end
126
+
95
127
  def ask_question question, first_answer = nil
96
128
  h = HighLine.new
97
129
  h.ask("#{question}\t") do |q|
data/lib/pivo_flow/cli.rb CHANGED
@@ -2,37 +2,42 @@ module PivoFlow
2
2
  class Cli
3
3
 
4
4
  def initialize *args
5
- if args.length.zero?
6
- puts "You forgot method name"
7
- exit 1
8
- end
5
+ @file_story_path = File.join(Dir.pwd, "/tmp/.pivotal_story_id")
6
+ @args = args
7
+ end
8
+
9
+ def go!
9
10
  Signal.trap(2) {
10
11
  puts "\nkkthxbye!"
11
- exit(0)
12
+ return 0
12
13
  }
13
- parse_argv(*args)
14
+ return parse_argv(@args)
14
15
  end
15
16
 
17
+ private
18
+
16
19
  def stories
17
- PivoFlow::Pivotal.new.show_stories
20
+ pivotal_object.show_stories
18
21
  end
19
22
 
20
- def start story_id
21
- PivoFlow::Pivotal.new.pick_up_story(story_id)
23
+ def start story_id=nil
24
+ unless story_id
25
+ puts "Ok, but which story?"
26
+ return 1
27
+ end
28
+ pivotal_object.pick_up_story(story_id)
22
29
  end
23
30
 
24
31
  def finish story_id=nil
25
- file_story_path = File.join(Dir.pwd, "/tmp/.pivotal_story_id")
26
- if File.exists? file_story_path
27
- story_id = File.open(file_story_path).read.strip
32
+ if File.exists? @file_story_path
33
+ story_id = File.open(@file_story_path).read.strip
28
34
  end
29
- PivoFlow::Pivotal.new.finish_story(story_id)
35
+ pivotal_object.finish_story(story_id)
30
36
  end
31
37
 
32
38
  def clear
33
- file_story_path = File.join(Dir.pwd, "/tmp/.pivotal_story_id")
34
- if File.exists? file_story_path
35
- FileUtils.remove_file(file_story_path)
39
+ if File.exists? @file_story_path
40
+ FileUtils.remove_file(@file_story_path)
36
41
  end
37
42
  puts "Current pivotal story id cleared."
38
43
  end
@@ -45,22 +50,75 @@ module PivoFlow
45
50
  puts PivoFlow::VERSION
46
51
  end
47
52
 
48
- private
53
+ def pivotal_object
54
+ @pivotal_object ||= PivoFlow::Pivotal.new(@options)
55
+ end
56
+
57
+ def no_method_error
58
+ puts "You forgot a method name"
59
+ end
49
60
 
50
- def valid_method? method_name
51
- self.methods.include? method_name.to_sym
61
+ def invalid_method_error
62
+ puts "Ups, no such method..."
52
63
  end
53
64
 
54
- def parse_argv(*args)
55
- command = args.first.split.first
56
- args = args.slice(1..-1)
65
+ def parse_argv(args)
66
+ @options = {}
67
+
68
+ opt_parser = OptionParser.new do |opts|
69
+ opts.banner = "Usage: pf <COMMAND> [OPTIONS]\n"
70
+ opts.separator "Commands"
71
+ opts.separator " clear: clears STORY_ID from temp file"
72
+ opts.separator " finish [STORY_ID]: finish story on Pivotal"
73
+ opts.separator " reconfig: clears API_TOKEN and PROJECT_ID from git config"
74
+ opts.separator " start <STORY_ID>: start a story of given ID"
75
+ opts.separator " stories: list stories for current project"
76
+ opts.separator ""
77
+ opts.separator "Options"
78
+
79
+ opts.on_tail("-h", "--help", "Show this message") do
80
+ puts opts
81
+ return 1
82
+ end
83
+
84
+ opts.on_tail("-v", "--version", "Show version") do
85
+ puts PivoFlow::VERSION
86
+ return 1
87
+ end
88
+
89
+ opts.on("-t <API_TOKEN>", "--token <API_TOKEN>", "Sets Pivotal Tracker API TOKEN") do |api_token|
90
+ @options[:api_token] = api_token
91
+ end
92
+
93
+ opts.on("-p <PROJECT_ID>", "--project <PROJECT_ID>", Numeric, "Sets Pivotal Tracker PROJECT_ID") do |project_id|
94
+ @options[:project_id] = project_id
95
+ end
57
96
 
58
- unless valid_method?(command)
59
- puts "Ups, no such method..."
60
- exit 1
61
97
  end
62
- send(command, *args)
63
- exit 0
98
+
99
+ opt_parser.parse!(args)
100
+
101
+ case args[0]
102
+ when "clear"
103
+ clear
104
+ when "reconfig"
105
+ reconfig
106
+ when "start"
107
+ start args[1]
108
+ when "stories"
109
+ stories
110
+ when "finish"
111
+ finish args[1]
112
+ when nil
113
+ no_method_error
114
+ puts opt_parser.summarize
115
+ return 1
116
+ else
117
+ invalid_method_error
118
+ return 1
119
+ end
120
+ return 0
121
+
64
122
  end
65
123
 
66
124
  end
@@ -68,7 +68,6 @@ module PivoFlow
68
68
  end
69
69
  end
70
70
 
71
-
72
71
  def find_story story_id
73
72
  story = project_stories.find { |p| p.id == story_id }
74
73
  story.nil? ? @options[:project].stories.find(story_id) : story
@@ -1,3 +1,3 @@
1
1
  module PivoFlow
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.3"
3
3
  end
data/pivo_flow.gemspec CHANGED
@@ -19,5 +19,7 @@ Gem::Specification.new do |gem|
19
19
  gem.add_runtime_dependency "grit"
20
20
  gem.add_runtime_dependency "highline"
21
21
  gem.add_development_dependency "rspec"
22
+ gem.add_development_dependency "simplecov"
23
+ gem.add_development_dependency "rake"
22
24
 
23
25
  end
@@ -0,0 +1,73 @@
1
+ require_relative './../../lib/pivo_flow/cli'
2
+
3
+ describe PivoFlow::Cli do
4
+
5
+ before(:each) do
6
+ # we don't need cli output all over the specs
7
+ PivoFlow::Cli.any_instance.stub(:puts)
8
+ end
9
+
10
+ describe "with no args provided" do
11
+
12
+ let(:command) { PivoFlow::Cli.new.go! }
13
+
14
+ before(:each) do
15
+ PivoFlow::Cli.any_instance.should_receive(:no_method_error).and_return(true)
16
+ end
17
+
18
+ it "calls no_method_error message " do
19
+ command
20
+ end
21
+
22
+ it "returns 1" do
23
+ expect(command).to eq 1
24
+ end
25
+
26
+ end
27
+
28
+ describe "on invalid command" do
29
+
30
+ let(:command) { PivoFlow::Cli.new("invalid_method_name").go! }
31
+
32
+ before(:each) do
33
+ PivoFlow::Cli.any_instance.should_receive(:invalid_method_error)
34
+ end
35
+
36
+ it "calls invalid_method_error message" do
37
+ command
38
+ end
39
+
40
+ it "returns 1" do
41
+ expect(command).to eq 1
42
+ end
43
+
44
+ end
45
+
46
+ describe "with valid command" do
47
+ cmd = "stories"
48
+ let(:command) { PivoFlow::Cli.new(cmd).go! }
49
+
50
+ before do
51
+ PivoFlow::Cli.any_instance.should_receive(cmd.to_sym)
52
+ end
53
+
54
+ it "runs this command if it is public" do
55
+ command
56
+ end
57
+
58
+ it "returns 0" do
59
+ expect(command).to eq 0
60
+ end
61
+
62
+ end
63
+
64
+ it "should allow to execute given commands" do
65
+ methods = [:stories, :start, :finish, :clear, :reconfig]
66
+
67
+ methods.each do |method|
68
+ PivoFlow::Cli.any_instance.stub(method)
69
+ PivoFlow::Cli.new(method.to_s).go!.should eq 0
70
+ end
71
+ end
72
+
73
+ end
data/spec/spec_helper.rb CHANGED
@@ -0,0 +1,7 @@
1
+ require 'simplecov'
2
+ SimpleCov.start
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
4
+
5
+ require 'pivo_flow'
6
+ require 'rspec'
7
+
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pivo_flow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-08-07 00:00:00.000000000 Z
12
+ date: 2012-08-11 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pivotal-tracker
@@ -75,6 +75,38 @@ dependencies:
75
75
  - - ! '>='
76
76
  - !ruby/object:Gem::Version
77
77
  version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: simplecov
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rake
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
78
110
  description: Automated querying for pivotal stories, adding story id to commit message,
79
111
  etc.
80
112
  email:
@@ -86,6 +118,8 @@ extensions: []
86
118
  extra_rdoc_files: []
87
119
  files:
88
120
  - .gitignore
121
+ - .rspec
122
+ - .travis.yml
89
123
  - Gemfile
90
124
  - LICENSE
91
125
  - README.md
@@ -98,6 +132,7 @@ files:
98
132
  - lib/pivo_flow/pivotal.rb
99
133
  - lib/pivo_flow/version.rb
100
134
  - pivo_flow.gemspec
135
+ - spec/pivo_flow/cli_spec.rb
101
136
  - spec/spec_helper.rb
102
137
  homepage: https://github.com/lubieniebieski/pivo_flow
103
138
  licenses: []
@@ -124,4 +159,6 @@ signing_key:
124
159
  specification_version: 3
125
160
  summary: Simple pivotal tracker integration for day to day work with git
126
161
  test_files:
162
+ - spec/pivo_flow/cli_spec.rb
127
163
  - spec/spec_helper.rb
164
+ has_rdoc: