socialcast-git-extensions 3.3 → 4.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,98 @@
1
+ require 'spec_helper'
2
+
3
+ describe Socialcast::Gitx::Github do
4
+ let(:test_class) do
5
+ Class.new do |k|
6
+ include Socialcast::Gitx::Github
7
+
8
+ def say(message); end
9
+ end
10
+ end
11
+ let(:said_messages) { [] }
12
+ before do
13
+ stub_const('TestClass', test_class)
14
+ allow_any_instance_of(TestClass).to receive(:'`') do |_instance, _cmd|
15
+ raise 'Unstubbed backticks detected'
16
+ end
17
+ allow_any_instance_of(TestClass).to receive(:say) do |_instance, message|
18
+ said_messages << message
19
+ end
20
+ end
21
+ let(:test_instance) { TestClass.new }
22
+ let(:branch) { 'my-branch' }
23
+ let(:base_branch) { 'master' }
24
+ let(:repo) { 'ownername/projectname' }
25
+
26
+ describe '#create_pull_request' do
27
+ subject { test_instance.send(:create_pull_request, branch, repo, body) }
28
+ let(:create_pr_payload) do
29
+ {
30
+ :title => branch,
31
+ :base => base_branch,
32
+ :head => branch,
33
+ :body => body
34
+ }
35
+ end
36
+ let(:dummy_pr_created_response) { { :dummy => :response } }
37
+ let(:body) { 'This is my pull request.' }
38
+ before do
39
+ allow(test_instance).to receive(:base_branch).and_return(base_branch)
40
+ expect(test_instance).to receive(:github_api_request).with('POST', 'repos/ownername/projectname/pulls', create_pr_payload.to_json).and_return(dummy_pr_created_response)
41
+ end
42
+ it { is_expected.to eq dummy_pr_created_response }
43
+ end
44
+
45
+ describe '#pull_requests_for_branch' do
46
+ subject { test_instance.send(:pull_requests_for_branch, repo, branch) }
47
+ let(:dummy_pr_list_response) { [{ :dummy => :response }] }
48
+ before do
49
+ expect(test_instance).to receive(:github_api_request).with('GET', 'repos/ownername/projectname/pulls?head=ownername:my-branch').and_return(dummy_pr_list_response)
50
+ end
51
+ it { is_expected.to eq dummy_pr_list_response }
52
+ end
53
+
54
+ describe '#current_pr_for_branch' do
55
+ subject(:current_pr) { test_instance.send(:current_pr_for_branch, repo, branch) }
56
+ let(:dummy_pr_one) { { :dummy => :pr1 } }
57
+ let(:dummy_pr_two) { { :dummy => :pr2 } }
58
+ before do
59
+ expect(test_instance).to receive(:pull_requests_for_branch).with(repo, branch).and_return(dummy_pr_list_response)
60
+ end
61
+ context 'when an empty pr list is returned' do
62
+ let(:dummy_pr_list_response) { [] }
63
+ it { is_expected.to be_nil }
64
+ end
65
+ context 'when a single pr is returned' do
66
+ let(:dummy_pr_list_response) { [dummy_pr_one] }
67
+ it { is_expected.to eq dummy_pr_one }
68
+ end
69
+ context 'when multiple prs are returned' do
70
+ let(:dummy_pr_list_response) { [dummy_pr_one, dummy_pr_two] }
71
+ it { expect { current_pr }.to raise_error 'Multiple (2) open PRs for my-branch found in ownername/projectname, unable to proceed' }
72
+ end
73
+ end
74
+
75
+ describe '#assign_pull_request' do
76
+ subject { test_instance.send(:assign_pull_request, assignee, issue_url) }
77
+ let(:assignee) { 'janedoe' }
78
+ let(:issue_url) { 'repos/ownername/projectname/issues/1' }
79
+ let(:dummy_assignment_response) { [{ :dummy => :response }] }
80
+ let(:assign_payload) { { :assignee => assignee } }
81
+ before do
82
+ expect(test_instance).to receive(:github_api_request).with('PATCH', 'repos/ownername/projectname/issues/1', assign_payload.to_json).and_return(dummy_assignment_response)
83
+ end
84
+ it { is_expected.to eq dummy_assignment_response }
85
+ end
86
+
87
+ describe '#comment_on_issue' do
88
+ subject { test_instance.send(:comment_on_issue, issue_url, comment_body) }
89
+ let(:issue_url) { 'repos/ownername/projectname/issues/1' }
90
+ let(:dummy_comment_response) { { :dummy => :response } }
91
+ let(:comment_payload) { { :body => comment_body } }
92
+ let(:comment_body) { 'Integrating into staging' }
93
+ before do
94
+ expect(test_instance).to receive(:github_api_request).with('POST', 'repos/ownername/projectname/issues/1/comments', comment_payload.to_json).and_return(dummy_comment_response)
95
+ end
96
+ it { is_expected.to eq dummy_comment_response }
97
+ end
98
+ end
@@ -4,7 +4,7 @@ require 'bundler/setup'
4
4
  require 'rspec/mocks'
5
5
  require 'webmock/rspec'
6
6
  require 'pry'
7
-
7
+ require 'byebug'
8
8
  require 'socialcast-git-extensions/cli'
9
9
 
10
10
  ENV['SCGITX_TEST'] = 'true'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: socialcast-git-extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: '3.3'
4
+ version: '4.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Socialcast
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-17 00:00:00.000000000 Z
11
+ date: 2016-02-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rugged
@@ -42,14 +42,14 @@ dependencies:
42
42
  name: activesupport
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '4.0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - "~>"
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '4.0'
55
55
  - !ruby/object:Gem::Dependency
@@ -136,13 +136,29 @@ dependencies:
136
136
  - - "~>"
137
137
  - !ruby/object:Gem::Version
138
138
  version: '1.21'
139
+ - !ruby/object:Gem::Dependency
140
+ name: byebug
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
139
153
  description: GIT it done!
140
154
  email:
141
155
  - developers@socialcast.com
142
156
  executables:
157
+ - git-assignpr
143
158
  - git-backportpr
144
159
  - git-branchdiff
145
160
  - git-cleanup
161
+ - git-createpr
146
162
  - git-findpr
147
163
  - git-integrate
148
164
  - git-nuke
@@ -166,9 +182,11 @@ files:
166
182
  - LICENSE
167
183
  - README.md
168
184
  - Rakefile
185
+ - bin/git-assignpr
169
186
  - bin/git-backportpr
170
187
  - bin/git-branchdiff
171
188
  - bin/git-cleanup
189
+ - bin/git-createpr
172
190
  - bin/git-findpr
173
191
  - bin/git-integrate
174
192
  - bin/git-nuke
@@ -191,6 +209,7 @@ files:
191
209
  - socialcast-git-extensions.gemspec
192
210
  - spec/cli_spec.rb
193
211
  - spec/git_spec.rb
212
+ - spec/github_spec.rb
194
213
  - spec/spec_helper.rb
195
214
  homepage: http://github.com/socialcast/socialcast-git-extensions
196
215
  licenses: []
@@ -218,4 +237,5 @@ summary: git extension scripts for socialcast workflow
218
237
  test_files:
219
238
  - spec/cli_spec.rb
220
239
  - spec/git_spec.rb
240
+ - spec/github_spec.rb
221
241
  - spec/spec_helper.rb