git_reflow 0.9.2 → 0.9.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/multi-ruby-tests.yml +24 -0
- data/.rubocop.yml +7 -0
- data/.ruby-version +1 -1
- data/CHANGELOG.md +105 -12
- data/Gemfile.lock +133 -61
- data/README.md +9 -5
- data/Rakefile +8 -1
- data/git_reflow.gemspec +26 -24
- data/lib/git_reflow/config.rb +30 -4
- data/lib/git_reflow/git_helpers.rb +10 -4
- data/lib/git_reflow/git_server/git_hub/pull_request.rb +22 -6
- data/lib/git_reflow/git_server/git_hub.rb +53 -40
- data/lib/git_reflow/git_server/pull_request.rb +15 -1
- data/lib/git_reflow/version.rb +1 -1
- data/lib/git_reflow/workflow.rb +3 -3
- data/spec/fixtures/authentication_failure.json +3 -0
- data/spec/fixtures/users/user.json +32 -0
- data/spec/lib/git_reflow/git_helpers_spec.rb +92 -72
- data/spec/lib/git_reflow/git_server/git_hub/pull_request_spec.rb +1 -1
- data/spec/lib/git_reflow/git_server/git_hub_spec.rb +77 -3
- data/spec/lib/git_reflow/git_server/pull_request_spec.rb +33 -5
- data/spec/lib/git_reflow_spec.rb +0 -1
- data/spec/spec_helper.rb +1 -1
- metadata +54 -36
- data/circle.yml +0 -26
data/lib/git_reflow/workflow.rb
CHANGED
@@ -132,7 +132,7 @@ module GitReflow
|
|
132
132
|
@workflows
|
133
133
|
end
|
134
134
|
|
135
|
-
# Creates a singleton method on the
|
135
|
+
# Creates a singleton method on the included class
|
136
136
|
#
|
137
137
|
# This method will take any number of keyword parameters. If @defaults keyword is provided, and the given
|
138
138
|
# key(s) in the defaults are not provided as keyword parameters, then it will use the value given in the
|
@@ -157,7 +157,7 @@ module GitReflow
|
|
157
157
|
self.commands[name] = params
|
158
158
|
self.command_docs[name] = params
|
159
159
|
|
160
|
-
self.define_singleton_method(name) do
|
160
|
+
self.define_singleton_method(name) do |args = {}|
|
161
161
|
args_with_defaults = {}
|
162
162
|
args.each do |name, value|
|
163
163
|
if "#{value}".length <= 0 && !defaults[name].nil?
|
@@ -230,7 +230,7 @@ module GitReflow
|
|
230
230
|
end
|
231
231
|
end
|
232
232
|
|
233
|
-
# Creates a singleton method on the
|
233
|
+
# Creates a singleton method on the included class
|
234
234
|
#
|
235
235
|
# This method updates the help text associated with the provided command.
|
236
236
|
#
|
@@ -0,0 +1,32 @@
|
|
1
|
+
{
|
2
|
+
"login": "reenhanced",
|
3
|
+
"id": 1,
|
4
|
+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
|
5
|
+
"gravatar_id": "somehexcode",
|
6
|
+
"url": "https://api.github.com/users/reenhanced",
|
7
|
+
"name": "monalisa octocat",
|
8
|
+
"company": "GitHub",
|
9
|
+
"blog": "https://github.com/blog",
|
10
|
+
"location": "San Francisco",
|
11
|
+
"email": "octocat@github.com",
|
12
|
+
"hireable": false,
|
13
|
+
"bio": "There once was...",
|
14
|
+
"public_repos": 2,
|
15
|
+
"public_gists": 1,
|
16
|
+
"followers": 20,
|
17
|
+
"following": 0,
|
18
|
+
"html_url": "https://github.com/reenhanced",
|
19
|
+
"created_at": "2008-01-14T04:33:35Z",
|
20
|
+
"type": "User",
|
21
|
+
"total_private_repos": 100,
|
22
|
+
"owned_private_repos": 100,
|
23
|
+
"private_gists": 81,
|
24
|
+
"disk_usage": 10000,
|
25
|
+
"collaborators": 8,
|
26
|
+
"plan": {
|
27
|
+
"name": "Medium",
|
28
|
+
"space": 400,
|
29
|
+
"collaborators": 10,
|
30
|
+
"private_repos": 20
|
31
|
+
}
|
32
|
+
}
|
@@ -1,15 +1,15 @@
|
|
1
|
-
require
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
module Gitacular
|
4
|
+
include GitReflow::GitHelpers
|
5
|
+
extend self
|
6
|
+
end
|
2
7
|
|
3
8
|
describe GitReflow::GitHelpers do
|
4
|
-
let(:origin_url) {
|
9
|
+
let(:origin_url) { "git@github.com:reenhanced.spectacular/this-is-the.shit.git" }
|
5
10
|
|
6
11
|
before do
|
7
|
-
stub_with_fallback(GitReflow::Config, :get).with(
|
8
|
-
|
9
|
-
module Gitacular
|
10
|
-
include GitReflow::GitHelpers
|
11
|
-
extend self
|
12
|
-
end
|
12
|
+
stub_with_fallback(GitReflow::Config, :get).with("remote.origin.url").and_return(origin_url)
|
13
13
|
|
14
14
|
stub_run_for Gitacular
|
15
15
|
end
|
@@ -18,83 +18,86 @@ describe GitReflow::GitHelpers do
|
|
18
18
|
subject { Gitacular.default_editor }
|
19
19
|
|
20
20
|
context "when the environment has EDITOR set" do
|
21
|
-
before { allow(ENV).to receive(:[]).with(
|
22
|
-
specify { expect(
|
21
|
+
before { allow(ENV).to receive(:[]).with("EDITOR").and_return("emacs") }
|
22
|
+
specify { expect(subject).to eql("emacs") }
|
23
23
|
end
|
24
24
|
|
25
25
|
context "when the environment has no EDITOR set" do
|
26
|
-
before { allow(ENV).to receive(:[]).with(
|
27
|
-
specify { expect(
|
26
|
+
before { allow(ENV).to receive(:[]).with("EDITOR").and_return(nil) }
|
27
|
+
specify { expect(subject).to eql("vi") }
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
31
|
describe ".git_root_dir" do
|
32
32
|
subject { Gitacular.git_root_dir }
|
33
|
-
it { expect{ subject }.to have_run_command_silently "git rev-parse --show-toplevel" }
|
33
|
+
it { expect { subject }.to have_run_command_silently "git rev-parse --show-toplevel" }
|
34
34
|
end
|
35
35
|
|
36
|
-
describe
|
36
|
+
describe ".git_editor_command" do
|
37
37
|
subject { Gitacular.git_editor_command }
|
38
|
-
before { ENV[
|
38
|
+
before { ENV["EDITOR"] = "vim" }
|
39
39
|
|
40
|
-
it
|
41
|
-
allow(GitReflow::Config).to receive(:get).with(
|
40
|
+
it "defaults to GitReflow config" do
|
41
|
+
allow(GitReflow::Config).to receive(:get).with("core.editor").and_return "nano"
|
42
42
|
|
43
|
-
expect(subject).to eq
|
43
|
+
expect(subject).to eq "nano"
|
44
44
|
end
|
45
45
|
|
46
|
-
it
|
47
|
-
allow(GitReflow::Config).to receive(:get).with(
|
46
|
+
it "falls back to the environment variable $EDITOR" do
|
47
|
+
allow(GitReflow::Config).to receive(:get).with("core.editor").and_return ""
|
48
48
|
|
49
|
-
expect(subject).to eq
|
49
|
+
expect(subject).to eq "vim"
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
53
|
describe ".remote_user" do
|
54
54
|
subject { Gitacular.remote_user }
|
55
55
|
|
56
|
-
it { is_expected.to eq(
|
56
|
+
it { is_expected.to eq("reenhanced.spectacular") }
|
57
57
|
|
58
58
|
context "remote origin url isn't set" do
|
59
|
-
let(:origin_url) {
|
60
|
-
it { is_expected.to eq(
|
59
|
+
let(:origin_url) { "" }
|
60
|
+
it { is_expected.to eq("") }
|
61
61
|
end
|
62
62
|
|
63
63
|
context "remote origin uses HTTP" do
|
64
|
-
let(:origin_url) {
|
65
|
-
it { is_expected.to eq(
|
64
|
+
let(:origin_url) { "https://github.com/reenhanced.spectacular/this-is-the.shit.git" }
|
65
|
+
it { is_expected.to eq("reenhanced.spectacular") }
|
66
66
|
end
|
67
67
|
end
|
68
68
|
|
69
69
|
describe ".remote_repo_name" do
|
70
70
|
subject { Gitacular.remote_repo_name }
|
71
71
|
|
72
|
-
it { is_expected.to eq(
|
72
|
+
it { is_expected.to eq("this-is-the.shit") }
|
73
73
|
|
74
74
|
context "remote origin url isn't set" do
|
75
|
-
let(:origin_url) {
|
76
|
-
it { is_expected.to eq(
|
75
|
+
let(:origin_url) { "" }
|
76
|
+
it { is_expected.to eq("") }
|
77
77
|
end
|
78
78
|
|
79
79
|
context "remote origin uses HTTP" do
|
80
|
-
let(:origin_url) {
|
81
|
-
it { is_expected.to eq(
|
80
|
+
let(:origin_url) { "https://github.com/reenhanced.spectacular/this-is-the.shit.git" }
|
81
|
+
it { is_expected.to eq("this-is-the.shit") }
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
85
|
-
describe
|
85
|
+
describe ".default_base_branch" do
|
86
86
|
subject { Gitacular.default_base_branch }
|
87
|
-
it { is_expected.to eq(
|
87
|
+
it { is_expected.to eq("master") }
|
88
88
|
|
89
|
-
context
|
90
|
-
before { allow(GitReflow::Config).to receive(:get).with(
|
91
|
-
it { is_expected.to eq(
|
89
|
+
context "when configured" do
|
90
|
+
before { allow(GitReflow::Config).to receive(:get).with("reflow.base-branch").and_return("tuba") }
|
91
|
+
it { is_expected.to eq("tuba") }
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
95
|
describe ".current_branch" do
|
96
96
|
subject { Gitacular.current_branch }
|
97
|
-
it
|
97
|
+
it {
|
98
|
+
expect { subject }
|
99
|
+
.to have_run_command_silently "git branch --no-color | grep '^\* ' | grep -v 'no branch' | sed 's/^* //g'"
|
100
|
+
}
|
98
101
|
end
|
99
102
|
|
100
103
|
describe ".pull_request_template" do
|
@@ -119,36 +122,29 @@ describe GitReflow::GitHelpers do
|
|
119
122
|
|
120
123
|
it { is_expected.to be_nil }
|
121
124
|
end
|
122
|
-
end
|
123
|
-
|
124
|
-
describe ".pull_request_template" do
|
125
|
-
subject { Gitacular.pull_request_template }
|
126
|
-
|
127
|
-
context "template file exists" do
|
128
|
-
let(:root_dir) { "/some_repo" }
|
129
|
-
let(:template_content) { "Template content" }
|
130
125
|
|
126
|
+
context "custom template file configured" do
|
131
127
|
before do
|
132
|
-
allow(
|
133
|
-
allow(File).to receive(:exist?).with("#{root_dir}/.github/PULL_REQUEST_TEMPLATE.md").and_return(true)
|
134
|
-
allow(File).to receive(:read).with("#{root_dir}/.github/PULL_REQUEST_TEMPLATE.md").and_return(template_content)
|
128
|
+
allow(GitReflow::Config).to receive(:get).with("templates.pull-request").and_return "pr_template_file.md"
|
135
129
|
end
|
136
130
|
|
137
|
-
|
131
|
+
context "template file exists" do
|
132
|
+
let(:template_content) { "Template content" }
|
138
133
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
134
|
+
before do
|
135
|
+
allow(File).to receive(:exist?).with("pr_template_file.md").and_return(true)
|
136
|
+
allow(File).to receive(:read).with("pr_template_file.md").and_return(template_content)
|
137
|
+
end
|
138
|
+
it { is_expected.to eq template_content }
|
143
139
|
end
|
144
|
-
end
|
145
140
|
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
141
|
+
context "template file does not exist" do
|
142
|
+
before do
|
143
|
+
allow(File).to receive(:exist?).and_return(false)
|
144
|
+
end
|
150
145
|
|
151
|
-
|
146
|
+
it { is_expected.to be_nil }
|
147
|
+
end
|
152
148
|
end
|
153
149
|
end
|
154
150
|
|
@@ -181,27 +177,51 @@ describe GitReflow::GitHelpers do
|
|
181
177
|
|
182
178
|
it { is_expected.to be_nil }
|
183
179
|
end
|
180
|
+
|
181
|
+
context "custom template file configured" do
|
182
|
+
before do
|
183
|
+
allow(GitReflow::Config).to receive(:get).with("templates.merge-commit").and_return "merge_template_file.md"
|
184
|
+
end
|
185
|
+
|
186
|
+
context "template file exists" do
|
187
|
+
let(:template_content) { "Template content" }
|
188
|
+
|
189
|
+
before do
|
190
|
+
allow(File).to receive(:exist?).with("merge_template_file.md").and_return(true)
|
191
|
+
allow(File).to receive(:read).with("merge_template_file.md").and_return(template_content)
|
192
|
+
end
|
193
|
+
it { is_expected.to eq template_content }
|
194
|
+
end
|
195
|
+
|
196
|
+
context "template file does not exist" do
|
197
|
+
before do
|
198
|
+
allow(File).to receive(:exist?).and_return(false)
|
199
|
+
end
|
200
|
+
|
201
|
+
it { is_expected.to be_nil }
|
202
|
+
end
|
203
|
+
end
|
184
204
|
end
|
185
205
|
|
186
206
|
describe ".get_first_commit_message" do
|
187
207
|
subject { Gitacular.get_first_commit_message }
|
188
|
-
it { expect{ subject }.to have_run_command_silently 'git log --pretty=format:"%s" --no-merges -n 1' }
|
208
|
+
it { expect { subject }.to have_run_command_silently 'git log --pretty=format:"%s" --no-merges -n 1' }
|
189
209
|
end
|
190
210
|
|
191
211
|
describe ".push_current_branch" do
|
192
212
|
subject { Gitacular.push_current_branch }
|
193
|
-
before { allow(Gitacular).to receive(:current_branch).and_return(
|
194
|
-
it { expect{ subject }.to have_run_command "git push origin bingo" }
|
213
|
+
before { allow(Gitacular).to receive(:current_branch).and_return("bingo") }
|
214
|
+
it { expect { subject }.to have_run_command "git push origin bingo" }
|
195
215
|
end
|
196
216
|
|
197
217
|
describe ".fetch_destination(destination_branch)" do
|
198
|
-
subject { Gitacular.fetch_destination(
|
199
|
-
it { expect{ subject }.to have_run_command "git fetch origin new-feature" }
|
218
|
+
subject { Gitacular.fetch_destination("new-feature") }
|
219
|
+
it { expect { subject }.to have_run_command "git fetch origin new-feature" }
|
200
220
|
end
|
201
221
|
|
202
222
|
describe ".update_destination(destination_branch)" do
|
203
|
-
let(:current_branch) {
|
204
|
-
let(:destination_branch) {
|
223
|
+
let(:current_branch) { "bananas" }
|
224
|
+
let(:destination_branch) { "monkey-business" }
|
205
225
|
|
206
226
|
before { allow(Gitacular).to receive(:current_branch).and_return(current_branch) }
|
207
227
|
subject { Gitacular.update_destination(destination_branch) }
|
@@ -217,7 +237,7 @@ describe GitReflow::GitHelpers do
|
|
217
237
|
|
218
238
|
describe ".update_current_branch" do
|
219
239
|
subject { Gitacular.update_current_branch }
|
220
|
-
before { allow(Gitacular).to receive(:current_branch).and_return(
|
240
|
+
before { allow(Gitacular).to receive(:current_branch).and_return("new-feature") }
|
221
241
|
|
222
242
|
it "updates the remote changes and pushes any local changes" do
|
223
243
|
expect { subject }.to have_run_commands_in_order [
|
@@ -228,9 +248,9 @@ describe GitReflow::GitHelpers do
|
|
228
248
|
end
|
229
249
|
|
230
250
|
describe ".update_feature_branch" do
|
231
|
-
options = {base: "base", remote: "remote"}
|
251
|
+
options = { base: "base", remote: "remote" }
|
232
252
|
subject { Gitacular.update_feature_branch(options) }
|
233
|
-
before { allow(Gitacular).to receive(:current_branch).and_return(
|
253
|
+
before { allow(Gitacular).to receive(:current_branch).and_return("feature") }
|
234
254
|
|
235
255
|
it "calls the correct methods" do
|
236
256
|
expect { subject }.to have_run_commands_in_order [
|
@@ -246,14 +266,14 @@ describe GitReflow::GitHelpers do
|
|
246
266
|
describe ".append_to_merge_commit_message(message)" do
|
247
267
|
let(:original_commit_message) { "Oooooo, SQUASH IT" }
|
248
268
|
let(:message) { "do do the voodoo that you do" }
|
249
|
-
let(:root_dir) {
|
269
|
+
let(:root_dir) { "/home/gitreflow" }
|
250
270
|
let(:merge_message_path) { "#{root_dir}/.git/SQUASH_MSG" }
|
251
271
|
let(:tmp_merge_message_path) { "#{root_dir}/.git/tmp_merge_msg" }
|
252
272
|
before { allow(Gitacular).to receive(:git_root_dir).and_return(root_dir) }
|
253
273
|
subject { Gitacular.append_to_merge_commit_message(message) }
|
254
274
|
|
255
275
|
it "appends the message to git's SQUASH_MSG temp file" do
|
256
|
-
tmp_file = double(
|
276
|
+
tmp_file = double("file")
|
257
277
|
allow(File).to receive(:open).with(tmp_merge_message_path, "w").and_yield(tmp_file)
|
258
278
|
allow(File).to receive(:exists?).with(merge_message_path).and_return(true)
|
259
279
|
allow(File).to receive(:foreach).with(merge_message_path).and_yield(original_commit_message)
|
@@ -269,7 +289,7 @@ describe GitReflow::GitHelpers do
|
|
269
289
|
let(:merge_message_path) { "#{root_dir}/.git/MERGE_MSG" }
|
270
290
|
subject { Gitacular.append_to_merge_commit_message(message, merge_method: "merge") }
|
271
291
|
it "appends the message to git's MERGE_MSG temp file if using a direct merge" do
|
272
|
-
tmp_file = double(
|
292
|
+
tmp_file = double("file")
|
273
293
|
allow(File).to receive(:open).with(tmp_merge_message_path, "w").and_yield(tmp_file)
|
274
294
|
allow(File).to receive(:exists?).with(merge_message_path).and_return(true)
|
275
295
|
allow(File).to receive(:foreach).with(merge_message_path).and_yield(original_commit_message)
|
@@ -100,7 +100,7 @@ describe GitReflow::GitServer::GitHub::PullRequest do
|
|
100
100
|
context "Testing Nil Comments" do
|
101
101
|
before do
|
102
102
|
stub_request(:get, "https://api.github.com/repos/reenhanced/repo/pulls/2/comments?access_token=a1b2c3d4e5f6g7h8i9j0").
|
103
|
-
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.
|
103
|
+
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.19.0'}).
|
104
104
|
to_return(:status => 200, :body => "", :headers => {})
|
105
105
|
|
106
106
|
FakeGitHub.new(
|
@@ -78,7 +78,7 @@ describe GitReflow::GitServer::GitHub do
|
|
78
78
|
subject { github.authenticate }
|
79
79
|
|
80
80
|
before do
|
81
|
-
allow(GitReflow::GitServer::GitHub).to receive(:user).and_return(
|
81
|
+
allow(GitReflow::GitServer::GitHub).to receive(:user).and_return(user)
|
82
82
|
allow(github_api).to receive(:oauth).and_return(github_authorizations)
|
83
83
|
allow(github_api).to receive_message_chain(:oauth, :all).and_return([])
|
84
84
|
allow(github).to receive(:run).with('hostname', loud: false).and_return(hostname)
|
@@ -151,12 +151,86 @@ describe GitReflow::GitServer::GitHub do
|
|
151
151
|
body: { error: "GET https://api.github.com/authorizations: 401 Bad credentials" }
|
152
152
|
}}
|
153
153
|
|
154
|
+
before do
|
155
|
+
allow(GitReflow::Config).to receive(:get).and_call_original
|
156
|
+
allow(GitReflow::Config).to receive(:get).with('github.oauth-token').and_return(oauth_token_hash[:token])
|
157
|
+
allow(Github::Client).to receive(:new).and_return(github_api)
|
158
|
+
allow(github_authorizations).to receive(:authenticated?).and_return(true)
|
159
|
+
allow(github_api.oauth).to receive(:create).with({ scopes: ['repo'], note: "git-reflow (#{hostname})" }).and_return(oauth_token_hash)
|
160
|
+
|
161
|
+
stub_request(:get, %r{/user}).
|
162
|
+
to_return(
|
163
|
+
body: Fixture.new('authentication_failure.json').to_s,
|
164
|
+
status: 401,
|
165
|
+
headers: {'content-type' => 'application/json; charset=utf-8', status: 'Unauthorized'},
|
166
|
+
)
|
167
|
+
end
|
168
|
+
|
169
|
+
it "notifies the user of successful setup" do
|
170
|
+
expect { subject }.to have_said "Your GitHub account was successfully setup!", :success
|
171
|
+
end
|
172
|
+
|
173
|
+
it "creates a new GitHub oauth token" do
|
174
|
+
expect(github_api.oauth).to receive(:create).and_return(oauth_token_hash)
|
175
|
+
subject
|
176
|
+
end
|
177
|
+
|
178
|
+
it "creates git config keys for github connections" do
|
179
|
+
expect{ subject }.to have_run_command_silently "git config -f #{GitReflow::Config::CONFIG_FILE_PATH} --replace-all github.site \"#{github_site}\"", blocking: false
|
180
|
+
expect{ subject }.to have_run_command_silently "git config -f #{GitReflow::Config::CONFIG_FILE_PATH} --replace-all github.endpoint \"#{github_api_endpoint}\"", blocking: false
|
181
|
+
expect{ subject }.to have_run_command_silently "git config -f #{GitReflow::Config::CONFIG_FILE_PATH} --replace-all github.oauth-token \"#{oauth_token_hash[:token]}\"", blocking: false
|
182
|
+
expect{ subject }.to have_run_command_silently "git config -f #{GitReflow::Config::CONFIG_FILE_PATH} --replace-all reflow.git-server \"GitHub\"", blocking: false
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
context 'already authenticated' do
|
189
|
+
let(:oauth_token) { "abc123" }
|
190
|
+
|
191
|
+
before do
|
192
|
+
allow(GitReflow::Config).to receive(:get).and_call_original
|
193
|
+
allow(GitReflow::Config).to receive(:get).with('github.oauth-token').and_return(oauth_token)
|
194
|
+
end
|
195
|
+
|
196
|
+
context "and authentication token is still valid" do
|
197
|
+
before do
|
198
|
+
stub_request(:get, %r{/user}).
|
199
|
+
to_return(
|
200
|
+
body: Fixture.new('users/user.json').to_s,
|
201
|
+
status: 200,
|
202
|
+
headers: { content_type: "application/json; charset=utf-8" }
|
203
|
+
)
|
204
|
+
|
205
|
+
allow(Github::Client).to receive(:new).and_return(github_api)
|
206
|
+
allow(github_api).to receive(:oauth).and_return(github_authorizations)
|
207
|
+
allow(github_authorizations).to receive(:authenticated?).and_return(true)
|
208
|
+
allow(github_api.oauth).to receive(:create).with({ scopes: ['repo'], note: "git-reflow (#{hostname})" }).and_return(oauth_token_hash)
|
209
|
+
end
|
210
|
+
|
211
|
+
it "resolves all missing git-reflow configurations" do
|
212
|
+
expect{ subject }.to have_run_command_silently "git config -f #{GitReflow::Config::CONFIG_FILE_PATH} --replace-all github.site \"#{github_site}\"", blocking: false
|
213
|
+
expect{ subject }.to have_run_command_silently "git config -f #{GitReflow::Config::CONFIG_FILE_PATH} --replace-all github.endpoint \"#{github_api_endpoint}\"", blocking: false
|
214
|
+
expect{ subject }.to have_run_command_silently "git config -f #{GitReflow::Config::CONFIG_FILE_PATH} --replace-all reflow.git-server \"GitHub\"", blocking: false
|
215
|
+
expect { subject }.to have_said "Your GitHub account was already setup with: "
|
216
|
+
expect { subject }.to have_said "\tUser Name: #{user}"
|
217
|
+
expect { subject }.to have_said "\tEndpoint: #{github_api_endpoint}"
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
context "and authentication token is expired" do
|
222
|
+
let(:unauthorized_error_response) {{
|
223
|
+
response_headers: {'content-type' => 'application/json; charset=utf-8', status: 'Unauthorized'},
|
224
|
+
method: 'GET',
|
225
|
+
status: '401',
|
226
|
+
body: { error: "GET https://api.github.com/authorizations: 401 Bad credentials" }
|
227
|
+
}}
|
228
|
+
|
154
229
|
before do
|
155
230
|
allow(Github::Client).to receive(:new).and_raise Github::Error::Unauthorized.new(unauthorized_error_response)
|
156
231
|
end
|
157
232
|
|
158
|
-
it "
|
159
|
-
expect { subject }.to have_said "Github Authentication Error: #{Github::Error::Unauthorized.new(unauthorized_error_response).inspect}", :error
|
233
|
+
it "requests a new oauth token" do
|
160
234
|
end
|
161
235
|
end
|
162
236
|
end
|
@@ -491,14 +491,42 @@ describe GitReflow::GitServer::PullRequest do
|
|
491
491
|
allow(GitReflow::Config).to receive(:get).with('reflow.always-cleanup').and_return('false')
|
492
492
|
end
|
493
493
|
|
494
|
-
context "and
|
495
|
-
|
494
|
+
context "and always cleanup local config is set" do
|
495
|
+
end
|
496
|
+
|
497
|
+
context "and always cleanup remote config is set" do
|
498
|
+
end
|
499
|
+
|
500
|
+
context "and user chooses to cleanup local only" do
|
501
|
+
before do
|
502
|
+
expect(pr).to receive(:ask).with('Would you like to cleanup your local feature branch? ').and_return('yes')
|
503
|
+
allow(pr).to receive(:ask).with('Would you like to cleanup your remote feature branch? ').and_return('no')
|
504
|
+
end
|
505
|
+
it { should be_truthy }
|
506
|
+
end
|
507
|
+
|
508
|
+
context "and user chooses to cleanup remote only" do
|
509
|
+
before do
|
510
|
+
expect(pr).to receive(:ask).with('Would you like to cleanup your local feature branch? ').and_return('no')
|
511
|
+
expect(pr).to receive(:ask).with('Would you like to cleanup your remote feature branch? ').and_return('yes')
|
512
|
+
end
|
496
513
|
it { should be_truthy }
|
497
514
|
end
|
498
515
|
|
499
|
-
context "and user chooses
|
500
|
-
before
|
501
|
-
|
516
|
+
context "and user chooses to cleanup local and remote" do
|
517
|
+
before do
|
518
|
+
allow(pr).to receive(:ask).with('Would you like to cleanup your local feature branch? ').and_return('yes')
|
519
|
+
allow(pr).to receive(:ask).with('Would you like to cleanup your remote feature branch? ').and_return('yes')
|
520
|
+
end
|
521
|
+
it { should be_truthy }
|
522
|
+
end
|
523
|
+
|
524
|
+
context "and user chooses to cleanup neither local nor remote" do
|
525
|
+
before do
|
526
|
+
expect(pr).to receive(:ask).with('Would you like to cleanup your local feature branch? ').and_return('no')
|
527
|
+
allow(pr).to receive(:ask).with('Would you like to cleanup your remote feature branch? ').and_return('no')
|
528
|
+
end
|
529
|
+
it { should be_falsey }
|
502
530
|
end
|
503
531
|
end
|
504
532
|
end
|
data/spec/lib/git_reflow_spec.rb
CHANGED