git_reflow 0.8.4 → 0.8.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Appraisals +1 -1
- data/Gemfile.lock +17 -17
- data/git_reflow.gemspec +1 -1
- data/lib/git_reflow/config.rb +1 -1
- data/lib/git_reflow/git_helpers.rb +2 -2
- data/lib/git_reflow/git_server/bit_bucket/pull_request.rb +1 -1
- data/lib/git_reflow/git_server/git_hub/pull_request.rb +11 -10
- data/lib/git_reflow/git_server/pull_request.rb +18 -4
- data/lib/git_reflow/rspec/command_line_helpers.rb +9 -9
- data/lib/git_reflow/version.rb +1 -1
- data/lib/git_reflow/workflow.rb +6 -1
- data/lib/git_reflow/workflows/core.rb +1 -3
- data/lib/git_reflow/workflows/flat_merge.rb +10 -0
- data/lib/git_reflow.rb +9 -1
- metadata +7 -70
- data/spec/fixtures/git/git_config +0 -7
- data/spec/fixtures/issues/comment.json.erb +0 -27
- data/spec/fixtures/issues/comments.json +0 -29
- data/spec/fixtures/issues/comments.json.erb +0 -15
- data/spec/fixtures/pull_requests/comment.json.erb +0 -45
- data/spec/fixtures/pull_requests/comments.json +0 -47
- data/spec/fixtures/pull_requests/comments.json.erb +0 -15
- data/spec/fixtures/pull_requests/commits.json +0 -29
- data/spec/fixtures/pull_requests/external_pull_request.json +0 -145
- data/spec/fixtures/pull_requests/pull_request.json +0 -142
- data/spec/fixtures/pull_requests/pull_request.json.erb +0 -142
- data/spec/fixtures/pull_requests/pull_request_exists_error.json +0 -32
- data/spec/fixtures/pull_requests/pull_requests.json +0 -136
- data/spec/fixtures/repositories/commit.json +0 -53
- data/spec/fixtures/repositories/commit.json.erb +0 -53
- data/spec/fixtures/repositories/commits.json.erb +0 -13
- data/spec/fixtures/repositories/statuses.json +0 -31
- data/spec/lib/git_reflow/config_spec.rb +0 -74
- data/spec/lib/git_reflow/git_helpers_spec.rb +0 -182
- data/spec/lib/git_reflow/git_server_spec.rb +0 -101
- data/spec/lib/git_reflow/workflow_spec.rb +0 -56
- data/spec/lib/git_reflow/workflows/core_spec.rb +0 -665
- data/spec/lib/git_reflow_spec.rb +0 -39
- data/spec/lib/git_server/bit_bucket_spec.rb +0 -81
- data/spec/lib/git_server/git_hub/pull_request_spec.rb +0 -472
- data/spec/lib/git_server/git_hub_spec.rb +0 -221
- data/spec/lib/git_server/pull_request_spec.rb +0 -583
- data/spec/spec_helper.rb +0 -38
- data/spec/support/fake_github.rb +0 -128
- data/spec/support/fixtures.rb +0 -54
- data/spec/support/github_helpers.rb +0 -109
- data/spec/support/web_mocks.rb +0 -39
data/spec/lib/git_reflow_spec.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe GitReflow do
|
4
|
-
|
5
|
-
describe ".default_editor" do
|
6
|
-
subject { GitReflow.default_editor }
|
7
|
-
|
8
|
-
context "when the environment has EDITOR set" do
|
9
|
-
before { allow(ENV).to receive(:[]).with('EDITOR').and_return('emacs') }
|
10
|
-
specify { expect( subject ).to eql('emacs') }
|
11
|
-
end
|
12
|
-
|
13
|
-
context "when the environment has no EDITOR set" do
|
14
|
-
before { allow(ENV).to receive(:[]).with('EDITOR').and_return(nil) }
|
15
|
-
specify { expect( subject ).to eql('vi') }
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe ".git_server" do
|
20
|
-
subject { GitReflow.git_server }
|
21
|
-
|
22
|
-
before do
|
23
|
-
allow(GitReflow::Config).to receive(:get).with('reflow.git-server').and_return('GitHub ')
|
24
|
-
end
|
25
|
-
|
26
|
-
it "attempts to connect to the provider" do
|
27
|
-
expect(GitReflow::GitServer).to receive(:connect).with(provider: 'GitHub', silent: true)
|
28
|
-
subject
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
context "aliases workflow commands" do
|
33
|
-
%w{deliver refresh review setup stage start status}.each do |command|
|
34
|
-
it "aliases the command to the workflow" do
|
35
|
-
expect( subject.respond_to?(command.to_sym) ).to be_truthy
|
36
|
-
end
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
@@ -1,81 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe GitReflow::GitServer::BitBucket do
|
4
|
-
let(:user) { 'reenhanced' }
|
5
|
-
let(:password) { 'shazam' }
|
6
|
-
let(:repo) { 'repo' }
|
7
|
-
let(:api_key) { 'a1b2c3d4e5f6g7h8i9j0' }
|
8
|
-
let(:hostname) { 'hostname.local' }
|
9
|
-
let(:api_endpoint) { 'https://bitbucket.org/api/1.0' }
|
10
|
-
let(:site) { 'https://bitbucket.org' }
|
11
|
-
let(:remote_url) { "git@bitbucket.org:#{user}/#{repo}.git" }
|
12
|
-
|
13
|
-
before do
|
14
|
-
allow_any_instance_of(HighLine).to receive(:ask) do |terminal, question|
|
15
|
-
values = {
|
16
|
-
"Please enter your BitBucket username: " => user
|
17
|
-
}
|
18
|
-
return_value = values[question]
|
19
|
-
question = ""
|
20
|
-
return_value
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe '#initialize(options)' do
|
25
|
-
subject { GitReflow::GitServer::BitBucket.new({}) }
|
26
|
-
|
27
|
-
it 'sets the reflow git server provider to BitBucket in the git config' do
|
28
|
-
expect(GitReflow::Config).to receive(:set).once.with('reflow.git-server', 'BitBucket', local: false)
|
29
|
-
subject
|
30
|
-
end
|
31
|
-
|
32
|
-
context 'storing git config settings only for this project' do
|
33
|
-
subject { GitReflow::GitServer::BitBucket.new(project_only: true) }
|
34
|
-
|
35
|
-
it 'sets the enterprise site and api as the site and api endpoints for the BitBucket provider in the git config' do
|
36
|
-
expect(GitReflow::Config).to receive(:set).once.with('reflow.git-server', 'BitBucket', local: true)
|
37
|
-
subject
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
describe '#authenticate' do
|
44
|
-
let(:bitbucket) { GitReflow::GitServer::BitBucket.new( { }) }
|
45
|
-
let!(:bitbucket_api) { BitBucket.new }
|
46
|
-
subject { bitbucket.authenticate }
|
47
|
-
|
48
|
-
context 'already authenticated' do
|
49
|
-
it "notifies the user of successful setup" do
|
50
|
-
allow(GitReflow::Config).to receive(:set).with('reflow.git-server', 'BitBucket', local: false)
|
51
|
-
allow(GitReflow::Config).to receive(:get).with('remote.origin.url').and_return(remote_url)
|
52
|
-
allow(GitReflow::Config).to receive(:get).with('bitbucket.user', local: false).and_return(user)
|
53
|
-
allow(GitReflow::Config).to receive(:get).with('bitbucket.api-key', reload: true, local: false).and_return(api_key)
|
54
|
-
allow(GitReflow::Config).to receive(:get).with('reflow.local-projects', all: true).and_return('')
|
55
|
-
expect { subject }.to have_said "\nYour BitBucket account was already setup with:"
|
56
|
-
expect { subject }.to have_said "\tUser Name: #{user}"
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context 'not yet authenticated' do
|
61
|
-
context 'with valid BitBucket credentials' do
|
62
|
-
before do
|
63
|
-
allow(GitReflow::Config).to receive(:get).and_return('')
|
64
|
-
allow(GitReflow::Config).to receive(:set)
|
65
|
-
allow(GitReflow::Config).to receive(:set).with('bitbucket.api-key', reload: true).and_return(api_key)
|
66
|
-
allow(GitReflow::Config).to receive(:get).with('bitbucket.api-key', reload: true).and_return('')
|
67
|
-
allow(GitReflow::Config).to receive(:get).with('remote.origin.url').and_return(remote_url)
|
68
|
-
allow(GitReflow::Config).to receive(:get).with('reflow.local-projects').and_return('')
|
69
|
-
allow(bitbucket).to receive(:connection).and_return double(repos: double(all: []))
|
70
|
-
end
|
71
|
-
|
72
|
-
it "prompts me to setup an API key" do
|
73
|
-
expect { subject }.to have_said "\nIn order to connect your BitBucket account,"
|
74
|
-
expect { subject }.to have_said "you'll need to generate an API key for your team"
|
75
|
-
expect { subject }.to have_said "Visit https://bitbucket.org/account/user/reenhanced/api-key/, to generate it\n"
|
76
|
-
end
|
77
|
-
end
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
end
|
@@ -1,472 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe GitReflow::GitServer::GitHub::PullRequest do
|
4
|
-
let(:user) { 'reenhanced' }
|
5
|
-
let(:password) { 'shazam' }
|
6
|
-
let(:repo) { 'repo' }
|
7
|
-
let(:oauth_token_hash) { Hashie::Mash.new({ token: 'a1b2c3d4e5f6g7h8i9j0'}) }
|
8
|
-
let(:hostname) { 'hostname.local' }
|
9
|
-
let(:github_site) { 'https://github.com' }
|
10
|
-
let(:github_api_endpoint) { 'https://api.github.com' }
|
11
|
-
let(:enterprise_site) { 'https://github.gittyup.com' }
|
12
|
-
let(:enterprise_api) { 'https://github.gittyup.com/api/v3' }
|
13
|
-
let(:github) { stub_github_with }
|
14
|
-
let!(:github_api) { github.connection }
|
15
|
-
let(:existing_pull_request) { Fixture.new('pull_requests/external_pull_request.json').to_json_hashie }
|
16
|
-
let(:existing_pull_requests) { Fixture.new('pull_requests/pull_requests.json').to_json_hashie }
|
17
|
-
let(:existing_pull_commits) { Fixture.new('pull_requests/commits.json').to_json_hashie }
|
18
|
-
let(:comment_author) { 'octocat' }
|
19
|
-
let(:feature_branch_name) { existing_pull_request.head.label[/[^:]+$/] }
|
20
|
-
let(:base_branch_name) { existing_pull_request.base.label[/[^:]+$/] }
|
21
|
-
let(:existing_pull_comments) {
|
22
|
-
Fixture.new('pull_requests/comments.json.erb',
|
23
|
-
repo_owner: user,
|
24
|
-
repo_name: repo,
|
25
|
-
comments: [{author: comment_author}],
|
26
|
-
pull_request_number: existing_pull_request.number).to_json_hashie }
|
27
|
-
let(:existing_issue_comments) {
|
28
|
-
Fixture.new('issues/comments.json.erb',
|
29
|
-
repo_owner: user,
|
30
|
-
repo_name: repo,
|
31
|
-
comments: [{author: comment_author}],
|
32
|
-
pull_request_number: existing_pull_request.number).to_json_hashie }
|
33
|
-
|
34
|
-
subject { GitReflow::GitServer::GitHub::PullRequest.new(existing_pull_request) }
|
35
|
-
|
36
|
-
|
37
|
-
before do
|
38
|
-
stub_command_line_inputs({
|
39
|
-
"Please enter your GitHub username: " => user,
|
40
|
-
"Please enter your GitHub password (we do NOT store this): " => password,
|
41
|
-
"Please enter your Enterprise site URL (e.g. https://github.company.com):" => enterprise_site,
|
42
|
-
"Please enter your Enterprise API endpoint (e.g. https://github.company.com/api/v3):" => enterprise_api
|
43
|
-
})
|
44
|
-
|
45
|
-
allow(github.class).to receive(:remote_user).and_return(user)
|
46
|
-
allow(github.class).to receive(:remote_repo_name).and_return(repo)
|
47
|
-
allow(GitReflow::GitServer::PullRequest).to receive(:approval_regex).and_return(/(?i-mx:lgtm|looks good to me|:\+1:|:thumbsup:|:shipit:)/)
|
48
|
-
end
|
49
|
-
|
50
|
-
describe '#initialize(options)' do
|
51
|
-
specify { expect(subject.number).to eql(existing_pull_request.number) }
|
52
|
-
specify { expect(subject.description).to eql(existing_pull_request.body) }
|
53
|
-
specify { expect(subject.html_url).to eql(existing_pull_request.html_url) }
|
54
|
-
specify { expect(subject.feature_branch_name).to eql(feature_branch_name) }
|
55
|
-
specify { expect(subject.base_branch_name).to eql(base_branch_name) }
|
56
|
-
specify { expect(subject.build_status).to eql('success') }
|
57
|
-
specify { expect(subject.source_object).to eql(existing_pull_request) }
|
58
|
-
end
|
59
|
-
|
60
|
-
describe '#commit_author' do
|
61
|
-
before do
|
62
|
-
stub_request(:get, %r{#{GitReflow.git_server.class.api_endpoint}/repos/#{user}/#{repo}/pulls/#{existing_pull_request.number}/commits}).
|
63
|
-
with(query: {"access_token" => "a1b2c3d4e5f6g7h8i9j0"}).
|
64
|
-
to_return(:body => Fixture.new("pull_requests/commits.json").to_s, status: 201, headers: {content_type: "application/json; charset=utf-8"})
|
65
|
-
end
|
66
|
-
specify { expect(subject.commit_author).to eql("#{existing_pull_commits.first.commit.author.name} <#{existing_pull_commits.first.commit.author.email}>") }
|
67
|
-
end
|
68
|
-
|
69
|
-
describe '#comments' do
|
70
|
-
context "Testing Appending of Comments" do
|
71
|
-
before do
|
72
|
-
FakeGitHub.new(
|
73
|
-
repo_owner: user,
|
74
|
-
repo_name: repo,
|
75
|
-
pull_request: {
|
76
|
-
number: existing_pull_request.number,
|
77
|
-
comments: [{author: comment_author}]
|
78
|
-
},
|
79
|
-
issue: {
|
80
|
-
number: existing_pull_request.number,
|
81
|
-
comments: [{author: comment_author}]
|
82
|
-
})
|
83
|
-
end
|
84
|
-
specify { expect(subject.comments).to eql(existing_pull_comments.to_a + existing_issue_comments.to_a) }
|
85
|
-
end
|
86
|
-
|
87
|
-
context "Testing Nil Comments" do
|
88
|
-
before do
|
89
|
-
stub_request(:get, "https://api.github.com/repos/reenhanced/repo/pulls/2/comments?access_token=a1b2c3d4e5f6g7h8i9j0").
|
90
|
-
with(:headers => {'Accept'=>'application/vnd.github.v3+json,application/vnd.github.beta+json;q=0.5,application/json;q=0.1', 'Accept-Charset'=>'utf-8', 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', 'Authorization'=>'token a1b2c3d4e5f6g7h8i9j0', 'User-Agent'=>'Github API Ruby Gem 0.14.0'}).
|
91
|
-
to_return(:status => 200, :body => "", :headers => {})
|
92
|
-
|
93
|
-
FakeGitHub.new(
|
94
|
-
repo_owner: user,
|
95
|
-
repo_name: repo,
|
96
|
-
pull_request: {
|
97
|
-
number: existing_pull_request.number,
|
98
|
-
comments: nil
|
99
|
-
},
|
100
|
-
issue: {
|
101
|
-
number: existing_pull_request.number,
|
102
|
-
comments: nil
|
103
|
-
})
|
104
|
-
end
|
105
|
-
specify { expect(subject.comments).to eql([]) }
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
describe '#reviewers' do
|
110
|
-
before do
|
111
|
-
allow(existing_pull_request.user).to receive(:login).and_return('ringo')
|
112
|
-
|
113
|
-
FakeGitHub.new(
|
114
|
-
repo_owner: user,
|
115
|
-
repo_name: repo,
|
116
|
-
pull_request: {
|
117
|
-
number: existing_pull_request.number,
|
118
|
-
owner: existing_pull_request.user.login,
|
119
|
-
comments: [{author: 'tito'}, {author: 'bobby'}, {author: 'ringo'}]
|
120
|
-
},
|
121
|
-
issue: {
|
122
|
-
number: existing_pull_request.number,
|
123
|
-
comments: [{author: 'ringo'}, {author: 'randy'}]
|
124
|
-
})
|
125
|
-
end
|
126
|
-
|
127
|
-
specify { expect(subject.reviewers).to eq(['tito', 'bobby', 'randy']) }
|
128
|
-
end
|
129
|
-
|
130
|
-
|
131
|
-
describe "#approved?" do
|
132
|
-
|
133
|
-
context "no approvals and build success" do
|
134
|
-
before do
|
135
|
-
FakeGitHub.new(
|
136
|
-
repo_owner: user,
|
137
|
-
repo_name: repo,
|
138
|
-
pull_request: {
|
139
|
-
number: existing_pull_request.number,
|
140
|
-
owner: existing_pull_request.head.user.login,
|
141
|
-
comments: []
|
142
|
-
})
|
143
|
-
allow(GitReflow::GitServer::GitHub::PullRequest).to receive(:minimum_approvals).and_return("0")
|
144
|
-
end
|
145
|
-
specify { expect(subject.approved?).to be_truthy }
|
146
|
-
end
|
147
|
-
|
148
|
-
context "all commenters must approve and minimum_approvals is nil" do
|
149
|
-
before do
|
150
|
-
FakeGitHub.new(
|
151
|
-
repo_owner: user,
|
152
|
-
repo_name: repo,
|
153
|
-
pull_request: {
|
154
|
-
number: existing_pull_request.number,
|
155
|
-
owner: existing_pull_request.head.user.login,
|
156
|
-
comments: []
|
157
|
-
})
|
158
|
-
allow(GitReflow::GitServer::GitHub::PullRequest).to receive(:minimum_approvals).and_return(nil)
|
159
|
-
allow(subject).to receive(:has_comments?).and_return(true)
|
160
|
-
allow(subject).to receive(:approvals).and_return(["Simon"])
|
161
|
-
allow(subject).to receive(:reviewers_pending_response).and_return([])
|
162
|
-
end
|
163
|
-
specify { expect(subject.approved?).to be_truthy }
|
164
|
-
end
|
165
|
-
|
166
|
-
context "all commenters must approve but we have no pending reviewers" do
|
167
|
-
before do
|
168
|
-
FakeGitHub.new(
|
169
|
-
repo_owner: user,
|
170
|
-
repo_name: repo,
|
171
|
-
pull_request: {
|
172
|
-
number: existing_pull_request.number,
|
173
|
-
owner: existing_pull_request.head.user.login,
|
174
|
-
comments: []
|
175
|
-
})
|
176
|
-
allow(GitReflow::GitServer::GitHub::PullRequest).to receive(:minimum_approvals).and_return("")
|
177
|
-
allow(subject).to receive(:has_comments?).and_return(true)
|
178
|
-
allow(subject).to receive(:approvals).and_return(["Simon"])
|
179
|
-
allow(subject).to receive(:reviewers_pending_response).and_return([])
|
180
|
-
end
|
181
|
-
specify { expect(subject.approved?).to be_truthy }
|
182
|
-
end
|
183
|
-
|
184
|
-
context "all commenters must approve but we have 1 pending reviewer" do
|
185
|
-
before do
|
186
|
-
FakeGitHub.new(
|
187
|
-
repo_owner: user,
|
188
|
-
repo_name: repo,
|
189
|
-
pull_request: {
|
190
|
-
number: existing_pull_request.number,
|
191
|
-
owner: existing_pull_request.head.user.login,
|
192
|
-
comments: []
|
193
|
-
})
|
194
|
-
allow(GitReflow::GitServer::GitHub::PullRequest).to receive(:minimum_approvals).and_return("")
|
195
|
-
allow(subject).to receive(:has_comments?).and_return(true)
|
196
|
-
allow(subject).to receive(:approvals).and_return(["Simon"])
|
197
|
-
allow(subject).to receive(:reviewers_pending_response).and_return(["Simon"])
|
198
|
-
end
|
199
|
-
specify { expect(subject.approved?).to be_falsy }
|
200
|
-
end
|
201
|
-
|
202
|
-
context "2 approvals required but we only have 1 approval" do
|
203
|
-
before do
|
204
|
-
FakeGitHub.new(
|
205
|
-
repo_owner: user,
|
206
|
-
repo_name: repo,
|
207
|
-
pull_request: {
|
208
|
-
number: existing_pull_request.number,
|
209
|
-
owner: existing_pull_request.head.user.login,
|
210
|
-
comments: []
|
211
|
-
})
|
212
|
-
allow(GitReflow::GitServer::GitHub::PullRequest).to receive(:minimum_approvals).and_return("2")
|
213
|
-
allow(subject).to receive(:approvals).and_return(["Simon"])
|
214
|
-
allow(subject).to receive(:last_comment).and_return("LGTM")
|
215
|
-
end
|
216
|
-
specify { expect(subject.approved?).to be_falsy }
|
217
|
-
end
|
218
|
-
|
219
|
-
context "2 approvals required and we have 2 approvals but last comment is not approval" do
|
220
|
-
before do
|
221
|
-
FakeGitHub.new(
|
222
|
-
repo_owner: user,
|
223
|
-
repo_name: repo,
|
224
|
-
pull_request: {
|
225
|
-
number: existing_pull_request.number,
|
226
|
-
owner: existing_pull_request.head.user.login,
|
227
|
-
comments: []
|
228
|
-
})
|
229
|
-
allow(GitReflow::GitServer::GitHub::PullRequest).to receive(:minimum_approvals).and_return("2")
|
230
|
-
allow(subject).to receive(:approvals).and_return(["Simon", "Peter"])
|
231
|
-
allow(subject).to receive(:last_comment).and_return("Boo")
|
232
|
-
end
|
233
|
-
specify { expect(subject.approved?).to be_falsy }
|
234
|
-
end
|
235
|
-
|
236
|
-
context "2 approvals required and we have 2 approvals and last comment is approval" do
|
237
|
-
before do
|
238
|
-
FakeGitHub.new(
|
239
|
-
repo_owner: user,
|
240
|
-
repo_name: repo,
|
241
|
-
pull_request: {
|
242
|
-
number: existing_pull_request.number,
|
243
|
-
owner: existing_pull_request.head.user.login,
|
244
|
-
comments: []
|
245
|
-
})
|
246
|
-
allow(GitReflow::GitServer::GitHub::PullRequest).to receive(:minimum_approvals).and_return("2")
|
247
|
-
allow(subject).to receive(:approvals).and_return(["Simon", "Peter"])
|
248
|
-
allow(subject).to receive(:last_comment).and_return("LGTM")
|
249
|
-
end
|
250
|
-
specify { expect(subject.approved?).to be_truthy }
|
251
|
-
end
|
252
|
-
end
|
253
|
-
|
254
|
-
describe '#approvals' do
|
255
|
-
context "no comments" do
|
256
|
-
before do
|
257
|
-
FakeGitHub.new(
|
258
|
-
repo_owner: user,
|
259
|
-
repo_name: repo,
|
260
|
-
pull_request: {
|
261
|
-
number: existing_pull_request.number,
|
262
|
-
owner: existing_pull_request.head.user.login,
|
263
|
-
comments: []
|
264
|
-
})
|
265
|
-
end
|
266
|
-
|
267
|
-
specify { expect(subject.approvals).to eq([]) }
|
268
|
-
end
|
269
|
-
|
270
|
-
context "single reviewer without approval" do
|
271
|
-
before do
|
272
|
-
FakeGitHub.new(
|
273
|
-
repo_owner: user,
|
274
|
-
repo_name: repo,
|
275
|
-
pull_request: {
|
276
|
-
number: existing_pull_request.number,
|
277
|
-
owner: existing_pull_request.head.user.login,
|
278
|
-
comments: [{author: 'tito', body: 'This is some funky stuff'}]
|
279
|
-
})
|
280
|
-
end
|
281
|
-
|
282
|
-
specify { expect(subject.approvals).to eq([]) }
|
283
|
-
end
|
284
|
-
|
285
|
-
context "single reviewer with approval" do
|
286
|
-
before do
|
287
|
-
FakeGitHub.new(
|
288
|
-
repo_owner: user,
|
289
|
-
repo_name: repo,
|
290
|
-
pull_request: {
|
291
|
-
number: existing_pull_request.number,
|
292
|
-
owner: existing_pull_request.head.user.login,
|
293
|
-
comments: [{author: 'tito', body: 'LGTM'}]
|
294
|
-
})
|
295
|
-
end
|
296
|
-
|
297
|
-
specify { expect(subject.approvals).to eq(['tito']) }
|
298
|
-
|
299
|
-
context "but a new commit has been introduced" do
|
300
|
-
before do
|
301
|
-
FakeGitHub.new(
|
302
|
-
repo_owner: user,
|
303
|
-
repo_name: repo,
|
304
|
-
commits: [
|
305
|
-
{
|
306
|
-
author: user,
|
307
|
-
pull_request_number: existing_pull_request.number,
|
308
|
-
created_at: Chronic.parse("1 second ago")
|
309
|
-
}
|
310
|
-
],
|
311
|
-
pull_request: {
|
312
|
-
number: existing_pull_request.number,
|
313
|
-
owner: existing_pull_request.head.user.login,
|
314
|
-
comments: [{author: 'tito', body: 'LGTM', created_at: Chronic.parse('1 minute ago')}]
|
315
|
-
})
|
316
|
-
end
|
317
|
-
|
318
|
-
specify { expect(subject.approvals).to eq([]) }
|
319
|
-
end
|
320
|
-
end
|
321
|
-
|
322
|
-
context "multiple reviewers with only one approval" do
|
323
|
-
before do
|
324
|
-
FakeGitHub.new(
|
325
|
-
repo_owner: user,
|
326
|
-
repo_name: repo,
|
327
|
-
pull_request: {
|
328
|
-
number: existing_pull_request.number,
|
329
|
-
owner: existing_pull_request.head.user.login,
|
330
|
-
comments: [{author: 'tito', body: 'LGTM'}, {author: 'ringo', body: 'Needs more cowbell.'}]
|
331
|
-
})
|
332
|
-
end
|
333
|
-
|
334
|
-
specify { expect(subject.approvals).to eq(['tito']) }
|
335
|
-
end
|
336
|
-
|
337
|
-
context "multiple reviewers with all approvals" do
|
338
|
-
before do
|
339
|
-
FakeGitHub.new(
|
340
|
-
repo_owner: user,
|
341
|
-
repo_name: repo,
|
342
|
-
pull_request: {
|
343
|
-
number: existing_pull_request.number,
|
344
|
-
owner: existing_pull_request.head.user.login,
|
345
|
-
comments: [{author: 'tito', body: 'lgtm'}, {author: 'ringo', body: ':+1:'}]
|
346
|
-
})
|
347
|
-
|
348
|
-
allow(GitReflow::GitServer::GitHub::PullRequest).to receive(:approval_regex).and_return(/(?i-mx:lgtm|looks good to me|:\+1:|:thumbsup:|:shipit:)/)
|
349
|
-
end
|
350
|
-
|
351
|
-
context "2 approvals" do
|
352
|
-
specify { expect(subject.approvals).to eq(['tito', 'ringo']) }
|
353
|
-
end
|
354
|
-
|
355
|
-
context "but a new commit has been introduced" do
|
356
|
-
before do
|
357
|
-
FakeGitHub.new(
|
358
|
-
repo_owner: user,
|
359
|
-
repo_name: repo,
|
360
|
-
commits: [
|
361
|
-
{
|
362
|
-
author: user,
|
363
|
-
pull_request_number: existing_pull_request.number,
|
364
|
-
created_at: Chronic.parse("1 second ago")
|
365
|
-
}
|
366
|
-
],
|
367
|
-
pull_request: {
|
368
|
-
number: existing_pull_request.number,
|
369
|
-
owner: existing_pull_request.head.user.login,
|
370
|
-
comments: [{author: 'tito', body: 'lgtm', created_at: Chronic.parse('1 minute ago')}, {author: 'ringo', body: ':+1:', created_at: Chronic.parse('1 minute ago')}]
|
371
|
-
})
|
372
|
-
end
|
373
|
-
|
374
|
-
specify { expect(subject.approvals).to eq([]) }
|
375
|
-
end
|
376
|
-
end
|
377
|
-
|
378
|
-
end
|
379
|
-
|
380
|
-
describe '#last_comment' do
|
381
|
-
before do
|
382
|
-
FakeGitHub.new(
|
383
|
-
repo_owner: user,
|
384
|
-
repo_name: repo,
|
385
|
-
pull_request: {
|
386
|
-
number: existing_pull_request.number,
|
387
|
-
owner: existing_pull_request.head.user.login,
|
388
|
-
comments: [{author: 'tito', body: 'lgtm'}, {author: 'ringo', body: 'Cha cha cha'}]
|
389
|
-
})
|
390
|
-
end
|
391
|
-
|
392
|
-
specify { expect(subject.last_comment).to eq('"Cha cha cha"') }
|
393
|
-
end
|
394
|
-
|
395
|
-
describe '#build' do
|
396
|
-
let(:build) { Fixture.new('repositories/statuses.json').to_json_hashie.first }
|
397
|
-
|
398
|
-
context "with an existing build" do
|
399
|
-
specify { expect(subject.build.state).to eq(build.state) }
|
400
|
-
specify { expect(subject.build.description).to eq(build.description) }
|
401
|
-
specify { expect(subject.build.url).to eq(build.target_url) }
|
402
|
-
end
|
403
|
-
|
404
|
-
context "no build found" do
|
405
|
-
before { allow(GitReflow.git_server).to receive(:get_build_status).and_return(nil) }
|
406
|
-
specify { expect(subject.build.state).to eq(nil) }
|
407
|
-
specify { expect(subject.build.description).to eq(nil) }
|
408
|
-
specify { expect(subject.build.url).to eq(nil) }
|
409
|
-
end
|
410
|
-
end
|
411
|
-
|
412
|
-
|
413
|
-
describe '.create(options)' do
|
414
|
-
let(:title) { 'Bone Saw is ready!' }
|
415
|
-
let(:body) { 'Snap into a Slim Jim!' }
|
416
|
-
let(:base_branch_name) { 'base-branch' }
|
417
|
-
let(:pull_request_response) do
|
418
|
-
Fixture.new('pull_requests/pull_request.json.erb',
|
419
|
-
number: 2,
|
420
|
-
title: title,
|
421
|
-
body: body,
|
422
|
-
base_branch: base_branch_name,
|
423
|
-
repo_owner: user,
|
424
|
-
repo_name: repo)
|
425
|
-
end
|
426
|
-
|
427
|
-
subject { GitReflow::GitServer::GitHub::PullRequest.create(title: title, body: body, base: base_branch_name) }
|
428
|
-
|
429
|
-
before do
|
430
|
-
stub_request(:post, %r{/repos/#{user}/#{repo}/pulls}).
|
431
|
-
to_return(body: pull_request_response.to_s, status: 201, headers: {content_type: "application/json; charset=utf-8"})
|
432
|
-
end
|
433
|
-
|
434
|
-
specify { expect(subject.class.to_s).to eql('GitReflow::GitServer::GitHub::PullRequest') }
|
435
|
-
specify { expect(subject.title).to eql(title) }
|
436
|
-
specify { expect(subject.description).to eql(body) }
|
437
|
-
specify { expect(subject.base_branch_name).to eql(base_branch_name) }
|
438
|
-
end
|
439
|
-
|
440
|
-
describe '.find_open(options)' do
|
441
|
-
let(:feature_branch) { 'new-feature' }
|
442
|
-
let(:base_branch) { 'base-branch' }
|
443
|
-
|
444
|
-
subject { GitReflow::GitServer::GitHub::PullRequest.find_open(from: feature_branch, to: base_branch) }
|
445
|
-
|
446
|
-
before do
|
447
|
-
allow(GitReflow.git_server.class).to receive(:current_branch).and_return(feature_branch)
|
448
|
-
FakeGitHub.new(
|
449
|
-
repo_owner: user,
|
450
|
-
repo_name: repo,
|
451
|
-
pull_request: {
|
452
|
-
number: existing_pull_request.number,
|
453
|
-
owner: existing_pull_request.head.user.login,
|
454
|
-
base_branch: base_branch,
|
455
|
-
feature_branch: feature_branch
|
456
|
-
})
|
457
|
-
end
|
458
|
-
|
459
|
-
specify { expect(subject.class.to_s).to eql('GitReflow::GitServer::GitHub::PullRequest') }
|
460
|
-
specify { expect(subject.number).to eql(existing_pull_request.number) }
|
461
|
-
|
462
|
-
context "without any options" do
|
463
|
-
let(:base_branch) { 'master' }
|
464
|
-
subject { GitReflow::GitServer::GitHub::PullRequest.find_open() }
|
465
|
-
it "defaults to the current branch as the feature branch and 'master' as the base branch" do
|
466
|
-
expect(subject.class.to_s).to eql('GitReflow::GitServer::GitHub::PullRequest')
|
467
|
-
expect(subject.number).to eql(existing_pull_request.number)
|
468
|
-
end
|
469
|
-
end
|
470
|
-
end
|
471
|
-
|
472
|
-
end
|