github-pivotal-flow 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,167 @@
1
+ require 'spec_helper'
2
+
3
+ module GithubPivotalFlow
4
+ describe Git do
5
+
6
+ before do
7
+ $stdout = StringIO.new
8
+ $stderr = StringIO.new
9
+ end
10
+
11
+ it 'should return the current branch name' do
12
+ Shell.should_receive(:exec).with('git branch', true).and_return(" master\n * dev_branch")
13
+
14
+ current_branch = Git.current_branch
15
+
16
+ expect(current_branch).to eq('dev_branch')
17
+ end
18
+
19
+ it 'should return the repository root' do
20
+ Dir.mktmpdir do |root|
21
+ child_directory = File.expand_path 'child', root
22
+ Dir.mkdir child_directory
23
+
24
+ git_directory = File.expand_path '.git', root
25
+ Dir.mkdir git_directory
26
+
27
+ Dir.should_receive(:pwd).and_return(child_directory)
28
+
29
+ repository_root = Git.repository_root
30
+
31
+ expect(repository_root).to eq(root)
32
+ end
33
+ end
34
+
35
+ it 'should raise an error there is no repository root' do
36
+ Dir.mktmpdir do |root|
37
+ child_directory = File.expand_path 'child', root
38
+ Dir.mkdir child_directory
39
+
40
+ Dir.should_receive(:pwd).and_return(child_directory)
41
+
42
+ expect { Git.repository_root }.to raise_error
43
+ end
44
+ end
45
+
46
+ it 'should get configuration when :branch scope is specified' do
47
+ Git.should_receive(:current_branch).and_return('test_branch_name')
48
+ Shell.should_receive(:exec).with('git config branch.test_branch_name.test_key', false).and_return('test_value')
49
+
50
+ value = Git.get_config 'test_key', :branch
51
+
52
+ expect(value).to eq('test_value')
53
+ end
54
+
55
+ it 'should get configuration when :inherited scope is specified' do
56
+ Shell.should_receive(:exec).with('git config test_key', false).and_return('test_value')
57
+
58
+ value = Git.get_config 'test_key', :inherited
59
+
60
+ expect(value).to eq('test_value')
61
+ end
62
+
63
+ it 'should raise an error when an unknown scope is specified (get)' do
64
+ expect { Git.get_config 'test_key', :unknown }.to raise_error
65
+ end
66
+
67
+ it 'should set configuration when :branch scope is specified' do
68
+ Git.should_receive(:current_branch).and_return('test_branch_name')
69
+ Shell.should_receive(:exec).with('git config --local branch.test_branch_name.test_key test_value', true)
70
+
71
+ Git.set_config 'test_key', 'test_value', :branch
72
+ end
73
+
74
+ it 'should set configuration when :global scope is specified' do
75
+ Shell.should_receive(:exec).with('git config --global test_key test_value', true)
76
+
77
+ Git.set_config 'test_key', 'test_value', :global
78
+ end
79
+
80
+ it 'should set configuration when :local scope is specified' do
81
+ Shell.should_receive(:exec).with('git config --local test_key test_value', true)
82
+
83
+ Git.set_config 'test_key', 'test_value', :local
84
+ end
85
+
86
+ it 'should raise an error when an unknown scope is specified (set)' do
87
+ expect { Git.set_config 'test_key', 'test_value', :unknown }.to raise_error
88
+ end
89
+
90
+ it 'should create a branch and set the root_branch and root_remote properties on it' do
91
+ Git.stub(:current_branch).and_return('master')
92
+ Shell.should_receive(:exec).with('git branch --quiet dev_branch', true)
93
+
94
+ Git.create_branch 'dev_branch'
95
+ end
96
+
97
+ it 'should not add a hook if it already exists' do
98
+ Dir.mktmpdir do |root|
99
+ Git.should_receive(:repository_root).and_return(root)
100
+ hook = "#{root}/.git/hooks/prepare-commit-msg"
101
+ File.should_receive(:exist?).with(hook).and_return(true)
102
+
103
+ Git.add_hook 'prepare-commit-msg', __FILE__
104
+
105
+ File.should_receive(:exist?).and_call_original
106
+ expect(File.exist?(hook)).to be_false
107
+ end
108
+ end
109
+
110
+ it 'should add a hook if it does not exist' do
111
+ Dir.mktmpdir do |root|
112
+ Git.should_receive(:repository_root).and_return(root)
113
+ hook = "#{root}/.git/hooks/prepare-commit-msg"
114
+ File.should_receive(:exist?).with(hook).and_return(false)
115
+
116
+ Git.add_hook 'prepare-commit-msg', __FILE__
117
+
118
+ File.should_receive(:exist?).and_call_original
119
+ expect(File.exist?(hook)).to be_true
120
+ end
121
+ end
122
+
123
+ it 'should add a hook if it already exists and overwrite is true' do
124
+ Dir.mktmpdir do |root|
125
+ Git.should_receive(:repository_root).and_return(root)
126
+ hook = "#{root}/.git/hooks/prepare-commit-msg"
127
+
128
+ Git.add_hook 'prepare-commit-msg', __FILE__, true
129
+
130
+ File.should_receive(:exist?).and_call_original
131
+ expect(File.exist?(hook)).to be_true
132
+ end
133
+ end
134
+
135
+ it 'should merge and delete branches' do
136
+ Shell.should_receive(:exec).with("git merge --quiet --no-ff -m \"Merge development_branch to master\" development_branch", true)
137
+
138
+ Git.merge 'development_branch', commit_message: 'Merge development_branch to master', no_ff: true
139
+ end
140
+
141
+ it 'should push changes without refs' do
142
+ Git.should_receive(:get_config).with('remote', :branch).and_return('origin')
143
+ Shell.should_receive(:exec).with('git push --quiet origin ', true)
144
+
145
+ Git.push
146
+ end
147
+
148
+ it 'should push changes with refs' do
149
+ Git.should_receive(:get_config).with('remote', :branch).and_return('origin')
150
+ Shell.should_receive(:exec).with('git push --quiet origin foo bar', true)
151
+
152
+ Git.push 'foo', 'bar'
153
+ end
154
+
155
+ it 'should create a commit' do
156
+ Shell.should_receive(:exec).with("git commit --quiet --allow-empty -m \"test_message\"", true)
157
+
158
+ Git.commit commit_message: 'test_message', allow_empty: true
159
+ end
160
+
161
+ it 'should create a tag' do
162
+ Shell.should_receive(:exec).with('git tag 1.0.0.RELEASE', true)
163
+
164
+ Git.tag '1.0.0.RELEASE'
165
+ end
166
+ end
167
+ end
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ module GithubPivotalFlow
4
+ describe Shell do
5
+
6
+ before do
7
+ $stdout = StringIO.new
8
+ $stderr = StringIO.new
9
+ end
10
+
11
+ it 'should return result when exit code is 0' do
12
+ Shell.should_receive(:`).with('test_command').and_return('test_result')
13
+ $?.should_receive(:exitstatus).and_return(0)
14
+
15
+ result = Shell.exec 'test_command'
16
+
17
+ expect(result).to eq('test_result')
18
+ end
19
+
20
+ it "should abort with 'FAIL' when the exit code is not 0" do
21
+ Shell.should_receive(:`).with('test_command')
22
+ $?.should_receive(:exitstatus).and_return(-1)
23
+
24
+ lambda { Shell.exec 'test_command' }.should raise_error(SystemExit)
25
+
26
+ expect($stderr.string).to match(/FAIL/)
27
+ end
28
+
29
+ it 'should return result when the exit code is not 0 and told not to abort on failure' do
30
+ Shell.should_receive(:`).with('test_command')
31
+ $?.should_receive(:exitstatus).and_return(-1)
32
+
33
+ Shell.exec 'test_command', false
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ module GithubPivotalFlow
4
+ describe Start do
5
+ before do
6
+ $stdout = StringIO.new
7
+ $stderr = StringIO.new
8
+
9
+ @project = double('project')
10
+ @story = double('story')
11
+ @ghclient = double('ghclient')
12
+ Git.should_receive(:repository_root)
13
+ GitHubAPI.should_receive(:new).and_return(@ghclient)
14
+ Configuration.any_instance.should_receive(:api_token)
15
+ Configuration.any_instance.should_receive(:project_id)
16
+ PivotalTracker::Project.should_receive(:find).and_return(@project)
17
+ @start = Start.new()
18
+ end
19
+
20
+ it 'should run' do
21
+ @start.options[:args] = 'test_filter'
22
+ @story.stub(:unestimated? => false, :release? => false)
23
+ Story.should_receive(:select_story).with(@project, 'test_filter').and_return(@story)
24
+ Story.should_receive(:pretty_print)
25
+ @story.should_receive(:create_branch!)
26
+ Configuration.any_instance.should_receive(:story=)
27
+ Git.should_receive(:add_hook)
28
+ @story.should_receive(:params_for_pull_request).and_return({})
29
+ @ghclient.should_receive(:create_pullrequest)
30
+ @story.should_receive(:mark_started!)
31
+
32
+ @start.run!
33
+ end
34
+
35
+ describe "create_branch" do
36
+ pending
37
+ #Git.should_receive(:get_config).with('user.name').and_return('test_owner')
38
+
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,125 @@
1
+ require 'spec_helper'
2
+
3
+ module GithubPivotalFlow
4
+ describe Story do
5
+
6
+ before do
7
+ $stdout = StringIO.new
8
+ $stderr = StringIO.new
9
+
10
+ @project = double('project')
11
+ @stories = double('stories')
12
+ @story = double('story')
13
+ @menu = double('menu')
14
+ end
15
+
16
+ it 'should pretty print story information' do
17
+ story = double('story')
18
+ story.should_receive(:name)
19
+ story.should_receive(:description).and_return("description-1\ndescription-2")
20
+ PivotalTracker::Note.should_receive(:all).and_return([
21
+ PivotalTracker::Note.new(:noted_at => Date.new, :text => 'note-1')
22
+ ])
23
+
24
+ Story.pretty_print story
25
+
26
+ expect($stdout.string).to eq(
27
+ " Title: \n" +
28
+ "Description: description-1\n" +
29
+ " description-2\n" +
30
+ " Note 1: note-1\n" +
31
+ "\n")
32
+ end
33
+
34
+ it 'should not pretty print description or notes if there are none (empty)' do
35
+ story = double('story')
36
+ story.should_receive(:name)
37
+ story.should_receive(:description)
38
+ PivotalTracker::Note.should_receive(:all).and_return([])
39
+
40
+ Story.pretty_print story
41
+
42
+ expect($stdout.string).to eq(
43
+ " Title: \n" +
44
+ "\n")
45
+ end
46
+
47
+ it 'should not pretty print description or notes if there are none (nil)' do
48
+ story = double('story')
49
+ story.should_receive(:name)
50
+ story.should_receive(:description).and_return('')
51
+ PivotalTracker::Note.should_receive(:all).and_return([])
52
+
53
+ Story.pretty_print story
54
+
55
+ expect($stdout.string).to eq(
56
+ " Title: \n" +
57
+ "\n")
58
+ end
59
+
60
+ it 'should select a story directly if the filter is a number' do
61
+ @project.should_receive(:stories).and_return(@stories)
62
+ @stories.should_receive(:find).with(12345678).and_return(@story)
63
+
64
+ story = Story.select_story @project, '12345678'
65
+
66
+ expect(story).to be_a(Story)
67
+ expect(story.story).to be(@story)
68
+ end
69
+
70
+ it 'should select a story if the result of the query is a single story' do
71
+ @project.should_receive(:stories).and_return(@stories)
72
+ @stories.should_receive(:all).with(
73
+ :current_state => %w(rejected unstarted unscheduled),
74
+ :limit => 1,
75
+ :story_type => 'release'
76
+ ).and_return([@story])
77
+
78
+ story = Story.select_story @project, 'release', 1
79
+
80
+ expect(story).to be_a(Story)
81
+ expect(story.story).to be(@story)
82
+ end
83
+
84
+ it 'should prompt the user for a story if the result of the query is more than a single story' do
85
+ @project.should_receive(:stories).and_return(@stories)
86
+ @stories.should_receive(:all).with(
87
+ :current_state => %w(rejected unstarted unscheduled),
88
+ :limit => 5,
89
+ :story_type => 'feature'
90
+ ).and_return([
91
+ PivotalTracker::Story.new(:name => 'name-1'),
92
+ PivotalTracker::Story.new(:name => 'name-2')
93
+ ])
94
+ @menu.should_receive(:prompt=)
95
+ @menu.should_receive(:choice).with('name-1')
96
+ @menu.should_receive(:choice).with('name-2')
97
+ Story.should_receive(:choose) { |&arg| arg.call @menu }.and_return(@story)
98
+
99
+ story = Story.select_story @project, 'feature'
100
+
101
+ expect(story).to be_a(Story)
102
+ expect(story.story).to be(@story)
103
+ end
104
+
105
+ it 'should prompt the user with the story type if no filter is specified' do
106
+ @project.should_receive(:stories).and_return(@stories)
107
+ @stories.should_receive(:all).with(
108
+ :current_state => %w(rejected unstarted unscheduled),
109
+ :limit => 5
110
+ ).and_return([
111
+ PivotalTracker::Story.new(:story_type => 'chore', :name => 'name-1'),
112
+ PivotalTracker::Story.new(:story_type => 'bug', :name => 'name-2')
113
+ ])
114
+ @menu.should_receive(:prompt=)
115
+ @menu.should_receive(:choice).with('CHORE name-1')
116
+ @menu.should_receive(:choice).with('BUG name-2')
117
+ Story.should_receive(:choose) { |&arg| arg.call @menu }.and_return(@story)
118
+
119
+ story = Story.select_story @project
120
+
121
+ expect(story).to be_a(Story)
122
+ expect(story.story).to be(@story)
123
+ end
124
+ end
125
+ end
metadata ADDED
@@ -0,0 +1,186 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: github-pivotal-flow
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Donald Piret
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-01-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: highline
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.6'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pivotal-tracker
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '0.5'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '0.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.3'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: redcarpet
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ~>
74
+ - !ruby/object:Gem::Version
75
+ version: '2.2'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ~>
81
+ - !ruby/object:Gem::Version
82
+ version: '2.2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ~>
88
+ - !ruby/object:Gem::Version
89
+ version: '2.13'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ~>
95
+ - !ruby/object:Gem::Version
96
+ version: '2.13'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ~>
102
+ - !ruby/object:Gem::Version
103
+ version: '0.7'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ~>
109
+ - !ruby/object:Gem::Version
110
+ version: '0.7'
111
+ - !ruby/object:Gem::Dependency
112
+ name: yard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ~>
116
+ - !ruby/object:Gem::Version
117
+ version: '0.8'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ~>
123
+ - !ruby/object:Gem::Version
124
+ version: '0.8'
125
+ description: Provides a set of additional Git commands to help developers when working
126
+ with Pivotal Tracker and Github pull requests
127
+ email: donald@donaldpiret.com
128
+ executables:
129
+ - git-finish
130
+ - git-start
131
+ extensions: []
132
+ extra_rdoc_files: []
133
+ files:
134
+ - LICENSE
135
+ - README.md
136
+ - lib/core_ext/object/blank.rb
137
+ - lib/github_pivotal_flow/command.rb
138
+ - lib/github_pivotal_flow/configuration.rb
139
+ - lib/github_pivotal_flow/finish.rb
140
+ - lib/github_pivotal_flow/git.rb
141
+ - lib/github_pivotal_flow/github_api.rb
142
+ - lib/github_pivotal_flow/project.rb
143
+ - lib/github_pivotal_flow/shell.rb
144
+ - lib/github_pivotal_flow/start.rb
145
+ - lib/github_pivotal_flow/story.rb
146
+ - lib/github_pivotal_flow.rb
147
+ - lib/github_pivotal_flow/prepare-commit-msg.sh
148
+ - bin/git-finish
149
+ - bin/git-start
150
+ - spec/github_pivotal_flow/configuration_spec.rb
151
+ - spec/github_pivotal_flow/finish_spec.rb
152
+ - spec/github_pivotal_flow/git_spec.rb
153
+ - spec/github_pivotal_flow/shell_spec.rb
154
+ - spec/github_pivotal_flow/start_spec.rb
155
+ - spec/github_pivotal_flow/story_spec.rb
156
+ homepage: https://github.com/roomorama/github-pivotal-flow
157
+ licenses:
158
+ - Apache 2.0
159
+ metadata: {}
160
+ post_install_message:
161
+ rdoc_options: []
162
+ require_paths:
163
+ - lib
164
+ required_ruby_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - '>='
167
+ - !ruby/object:Gem::Version
168
+ version: 1.8.7
169
+ required_rubygems_version: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ requirements: []
175
+ rubyforge_project:
176
+ rubygems_version: 2.0.14
177
+ signing_key:
178
+ specification_version: 4
179
+ summary: Git commands for integration with Pivotal Tracker and Github pull requests
180
+ test_files:
181
+ - spec/github_pivotal_flow/configuration_spec.rb
182
+ - spec/github_pivotal_flow/finish_spec.rb
183
+ - spec/github_pivotal_flow/git_spec.rb
184
+ - spec/github_pivotal_flow/shell_spec.rb
185
+ - spec/github_pivotal_flow/start_spec.rb
186
+ - spec/github_pivotal_flow/story_spec.rb