git-process 0.9.1.pre3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. data/.gitignore +16 -0
  2. data/.rspec +3 -0
  3. data/.travis.yml +4 -0
  4. data/Gemfile +22 -0
  5. data/Gemfile.lock +56 -0
  6. data/LICENSE +22 -0
  7. data/README.md +80 -0
  8. data/Rakefile +16 -0
  9. data/bin/git-new-fb +21 -0
  10. data/bin/git-pull-request +21 -0
  11. data/bin/git-sync +21 -0
  12. data/bin/git-to-master +21 -0
  13. data/git-process.gemspec +21 -0
  14. data/lib/git-process/abstract-error-builder.rb +46 -0
  15. data/lib/git-process/git-abstract-merge-error-builder.rb +115 -0
  16. data/lib/git-process/git-branch.rb +86 -0
  17. data/lib/git-process/git-branches.rb +53 -0
  18. data/lib/git-process/git-lib.rb +413 -0
  19. data/lib/git-process/git-merge-error.rb +31 -0
  20. data/lib/git-process/git-new-fb-options.rb +34 -0
  21. data/lib/git-process/git-process-error.rb +10 -0
  22. data/lib/git-process/git-process-options.rb +82 -0
  23. data/lib/git-process/git-process.rb +194 -0
  24. data/lib/git-process/git-pull-request-options.rb +42 -0
  25. data/lib/git-process/git-rebase-error.rb +31 -0
  26. data/lib/git-process/git-status.rb +72 -0
  27. data/lib/git-process/git-sync-options.rb +34 -0
  28. data/lib/git-process/git-to-master-options.rb +18 -0
  29. data/lib/git-process/github-client.rb +73 -0
  30. data/lib/git-process/github-service.rb +156 -0
  31. data/lib/git-process/parked-changes-error.rb +32 -0
  32. data/lib/git-process/pull-request.rb +38 -0
  33. data/lib/git-process/uncommitted-changes-error.rb +15 -0
  34. data/lib/git-process/version.rb +12 -0
  35. data/spec/FileHelpers.rb +18 -0
  36. data/spec/GitRepoHelper.rb +86 -0
  37. data/spec/git-abstract-merge-error-builder_spec.rb +113 -0
  38. data/spec/git-lib_spec.rb +118 -0
  39. data/spec/git-process_spec.rb +328 -0
  40. data/spec/git-status_spec.rb +101 -0
  41. data/spec/github-service_spec.rb +209 -0
  42. data/spec/pull-request_spec.rb +57 -0
  43. data/spec/spec_helper.rb +1 -0
  44. metadata +133 -0
@@ -0,0 +1,101 @@
1
+ require 'git-status'
2
+ require 'GitRepoHelper'
3
+
4
+ describe Git::GitStatus do
5
+
6
+ include GitRepoHelper
7
+
8
+ before(:each) do
9
+ create_files(['.gitignore'])
10
+ gitlib.commit('initial')
11
+ end
12
+
13
+
14
+ after(:each) do
15
+ rm_rf(@tmpdir)
16
+ end
17
+
18
+
19
+ it "should handle added files" do
20
+ create_files(['a', 'b', 'c'])
21
+
22
+ gitlib.status.added.should == ['a', 'b', 'c']
23
+ end
24
+
25
+
26
+ it "should handle a modification on both sides" do
27
+ change_file_and_commit('a', '')
28
+
29
+ gitlib.checkout('fb', :new_branch => 'master')
30
+ change_file_and_commit('a', 'hello')
31
+
32
+ gitlib.checkout('master')
33
+ change_file_and_commit('a', 'goodbye')
34
+
35
+ gitlib.merge('fb') rescue
36
+
37
+ status = gitlib.status
38
+ status.unmerged.should == ['a']
39
+ status.modified.should == ['a']
40
+ end
41
+
42
+
43
+ it "should handle an addition on both sides" do
44
+ gitlib.checkout('fb', :new_branch => 'master')
45
+ change_file_and_commit('a', 'hello')
46
+
47
+ gitlib.checkout('master')
48
+ change_file_and_commit('a', 'goodbye')
49
+
50
+ gitlib.merge('fb') rescue
51
+
52
+ status = gitlib.status
53
+ status.unmerged.should == ['a']
54
+ status.added.should == ['a']
55
+ end
56
+
57
+
58
+ it "should handle a merge deletion on fb" do
59
+ change_file_and_commit('a', '')
60
+
61
+ gitlib.checkout('fb', :new_branch => 'master')
62
+ gitlib.remove('a', :force => true)
63
+ gitlib.commit('removed a')
64
+
65
+ gitlib.checkout('master')
66
+ change_file_and_commit('a', 'goodbye')
67
+
68
+ gitlib.merge('fb') rescue
69
+
70
+ status = gitlib.status
71
+ status.unmerged.should == ['a']
72
+ status.deleted.should == ['a']
73
+ end
74
+
75
+
76
+ it "should handle a merge deletion on master" do
77
+ change_file_and_commit('a', '')
78
+
79
+ gitlib.checkout('fb', :new_branch => 'master')
80
+ change_file_and_commit('a', 'hello')
81
+
82
+ gitlib.checkout('master')
83
+ gitlib.remove('a', :force => true)
84
+ gitlib.commit('removed a')
85
+
86
+ gitlib.merge('fb') rescue
87
+
88
+ status = gitlib.status
89
+ status.unmerged.should == ['a']
90
+ status.deleted.should == ['a']
91
+ end
92
+
93
+
94
+ it "should return an empty result" do
95
+ gitlib.status.added.should == []
96
+ gitlib.status.deleted.should == []
97
+ gitlib.status.modified.should == []
98
+ gitlib.status.unmerged.should == []
99
+ end
100
+
101
+ end
@@ -0,0 +1,209 @@
1
+ require 'github-service'
2
+ require 'webmock/rspec'
3
+ require 'json'
4
+ require 'octokit'
5
+ require 'tempfile'
6
+ require 'rspec/mocks/methods'
7
+ require 'rspec/mocks/test_double'
8
+ require 'rspec/mocks/mock'
9
+
10
+
11
+ class GHS
12
+ include GitHubService
13
+
14
+ def initialize(user = nil, password = nil, site = nil)
15
+ @user = user
16
+ @password = password
17
+ @site = site
18
+
19
+ logger = RSpec::Mocks::Mock.new('logger')
20
+ logger.stub(:debug)
21
+ logger.stub(:info)
22
+
23
+ @lib = RSpec::Mocks::Mock.new('lib')
24
+ @lib.stub(:logger).and_return(logger)
25
+ end
26
+
27
+ def lib
28
+ @lib
29
+ end
30
+ end
31
+
32
+
33
+ describe GitHubService do
34
+
35
+ def test_token
36
+ 'hfgkdjfgksjhdfkls'
37
+ end
38
+
39
+
40
+ describe "create_authorization" do
41
+
42
+ def ghs
43
+ unless @ghs
44
+ @ghs = GHS.new('tu', 'dfsdf')
45
+ @ghs.lib.stub(:config).with('remote.origin.url').and_return('git@github.com:jdigger/git-process.git')
46
+ end
47
+ @ghs
48
+ end
49
+
50
+
51
+ it "should return an auth_token for a good request" do
52
+ ghs.lib.should_receive(:config).with('gitProcess.github.authToken', anything).once
53
+
54
+ stub_request(:post, /api.github.com\/authorizations/).
55
+ to_return(:status => 200, :body => JSON({:token => test_token}))
56
+
57
+ ghs.create_authorization().should == test_token
58
+ end
59
+
60
+
61
+ it "should 401 for bad password" do
62
+ stub_request(:post, /api.github.com\/authorizations/).
63
+ to_return(:status => 401)
64
+
65
+ lambda { ghs.create_authorization() }.should raise_error Octokit::Unauthorized
66
+ end
67
+
68
+ end
69
+
70
+
71
+ describe "auth_token" do
72
+
73
+ it "should get the token from config if it exists" do
74
+ ghs = GHS.new
75
+ ghs.lib.stub(:config).with('github.user').and_return('test_user')
76
+ ghs.lib.stub(:config).with('remote.origin.url').and_return('git@github.com:jdigger/git-process.git')
77
+ ghs.lib.stub(:config).with('gitProcess.github.authToken').and_return(test_token)
78
+
79
+ ghs.auth_token.should == test_token
80
+ end
81
+
82
+
83
+ it "should get the token from the server if it does not exist in config" do
84
+ ghs = GHS.new(nil, 'dfsdf')
85
+ ghs.lib.stub(:config).with('github.user').and_return('test_user')
86
+ ghs.lib.stub(:config).with('remote.origin.url').and_return('git@github.com:jdigger/git-process.git')
87
+ ghs.lib.stub(:config).with('gitProcess.github.authToken').and_return('')
88
+ ghs.lib.should_receive(:config).with('gitProcess.github.authToken', anything).once
89
+
90
+ stub_request(:post, /api.github.com\/authorizations/).
91
+ to_return(:status => 200, :body => JSON({:token => test_token}))
92
+
93
+ ghs.auth_token.should == test_token
94
+ end
95
+
96
+ end
97
+
98
+
99
+ describe "user" do
100
+
101
+ it "should get the value from config" do
102
+ ghs = GHS.new(nil, 'dfsdf')
103
+ ghs.lib.stub(:config).with('github.user').and_return('test_user')
104
+
105
+ ghs.user.should == 'test_user'
106
+ end
107
+
108
+
109
+ it "should prompt the user and store it in the config" do
110
+ ghs = GHS.new(nil, 'dfsdf')
111
+ ghs.lib.stub(:config).with('github.user').and_return('')
112
+ ghs.lib.stub(:config).with('github.user', anything).once
113
+
114
+ ghs.stub(:ask).with(/username/).and_return('test_user')
115
+ ghs.user.should == 'test_user'
116
+ end
117
+
118
+ end
119
+
120
+
121
+ describe "using GHE instead of GitHub.com" do
122
+
123
+ def ghs
124
+ @ghs ||= GHS.new('tu', 'dfsdf', nil)
125
+ end
126
+
127
+
128
+ it "should use the correct server and path for a non-GitHub.com site" do
129
+ ghs.lib.stub(:config).with('remote.origin.url').and_return('git@myco.com:jdigger/git-process.git')
130
+ ghs.lib.should_receive(:config).with('gitProcess.github.authToken', anything).once
131
+
132
+ stub_request(:post, /myco.com\/api\/v3\/authorizations/).
133
+ to_return(:status => 200, :body => JSON({:token => test_token}))
134
+
135
+ ghs.create_authorization().should == test_token
136
+ end
137
+
138
+
139
+ it "site should work for git@... ssh address" do
140
+ ghs.lib.stub(:config).with('remote.origin.url').and_return('git@myco.com:jdigger/git-process.git')
141
+
142
+ ghs.site.should == 'http://myco.com'
143
+ end
144
+
145
+
146
+ it "site should work for https address" do
147
+ ghs.lib.stub(:config).with('remote.origin.url').and_return('https://myco.com/jdigger/git-process.git')
148
+
149
+ ghs.site.should == 'https://myco.com'
150
+ end
151
+
152
+
153
+ it "site should work for http address" do
154
+ ghs.lib.stub(:config).with('remote.origin.url').and_return('http://jdigger@myco.com/jdigger/git-process.git')
155
+
156
+ ghs.site.should == 'http://myco.com'
157
+ end
158
+
159
+
160
+ it "site should work for git://myco.com/ address" do
161
+ ghs.lib.stub(:config).with('remote.origin.url').and_return('git://myco.com/jdigger/git-process.git')
162
+
163
+ ghs.site.should == 'http://myco.com'
164
+ end
165
+
166
+
167
+ it "site should raise an error if remote.origin.url not set" do
168
+ ghs.lib.stub(:config).with('remote.origin.url').and_return('')
169
+
170
+ lambda {ghs.site}.should raise_error GitHubService::NoRemoteRepository
171
+ end
172
+
173
+
174
+ it "site should not work for a garbase url address" do
175
+ ghs.lib.stub(:config).with('remote.origin.url').and_return('garbage')
176
+
177
+ lambda {ghs.site}.should raise_error URI::InvalidURIError
178
+ end
179
+
180
+
181
+ def in_tempfile(content, &block)
182
+ file = Tempfile.new('ssh_config')
183
+ file.puts content
184
+ file.flush
185
+
186
+ begin
187
+ block.call(file)
188
+ ensure
189
+ file.close
190
+ file.unlink
191
+ end
192
+ end
193
+
194
+
195
+ it "site should work for an ssh-configged url address" do
196
+ ghs.lib.stub(:config).with('remote.origin.url').and_return('mygithub:jdigger/git-process.git')
197
+
198
+ content = "\nHost mygithub\n"+
199
+ " User git\n"+
200
+ " HostName github.myco.com\n"
201
+
202
+ in_tempfile(content) do |file|
203
+ ghs.site(:ssh_config_file => file.path).should == 'http://github.myco.com'
204
+ end
205
+ end
206
+
207
+ end
208
+
209
+ end
@@ -0,0 +1,57 @@
1
+ require 'pull-request'
2
+ require 'webmock/rspec'
3
+ require 'json'
4
+ require 'octokit'
5
+ require 'tempfile'
6
+ require 'GitRepoHelper'
7
+
8
+
9
+ describe GitHub::PullRequest do
10
+ include GitRepoHelper
11
+
12
+ def lib
13
+ unless @lib
14
+ @lib = double('lib')
15
+ @lib.stub(:logger).and_return(logger)
16
+ end
17
+ @lib
18
+ end
19
+
20
+
21
+ def test_token
22
+ 'hfgkdjfgksjhdfkls'
23
+ end
24
+
25
+
26
+ def pull_request
27
+ @pr ||= GitHub::PullRequest.new(lib, 'test_repo', :user => 'test_user')
28
+ end
29
+
30
+
31
+ before(:each) do
32
+ lib.stub(:config).with('gitProcess.github.authToken').and_return(test_token)
33
+ lib.stub(:config).with('remote.origin.url').and_return('git@github.com:jdigger/git-process.git')
34
+ end
35
+
36
+
37
+ it "should return a pull request for a good request" do
38
+ stub_request(:post, "https://api.github.com/repos/test_repo/pulls?access_token=#{test_token}").
39
+ to_return(:status => 200, :body => JSON({:number => 1, :state => 'open'}))
40
+
41
+ pull_request.create('test_base', 'test_head', 'test title', 'test body')[:state].should == 'open'
42
+ end
43
+
44
+
45
+ it "should handle asking for a duplicate pull request" do
46
+ # trying to create the request should return "HTTP 422: Unprocessable Entity" because it already exists
47
+ stub_request(:post, "https://api.github.com/repos/test_repo/pulls?access_token=#{test_token}").
48
+ to_return(:status => 422)
49
+
50
+ # listing all existing pull requests should contain the current branch
51
+ stub_request(:get, /test_repo\/pulls\?access_token=/).
52
+ to_return(:status => 200, :body => JSON([{:html_url => 'test_url', :head => {:ref => 'test_head'}, :base => {:ref => 'test_base'}}]))
53
+
54
+ pull_request.create('test_base', 'test_head', 'test title', 'test body')[:html_url].should == 'test_url'
55
+ end
56
+
57
+ end
@@ -0,0 +1 @@
1
+ $LOAD_PATH.unshift File.join(File.dirname(__FILE__), '../lib/git-process')
metadata ADDED
@@ -0,0 +1,133 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: git-process
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: true
5
+ segments:
6
+ - 0
7
+ - 9
8
+ - 1
9
+ - pre
10
+ - 3
11
+ version: 0.9.1.pre3
12
+ platform: ruby
13
+ authors:
14
+ - Jim Moore
15
+ autorequire:
16
+ bindir: bin
17
+ cert_chain: []
18
+
19
+ date: 2012-07-02 00:00:00 -06:00
20
+ default_executable:
21
+ dependencies:
22
+ - !ruby/object:Gem::Dependency
23
+ type: :development
24
+ version_requirements: &id001 !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ segments:
29
+ - 0
30
+ version: "0"
31
+ name: rspec
32
+ requirement: *id001
33
+ prerelease: false
34
+ description: A set of scripts to make working with git easier and more consistent
35
+ email:
36
+ - moore.jim@gmail.com
37
+ executables:
38
+ - git-new-fb
39
+ - git-pull-request
40
+ - git-sync
41
+ - git-to-master
42
+ extensions: []
43
+
44
+ extra_rdoc_files: []
45
+
46
+ files:
47
+ - .gitignore
48
+ - .rspec
49
+ - .travis.yml
50
+ - Gemfile
51
+ - Gemfile.lock
52
+ - LICENSE
53
+ - README.md
54
+ - Rakefile
55
+ - bin/git-new-fb
56
+ - bin/git-pull-request
57
+ - bin/git-sync
58
+ - bin/git-to-master
59
+ - git-process.gemspec
60
+ - lib/git-process/abstract-error-builder.rb
61
+ - lib/git-process/git-abstract-merge-error-builder.rb
62
+ - lib/git-process/git-branch.rb
63
+ - lib/git-process/git-branches.rb
64
+ - lib/git-process/git-lib.rb
65
+ - lib/git-process/git-merge-error.rb
66
+ - lib/git-process/git-new-fb-options.rb
67
+ - lib/git-process/git-process-error.rb
68
+ - lib/git-process/git-process-options.rb
69
+ - lib/git-process/git-process.rb
70
+ - lib/git-process/git-pull-request-options.rb
71
+ - lib/git-process/git-rebase-error.rb
72
+ - lib/git-process/git-status.rb
73
+ - lib/git-process/git-sync-options.rb
74
+ - lib/git-process/git-to-master-options.rb
75
+ - lib/git-process/github-client.rb
76
+ - lib/git-process/github-service.rb
77
+ - lib/git-process/parked-changes-error.rb
78
+ - lib/git-process/pull-request.rb
79
+ - lib/git-process/uncommitted-changes-error.rb
80
+ - lib/git-process/version.rb
81
+ - spec/FileHelpers.rb
82
+ - spec/GitRepoHelper.rb
83
+ - spec/git-abstract-merge-error-builder_spec.rb
84
+ - spec/git-lib_spec.rb
85
+ - spec/git-process_spec.rb
86
+ - spec/git-status_spec.rb
87
+ - spec/github-service_spec.rb
88
+ - spec/pull-request_spec.rb
89
+ - spec/spec_helper.rb
90
+ has_rdoc: true
91
+ homepage: http://jdigger.github.com/git-process/
92
+ licenses: []
93
+
94
+ post_install_message:
95
+ rdoc_options: []
96
+
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ segments:
104
+ - 1
105
+ - 8
106
+ - 7
107
+ version: 1.8.7
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">"
111
+ - !ruby/object:Gem::Version
112
+ segments:
113
+ - 1
114
+ - 3
115
+ - 1
116
+ version: 1.3.1
117
+ requirements: []
118
+
119
+ rubyforge_project:
120
+ rubygems_version: 1.3.6
121
+ signing_key:
122
+ specification_version: 3
123
+ summary: A set of scripts for a good git process
124
+ test_files:
125
+ - spec/FileHelpers.rb
126
+ - spec/GitRepoHelper.rb
127
+ - spec/git-abstract-merge-error-builder_spec.rb
128
+ - spec/git-lib_spec.rb
129
+ - spec/git-process_spec.rb
130
+ - spec/git-status_spec.rb
131
+ - spec/github-service_spec.rb
132
+ - spec/pull-request_spec.rb
133
+ - spec/spec_helper.rb