git-storyid 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile CHANGED
@@ -2,6 +2,10 @@ source "http://rubygems.org"
2
2
 
3
3
  gem "pivotal-tracker"
4
4
  group :development do
5
- gem "rspec", "~> 2.8.0"
5
+ gem "webmock"
6
+ gem "debugger", :platform => "ruby_19"
7
+ gem "mocha"
8
+ gem "rspec"
6
9
  gem "jeweler", "~> 1.8.3"
10
+ gem "hashie"
7
11
  end
@@ -1,11 +1,22 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
+ addressable (2.3.2)
4
5
  builder (3.0.0)
5
- diff-lcs (1.1.3)
6
+ columnize (0.3.6)
7
+ crack (0.3.1)
8
+ debugger (1.2.1)
9
+ columnize (>= 0.3.1)
10
+ debugger-linecache (~> 1.1.1)
11
+ debugger-ruby_core_source (~> 1.1.4)
12
+ debugger-linecache (1.1.2)
13
+ debugger-ruby_core_source (>= 1.1.1)
14
+ debugger-ruby_core_source (1.1.4)
15
+ diff-lcs (1.2.1)
6
16
  git (1.2.5)
7
17
  happymapper (0.4.0)
8
18
  libxml-ruby (~> 2.0)
19
+ hashie (1.2.0)
9
20
  jeweler (1.8.4)
10
21
  bundler (~> 1.0)
11
22
  git (>= 1.2.5)
@@ -13,7 +24,10 @@ GEM
13
24
  rdoc
14
25
  json (1.7.3)
15
26
  libxml-ruby (2.3.3)
27
+ metaclass (0.0.1)
16
28
  mime-types (1.19)
29
+ mocha (0.13.2)
30
+ metaclass (~> 0.0.1)
17
31
  nokogiri (1.5.5)
18
32
  pivotal-tracker (0.5.4)
19
33
  builder
@@ -29,19 +43,26 @@ GEM
29
43
  json (~> 1.4)
30
44
  rest-client (1.6.7)
31
45
  mime-types (>= 1.16)
32
- rspec (2.8.0)
33
- rspec-core (~> 2.8.0)
34
- rspec-expectations (~> 2.8.0)
35
- rspec-mocks (~> 2.8.0)
36
- rspec-core (2.8.0)
37
- rspec-expectations (2.8.0)
38
- diff-lcs (~> 1.1.2)
39
- rspec-mocks (2.8.0)
46
+ rspec (2.13.0)
47
+ rspec-core (~> 2.13.0)
48
+ rspec-expectations (~> 2.13.0)
49
+ rspec-mocks (~> 2.13.0)
50
+ rspec-core (2.13.0)
51
+ rspec-expectations (2.13.0)
52
+ diff-lcs (>= 1.1.3, < 2.0)
53
+ rspec-mocks (2.13.0)
54
+ webmock (1.8.7)
55
+ addressable (>= 2.2.7)
56
+ crack (>= 0.1.7)
40
57
 
41
58
  PLATFORMS
42
59
  ruby
43
60
 
44
61
  DEPENDENCIES
62
+ debugger
63
+ hashie
45
64
  jeweler (~> 1.8.3)
65
+ mocha
46
66
  pivotal-tracker
47
- rspec (~> 2.8.0)
67
+ rspec
68
+ webmock
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.1
1
+ 0.3.0
@@ -4,15 +4,14 @@
4
4
  # -*- encoding: utf-8 -*-
5
5
 
6
6
  Gem::Specification.new do |s|
7
- s.name = %q{git-storyid}
8
- s.version = "0.2.1"
7
+ s.name = "git-storyid"
8
+ s.version = "0.3.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Bogdan Gusiev"]
12
- s.date = %q{2013-02-19}
13
- s.default_executable = %q{git-storyid}
14
- s.description = %q{Helps include pivotal story id and description in commit}
15
- s.email = %q{agresso@gmail.com}
12
+ s.date = "2013-03-06"
13
+ s.description = "Helps include pivotal story id and description in commit"
14
+ s.email = "agresso@gmail.com"
16
15
  s.executables = ["git-storyid"]
17
16
  s.extra_rdoc_files = [
18
17
  "LICENSE.txt",
@@ -34,28 +33,40 @@ Gem::Specification.new do |s|
34
33
  "spec/git_storyid_spec.rb",
35
34
  "spec/spec_helper.rb"
36
35
  ]
37
- s.homepage = %q{http://github.com/bogdan/git-storyid}
36
+ s.homepage = "http://github.com/bogdan/git-storyid"
38
37
  s.licenses = ["MIT"]
39
38
  s.require_paths = ["lib"]
40
- s.rubygems_version = %q{1.6.0}
41
- s.summary = %q{Attach commits to pivotal stories}
39
+ s.rubygems_version = "1.8.24"
40
+ s.summary = "Attach commits to pivotal stories"
42
41
 
43
42
  if s.respond_to? :specification_version then
44
43
  s.specification_version = 3
45
44
 
46
45
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
47
46
  s.add_runtime_dependency(%q<pivotal-tracker>, [">= 0"])
48
- s.add_development_dependency(%q<rspec>, ["~> 2.8.0"])
47
+ s.add_development_dependency(%q<webmock>, [">= 0"])
48
+ s.add_development_dependency(%q<debugger>, [">= 0"])
49
+ s.add_development_dependency(%q<mocha>, [">= 0"])
50
+ s.add_development_dependency(%q<rspec>, [">= 0"])
49
51
  s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
52
+ s.add_development_dependency(%q<hashie>, [">= 0"])
50
53
  else
51
54
  s.add_dependency(%q<pivotal-tracker>, [">= 0"])
52
- s.add_dependency(%q<rspec>, ["~> 2.8.0"])
55
+ s.add_dependency(%q<webmock>, [">= 0"])
56
+ s.add_dependency(%q<debugger>, [">= 0"])
57
+ s.add_dependency(%q<mocha>, [">= 0"])
58
+ s.add_dependency(%q<rspec>, [">= 0"])
53
59
  s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
60
+ s.add_dependency(%q<hashie>, [">= 0"])
54
61
  end
55
62
  else
56
63
  s.add_dependency(%q<pivotal-tracker>, [">= 0"])
57
- s.add_dependency(%q<rspec>, ["~> 2.8.0"])
64
+ s.add_dependency(%q<webmock>, [">= 0"])
65
+ s.add_dependency(%q<debugger>, [">= 0"])
66
+ s.add_dependency(%q<mocha>, [">= 0"])
67
+ s.add_dependency(%q<rspec>, [">= 0"])
58
68
  s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
69
+ s.add_dependency(%q<hashie>, [">= 0"])
59
70
  end
60
71
  end
61
72
 
@@ -11,10 +11,11 @@ class GitStoryid
11
11
  end
12
12
 
13
13
  def initialize(*arguments)
14
+ @git_options = []
14
15
  parser = OptionParser.new do |opts|
15
16
  opts.banner = "Do git commit with information from pivotal story"
16
- opts.on("-m [MESSAGE]", "Add addional MESSAGE to comit") do |message|
17
- @message = message
17
+ opts.on("-m", "--message [MESSAGE]", "Add addional MESSAGE to comit") do |custom_message|
18
+ @custom_message = custom_message
18
19
  end
19
20
  end
20
21
  parser.parse!(arguments)
@@ -35,51 +36,83 @@ class GitStoryid
35
36
  end
36
37
 
37
38
  def readline_stories_if_not_present
38
- return if @stories
39
+ if !@stories || @stories.empty?
40
+ quit_if_no_stories
41
+ output stories_menu
42
+ @stories = readline_story_ids.map do |index|
43
+ all_stories[index - 1] || (quit("Story index #{index} not found."))
44
+ end
45
+ end
46
+ end
47
+
48
+ def output(message)
49
+ puts message
50
+ end
51
+
52
+ def quit_if_no_stories
39
53
  if all_stories.empty?
40
54
  quit "No stories started and owned by you."
41
55
  end
56
+ end
57
+
58
+ def stories_menu
59
+ result = ""
42
60
  all_stories.each_with_index do |story, index|
43
- puts "[#{index + 1}] #{story.name}"
61
+ result << "[#{index + 1}] #{story.name}\n"
44
62
  end
45
- puts ""
46
- @stories = Readline.readline("Indexes(csv): ", true).split(/\s*,\s*/).reject do |string|
63
+ result << "\n"
64
+ result
65
+ end
66
+
67
+ def readline_story_ids
68
+ Readline.readline("Indexes(csv): ", true).split(/\s*,\s*/).reject do |string|
47
69
  string == ""
48
- end.map do |string|
49
- index = string.to_i
50
- all_stories[index - 1] || (quit("Story index #{index} not found."))
51
- end
70
+ end.map {|id| id.to_i }
52
71
  end
53
72
 
54
73
  def quit(message)
55
- puts message
74
+ output message
56
75
  exit 1
57
76
  end
58
77
 
59
78
  def run
60
- if execute("git", "diff", "--staged").empty?
61
- quit "No changes staged to commit."
62
- end
63
-
79
+ ensure_changes_stashed!
64
80
  readline_stories_if_not_present
81
+ commit_changes
82
+ end
65
83
 
84
+ def commit_changes
85
+ output execute("git", "commit", "-m", build_commit_message)
86
+ end
87
+
88
+ def build_commit_message
66
89
  message = ("[#{@stories.map { |s| "\##{s.id}"}.join(", ")}]").rjust 12
67
90
  message += ' '
68
- if @message && !@message.empty?
69
- message += @message.to_s + "\n\n"
91
+ if @custom_message && !@custom_message.empty?
92
+ message += @custom_message.to_s + "\n\n"
70
93
  end
71
- message += @stories.map {|s| "Feature: " + s.name.strip}.join("\n\n")
72
- puts execute("git", "commit", "-m", message)
94
+ message += @stories.map {|s| "#{s.story_type.capitalize}: " + s.name.strip}.join("\n\n")
95
+ message
73
96
  end
74
97
 
75
98
  def execute(*args)
76
99
  Open3.popen3(*args) {|i, o| return o.read }
77
100
  end
78
101
 
102
+ def ensure_changes_stashed!
103
+ if execute("git", "diff", "--staged").empty?
104
+ quit "No changes staged to commit."
105
+ end
106
+ end
79
107
 
80
108
 
81
109
  module Configuration
82
110
  class << self
111
+
112
+ def config=(config)
113
+ @config = config
114
+ end
115
+
83
116
  def read
84
117
  return if @loaded
85
118
  load_config
@@ -89,7 +122,8 @@ class GitStoryid
89
122
  end
90
123
 
91
124
  def load_config
92
- @config = load_config_from(global_config_path)
125
+ @config ||= {}
126
+ @config.merge!(load_config_from(global_config_path))
93
127
  @project_config = load_config_from(project_config_path)
94
128
  @config.merge!(@project_config)
95
129
  end
@@ -118,7 +152,7 @@ class GitStoryid
118
152
  file.write YAML.dump(@project_config)
119
153
  end
120
154
  @config.merge!(@project_config)
121
- puts "Writing config to .pivotalrc"
155
+ output "Writing config to .pivotalrc"
122
156
  end
123
157
  end
124
158
 
@@ -3,12 +3,107 @@ require "fileutils"
3
3
 
4
4
  describe GitStoryid do
5
5
 
6
+ let(:commands) { []}
7
+
8
+ def run(*args)
9
+ GitStoryid.run(*args)
10
+ end
11
+
6
12
  before(:each) do
7
- FileUtils.rm_rf("spec/repo")
8
- FileUtils.mkdir_p("spec/repo")
9
- FileUtils.cd("spec/repo")
10
- `git init`
13
+ GitStoryid::Configuration.config = {
14
+ "api_token" => "a2b4e",
15
+ "use_ssl" => false,
16
+ "me" => "BG",
17
+ "project_id" => "1234"
18
+ }
19
+ commands = self.commands
20
+ GitStoryid.send(:define_method, :execute) do |*args|
21
+ commands << args
22
+ ""
23
+ end
24
+
25
+ GitStoryid.any_instance.stubs(:ensure_changes_stashed!).returns(true)
26
+ GitStoryid.any_instance.stubs(:readline_story_ids).returns([1])
27
+ GitStoryid.any_instance.stubs(:output).returns(true)
28
+
29
+ GitStoryid::Configuration.stubs(:project).returns(Hashie::Mash.new(
30
+ :initial_velocity => 10,
31
+ :labels => "bonobos,true&co,website",
32
+ :id => 135657,
33
+ :week_start_day => "Monday",
34
+ :use_https => false,
35
+ :iteration_length => 1,
36
+ :account => "Allan Grant",
37
+ :name => "Curebit Marketing",
38
+ :stories => PivotalTracker::Story,
39
+ :last_activity_at => DateTime.now,
40
+ :velocity_scheme => "Average of 3 iterations",
41
+ :current_iteration_number => 122,
42
+ :current_velocity => 19,
43
+ :point_scale => "0,1,2,3",
44
+ :first_iteration_start_time => DateTime.now
45
+ ))
46
+
47
+ GitStoryid.any_instance.stubs(:all_stories).returns([
48
+ Hashie::Mash.new(
49
+ :deadline => nil,
50
+ :labels => "paypal",
51
+ :accepted_at => nil,
52
+ :id => 44647731,
53
+ :jira_id => nil,
54
+ :estimate => 1,
55
+ :integration_id => nil,
56
+ :owned_by => "Bogdan Gusiev",
57
+ :name => "Strip Default paypal credentials",
58
+ :created_at => DateTime.now,
59
+ :story_type => "feature",
60
+ :other_id => nil,
61
+ :description => "",
62
+ :requested_by => "Dominic Coryell",
63
+ :url => "http://www.pivotaltracker.com/story/show/44647731",
64
+ :attachments => [],
65
+ :project_id => 135657,
66
+ :jira_url => nil,
67
+ :current_state => "finished",
68
+ ),
69
+ Hashie::Mash.new(
70
+ :deadline => nil,
71
+ :labels => "paypal",
72
+ :accepted_at => nil,
73
+ :id => 44647732,
74
+ :jira_id => nil,
75
+ :estimate => 1,
76
+ :integration_id => nil,
77
+ :owned_by => "Bogdan Gusiev",
78
+ :name => "Require pro paypal account for mass payments",
79
+ :created_at => DateTime.now,
80
+ :story_type => "feature",
81
+ :other_id => nil,
82
+ :description => "",
83
+ :requested_by => "Dominic Coryell",
84
+ :url => "http://www.pivotaltracker.com/story/show/44647732",
85
+ :attachments => [],
86
+ :project_id => 135657,
87
+ :jira_url => nil,
88
+ :current_state => "finished"
89
+ )
90
+ ])
11
91
  end
12
92
 
93
+ it "should commit changes" do
94
+ run("-m", 'Hello world')
95
+ commands.should include(["git", "commit", "-m", " [#44647731] Hello world\n\nFeature: Strip Default paypal credentials"])
96
+ end
97
+
98
+ it "should render stories menu correctly" do
99
+ subject.stories_menu.should == <<-EOI
100
+ [1] Strip Default paypal credentials
101
+ [2] Require pro paypal account for mass payments
102
+
103
+ EOI
104
+ end
105
+
106
+
107
+
13
108
 
14
109
  end
@@ -1,12 +1,17 @@
1
1
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
3
  require 'rspec'
4
+ require "webmock"
5
+ require "hashie"
4
6
  require 'git-storyid'
5
7
 
6
8
  # Requires supporting files with custom matchers and macros, etc,
7
9
  # in ./support/ and its subdirectories.
8
10
  Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
11
 
12
+ WebMock.disable_net_connect!
13
+
10
14
  RSpec.configure do |config|
15
+ config.mock_with :mocha
11
16
 
12
17
  end
metadata CHANGED
@@ -1,79 +1,137 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: git-storyid
3
- version: !ruby/object:Gem::Version
4
- hash: 21
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 2
9
- - 1
10
- version: 0.2.1
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Bogdan Gusiev
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2013-02-19 00:00:00 +02:00
19
- default_executable: git-storyid
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- requirement: &id001 !ruby/object:Gem::Requirement
23
- none: false
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- hash: 3
28
- segments:
29
- - 0
30
- version: "0"
31
- version_requirements: *id001
32
- prerelease: false
12
+ date: 2013-03-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
33
15
  name: pivotal-tracker
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
34
22
  type: :runtime
35
- - !ruby/object:Gem::Dependency
36
- requirement: &id002 !ruby/object:Gem::Requirement
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
37
25
  none: false
38
- requirements:
39
- - - ~>
40
- - !ruby/object:Gem::Version
41
- hash: 47
42
- segments:
43
- - 2
44
- - 8
45
- - 0
46
- version: 2.8.0
47
- version_requirements: *id002
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: webmock
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: debugger
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: mocha
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :development
48
71
  prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
49
79
  name: rspec
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
50
86
  type: :development
51
- - !ruby/object:Gem::Dependency
52
- requirement: &id003 !ruby/object:Gem::Requirement
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
53
89
  none: false
54
- requirements:
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: jeweler
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
55
99
  - - ~>
56
- - !ruby/object:Gem::Version
57
- hash: 49
58
- segments:
59
- - 1
60
- - 8
61
- - 3
100
+ - !ruby/object:Gem::Version
62
101
  version: 1.8.3
63
- version_requirements: *id003
102
+ type: :development
64
103
  prerelease: false
65
- name: jeweler
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 1.8.3
110
+ - !ruby/object:Gem::Dependency
111
+ name: hashie
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
66
118
  type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
67
126
  description: Helps include pivotal story id and description in commit
68
127
  email: agresso@gmail.com
69
- executables:
128
+ executables:
70
129
  - git-storyid
71
130
  extensions: []
72
-
73
- extra_rdoc_files:
131
+ extra_rdoc_files:
74
132
  - LICENSE.txt
75
133
  - README.md
76
- files:
134
+ files:
77
135
  - .document
78
136
  - .rspec
79
137
  - Gemfile
@@ -88,39 +146,32 @@ files:
88
146
  - lib/git_storyid.rb
89
147
  - spec/git_storyid_spec.rb
90
148
  - spec/spec_helper.rb
91
- has_rdoc: true
92
149
  homepage: http://github.com/bogdan/git-storyid
93
- licenses:
150
+ licenses:
94
151
  - MIT
95
152
  post_install_message:
96
153
  rdoc_options: []
97
-
98
- require_paths:
154
+ require_paths:
99
155
  - lib
100
- required_ruby_version: !ruby/object:Gem::Requirement
156
+ required_ruby_version: !ruby/object:Gem::Requirement
101
157
  none: false
102
- requirements:
103
- - - ">="
104
- - !ruby/object:Gem::Version
105
- hash: 3
106
- segments:
158
+ requirements:
159
+ - - ! '>='
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ segments:
107
163
  - 0
108
- version: "0"
109
- required_rubygems_version: !ruby/object:Gem::Requirement
164
+ hash: 596398730235191081
165
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
166
  none: false
111
- requirements:
112
- - - ">="
113
- - !ruby/object:Gem::Version
114
- hash: 3
115
- segments:
116
- - 0
117
- version: "0"
167
+ requirements:
168
+ - - ! '>='
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
118
171
  requirements: []
119
-
120
172
  rubyforge_project:
121
- rubygems_version: 1.6.0
173
+ rubygems_version: 1.8.24
122
174
  signing_key:
123
175
  specification_version: 3
124
176
  summary: Attach commits to pivotal stories
125
177
  test_files: []
126
-