git_reflow 0.7.5 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Appraisals +2 -2
- data/CHANGELOG.md +75 -0
- data/Gemfile.lock +34 -35
- data/README.rdoc +187 -60
- data/circle.yml +9 -9
- data/git_reflow.gemspec +8 -8
- data/lib/git_reflow/commands/deliver.rb +1 -9
- data/lib/git_reflow/commands/refresh.rb +23 -0
- data/lib/git_reflow/commands/review.rb +7 -7
- data/lib/git_reflow/commands/setup.rb +7 -3
- data/lib/git_reflow/commands/start.rb +13 -5
- data/lib/git_reflow/git_helpers.rb +22 -23
- data/lib/git_reflow/git_server/bit_bucket/pull_request.rb +4 -4
- data/lib/git_reflow/git_server/bit_bucket.rb +7 -7
- data/lib/git_reflow/git_server/git_hub/pull_request.rb +75 -2
- data/lib/git_reflow/git_server/git_hub.rb +17 -8
- data/lib/git_reflow/git_server/pull_request.rb +73 -5
- data/lib/git_reflow/git_server.rb +3 -3
- data/lib/git_reflow/merge_error.rb +9 -0
- data/lib/git_reflow/sandbox.rb +4 -16
- data/lib/git_reflow/version.rb +1 -1
- data/lib/git_reflow.rb +32 -75
- data/spec/git_reflow_spec.rb +157 -141
- data/spec/lgtm_git_reflow_spec.rb +165 -139
- data/spec/lib/git_reflow/git_helpers_spec.rb +19 -63
- data/spec/lib/git_reflow/git_server_spec.rb +24 -24
- data/spec/lib/git_server/bit_bucket_spec.rb +12 -12
- data/spec/lib/git_server/git_hub/pull_request_spec.rb +7 -5
- data/spec/lib/git_server/git_hub_spec.rb +34 -34
- data/spec/lib/git_server/pull_request_spec.rb +207 -16
- data/spec/support/command_line_helpers.rb +14 -9
- data/spec/support/github_helpers.rb +21 -21
- data/spec/support/rspec_stub_helpers.rb +2 -2
- metadata +18 -16
@@ -22,32 +22,32 @@ describe GitReflow::GitHelpers do
|
|
22
22
|
describe ".remote_user" do
|
23
23
|
subject { Gitacular.remote_user }
|
24
24
|
|
25
|
-
it {
|
25
|
+
it { is_expected.to eq('reenhanced.spectacular') }
|
26
26
|
|
27
27
|
context "remote origin url isn't set" do
|
28
28
|
let(:origin_url) { nil }
|
29
|
-
it {
|
29
|
+
it { is_expected.to eq('') }
|
30
30
|
end
|
31
31
|
|
32
32
|
context "remote origin uses HTTP" do
|
33
33
|
let(:origin_url) { 'https://github.com/reenhanced.spectacular/this-is-the.shit.git' }
|
34
|
-
it {
|
34
|
+
it { is_expected.to eq('reenhanced.spectacular') }
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
38
|
describe ".remote_repo_name" do
|
39
39
|
subject { Gitacular.remote_repo_name }
|
40
40
|
|
41
|
-
it {
|
41
|
+
it { is_expected.to eq('this-is-the.shit') }
|
42
42
|
|
43
43
|
context "remote origin url isn't set" do
|
44
44
|
let(:origin_url) { nil }
|
45
|
-
it {
|
45
|
+
it { is_expected.to eq('') }
|
46
46
|
end
|
47
47
|
|
48
48
|
context "remote origin uses HTTP" do
|
49
49
|
let(:origin_url) { 'https://github.com/reenhanced.spectacular/this-is-the.shit.git' }
|
50
|
-
it {
|
50
|
+
it { is_expected.to eq('this-is-the.shit') }
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -63,7 +63,7 @@ describe GitReflow::GitHelpers do
|
|
63
63
|
|
64
64
|
describe ".push_current_branch" do
|
65
65
|
subject { Gitacular.push_current_branch }
|
66
|
-
before { Gitacular.
|
66
|
+
before { allow(Gitacular).to receive(:current_branch).and_return('bingo') }
|
67
67
|
it { expect{ subject }.to have_run_command "git push origin bingo" }
|
68
68
|
end
|
69
69
|
|
@@ -76,7 +76,7 @@ describe GitReflow::GitHelpers do
|
|
76
76
|
let(:current_branch) { 'bananas' }
|
77
77
|
let(:destination_branch) { 'monkey-business' }
|
78
78
|
|
79
|
-
before { Gitacular.
|
79
|
+
before { allow(Gitacular).to receive(:current_branch).and_return(current_branch) }
|
80
80
|
subject { Gitacular.update_destination(destination_branch) }
|
81
81
|
|
82
82
|
it "updates the destination branch with the latest code from the remote repo" do
|
@@ -90,7 +90,7 @@ describe GitReflow::GitHelpers do
|
|
90
90
|
|
91
91
|
describe ".update_current_branch" do
|
92
92
|
subject { Gitacular.update_current_branch }
|
93
|
-
before { Gitacular.
|
93
|
+
before { allow(Gitacular).to receive(:current_branch).and_return('new-feature') }
|
94
94
|
|
95
95
|
it "updates the remote changes and pushes any local changes" do
|
96
96
|
expect { subject }.to have_run_commands_in_order [
|
@@ -100,64 +100,20 @@ describe GitReflow::GitHelpers do
|
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
103
|
-
describe ".
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
subject { Gitacular.merge_feature_branch(feature_branch, merge_options) }
|
103
|
+
describe ".update_feature_branch" do
|
104
|
+
options = {base: "base", remote: "remote"}
|
105
|
+
subject { Gitacular.update_feature_branch(options) }
|
106
|
+
before { allow(Gitacular).to receive(:current_branch).and_return('feature') }
|
109
107
|
|
110
|
-
it
|
108
|
+
it "calls the correct methods" do
|
111
109
|
expect { subject }.to have_run_commands_in_order [
|
112
|
-
|
113
|
-
"git
|
110
|
+
"git checkout base",
|
111
|
+
"git pull remote base",
|
112
|
+
"git checkout feature",
|
113
|
+
"git pull origin feature",
|
114
|
+
"git merge base"
|
114
115
|
]
|
115
116
|
end
|
116
|
-
|
117
|
-
context "providing a destination branch" do
|
118
|
-
let(:merge_options) {{ destination_branch: destination_branch }}
|
119
|
-
it { expect{ subject }.to have_run_command "git checkout #{destination_branch}" }
|
120
|
-
end
|
121
|
-
|
122
|
-
context "with a message" do
|
123
|
-
let(:merge_options) {{ message: "don't throw doo doo" }}
|
124
|
-
it "appends the message to the squashed commit message" do
|
125
|
-
Gitacular.should_receive(:append_to_squashed_commit_message).with("don't throw doo doo")
|
126
|
-
subject
|
127
|
-
end
|
128
|
-
|
129
|
-
context 'and a pull reuqest number' do
|
130
|
-
before { merge_options.merge!(pull_request_number: 3) }
|
131
|
-
it "appends the message to the squashed commit message" do
|
132
|
-
Gitacular.should_receive(:append_to_squashed_commit_message).with("don't throw doo doo\nCloses #3\n")
|
133
|
-
subject
|
134
|
-
end
|
135
|
-
end
|
136
|
-
end
|
137
|
-
|
138
|
-
context "with a pull request number" do
|
139
|
-
let(:merge_options) {{ pull_request_number: 3 }}
|
140
|
-
it "appends the message to the squashed commit message" do
|
141
|
-
Gitacular.should_receive(:append_to_squashed_commit_message).with("\nCloses #3\n")
|
142
|
-
subject
|
143
|
-
end
|
144
|
-
end
|
145
|
-
|
146
|
-
context "with one LGTM author" do
|
147
|
-
let(:merge_options) {{ lgtm_authors: 'codenamev' }}
|
148
|
-
it "appends the message to the squashed commit message" do
|
149
|
-
Gitacular.should_receive(:append_to_squashed_commit_message).with("\nLGTM given by: @#{merge_options[:lgtm_authors]}\n")
|
150
|
-
subject
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
context "with LGTM authors" do
|
155
|
-
let(:merge_options) {{ lgtm_authors: ['codenamev', 'nhance'] }}
|
156
|
-
it "appends the message to the squashed commit message" do
|
157
|
-
Gitacular.should_receive(:append_to_squashed_commit_message).with("\nLGTM given by: @#{merge_options[:lgtm_authors].join(', @')}\n")
|
158
|
-
subject
|
159
|
-
end
|
160
|
-
end
|
161
117
|
end
|
162
118
|
|
163
119
|
describe ".append_to_squashed_commit_message(message)" do
|
@@ -6,7 +6,7 @@ describe GitReflow::GitServer do
|
|
6
6
|
subject { GitReflow::GitServer.connect connection_options }
|
7
7
|
|
8
8
|
before do
|
9
|
-
GitReflow::GitServer::GitHub.
|
9
|
+
allow(GitReflow::GitServer::GitHub).to receive(:new)
|
10
10
|
|
11
11
|
module GitReflow::GitServer
|
12
12
|
class DummyHub < Base
|
@@ -27,8 +27,8 @@ describe GitReflow::GitServer do
|
|
27
27
|
describe '.connect(options)' do
|
28
28
|
it 'initializes a new GitHub server provider by default' do
|
29
29
|
stubbed_github = Class.new
|
30
|
-
stubbed_github.
|
31
|
-
GitReflow::GitServer::GitHub.
|
30
|
+
allow(stubbed_github).to receive(:authenticate)
|
31
|
+
expect(GitReflow::GitServer::GitHub).to receive(:new).and_return(stubbed_github)
|
32
32
|
subject
|
33
33
|
end
|
34
34
|
|
@@ -38,39 +38,39 @@ describe GitReflow::GitServer do
|
|
38
38
|
|
39
39
|
it 'initializes any server provider that has been implemented' do
|
40
40
|
dummy_hub = GitReflow::GitServer::DummyHub.new({})
|
41
|
-
GitReflow::GitServer::DummyHub.
|
42
|
-
subject.
|
43
|
-
$
|
41
|
+
expect(GitReflow::GitServer::DummyHub).to receive(:new).with(expected_server_options).and_return(dummy_hub)
|
42
|
+
expect(subject).to eq(dummy_hub)
|
43
|
+
expect($says).not_to include 'GitServer not setup for: DummyHub'
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
47
|
context 'provider not yet implemented' do
|
48
48
|
let(:connection_options) {{ provider: 'GitLab' }}
|
49
|
-
it { expect{ subject }.to
|
49
|
+
it { expect{ subject }.to have_said "Error connecting to GitLab: GitServer not setup for \"GitLab\"", :error }
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
53
|
describe '.current_provider' do
|
54
54
|
subject { GitReflow::GitServer.current_provider }
|
55
55
|
|
56
|
-
before { GitReflow::Config.
|
56
|
+
before { allow(GitReflow::Config).to receive(:get).with('reflow.git-server', local: true).and_return(nil) }
|
57
57
|
|
58
58
|
context 'Reflow setup to use GitHub' do
|
59
|
-
before { GitReflow::Config.
|
60
|
-
it {
|
59
|
+
before { allow(GitReflow::Config).to receive(:get).with('reflow.git-server').and_return('GitHub') }
|
60
|
+
it { is_expected.to eq(GitReflow::GitServer::GitHub) }
|
61
61
|
end
|
62
62
|
|
63
63
|
context 'Reflow has not yet been setup' do
|
64
|
-
before { GitReflow::Config.
|
65
|
-
it {
|
66
|
-
it { expect{ subject }.to
|
64
|
+
before { allow(GitReflow::Config).to receive(:get).with('reflow.git-server').and_return('') }
|
65
|
+
it { is_expected.to be_nil }
|
66
|
+
it { expect{ subject }.to have_said "Reflow hasn't been setup yet. Run 'git reflow setup' to continue", :notice }
|
67
67
|
end
|
68
68
|
|
69
69
|
context 'an unknown server provider is stored in the git config' do
|
70
|
-
before { GitReflow::Config.
|
70
|
+
before { allow(GitReflow::Config).to receive(:get).with('reflow.git-server').and_return('GittyUp') }
|
71
71
|
|
72
|
-
it {
|
73
|
-
it { expect{ subject }.to
|
72
|
+
it { is_expected.to be_nil }
|
73
|
+
it { expect{ subject }.to have_said "GitServer not setup for \"GittyUp\"", :error }
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
@@ -78,24 +78,24 @@ describe GitReflow::GitServer do
|
|
78
78
|
subject { GitReflow::GitServer.connection }
|
79
79
|
|
80
80
|
before do
|
81
|
-
GitReflow::Config.
|
82
|
-
GitReflow::Config.
|
81
|
+
allow(GitReflow::Config).to receive(:get).with('reflow.git-server', local: true).and_return(nil)
|
82
|
+
allow(GitReflow::Config).to receive(:get).with('reflow.git-server').and_return(nil)
|
83
83
|
end
|
84
84
|
|
85
|
-
it {
|
85
|
+
it { is_expected.to be_nil }
|
86
86
|
|
87
87
|
context "with a valid provider" do
|
88
|
-
before { GitReflow::Config.
|
88
|
+
before { allow(GitReflow::Config).to receive(:get).with('reflow.git-server').and_return('GitHub') }
|
89
89
|
it 'calls connection on the provider' do
|
90
|
-
GitReflow::GitServer::GitHub.
|
90
|
+
expect(GitReflow::GitServer::GitHub).to receive(:connection)
|
91
91
|
subject
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
95
|
context "with an invalid provider" do
|
96
|
-
before { GitReflow::Config.
|
97
|
-
it {
|
98
|
-
it { expect{ subject }.to
|
96
|
+
before { allow(GitReflow::Config).to receive(:get).with('reflow.git-server').and_return('GittyUp') }
|
97
|
+
it { is_expected.to be_nil }
|
98
|
+
it { expect{ subject }.to have_said "GitServer not setup for \"GittyUp\"", :error }
|
99
99
|
end
|
100
100
|
end
|
101
101
|
end
|
@@ -11,7 +11,7 @@ describe GitReflow::GitServer::BitBucket do
|
|
11
11
|
let(:remote_url) { "git@bitbucket.org:#{user}/#{repo}.git" }
|
12
12
|
|
13
13
|
before do
|
14
|
-
HighLine.
|
14
|
+
allow_any_instance_of(HighLine).to receive(:ask) do |terminal, question|
|
15
15
|
values = {
|
16
16
|
"Please enter your BitBucket username: " => user
|
17
17
|
}
|
@@ -25,7 +25,7 @@ describe GitReflow::GitServer::BitBucket do
|
|
25
25
|
subject { GitReflow::GitServer::BitBucket.new({}) }
|
26
26
|
|
27
27
|
it 'sets the reflow git server provider to BitBucket in the git config' do
|
28
|
-
GitReflow::Config.
|
28
|
+
expect(GitReflow::Config).to receive(:set).once.with('reflow.git-server', 'BitBucket', local: false)
|
29
29
|
subject
|
30
30
|
end
|
31
31
|
|
@@ -33,7 +33,7 @@ describe GitReflow::GitServer::BitBucket do
|
|
33
33
|
subject { GitReflow::GitServer::BitBucket.new(project_only: true) }
|
34
34
|
|
35
35
|
it 'sets the enterprise site and api as the site and api endpoints for the BitBucket provider in the git config' do
|
36
|
-
GitReflow::Config.
|
36
|
+
expect(GitReflow::Config).to receive(:set).once.with('reflow.git-server', 'BitBucket', local: true)
|
37
37
|
subject
|
38
38
|
end
|
39
39
|
end
|
@@ -52,27 +52,27 @@ describe GitReflow::GitServer::BitBucket do
|
|
52
52
|
allow(GitReflow::Config).to receive(:get).with('bitbucket.user', local: false).and_return(user)
|
53
53
|
allow(GitReflow::Config).to receive(:get).with('bitbucket.api-key', reload: true, local: false).and_return(api_key)
|
54
54
|
allow(GitReflow::Config).to receive(:get).with('reflow.local-projects', all: true).and_return('')
|
55
|
-
expect { subject }.to
|
56
|
-
expect { subject }.to
|
55
|
+
expect { subject }.to have_said "\nYour BitBucket account was already setup with:"
|
56
|
+
expect { subject }.to have_said "\tUser Name: #{user}"
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
60
|
context 'not yet authenticated' do
|
61
61
|
context 'with valid BitBucket credentials' do
|
62
62
|
before do
|
63
|
-
GitReflow::Config.
|
64
|
-
GitReflow::Config.
|
65
|
-
GitReflow::Config.
|
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
66
|
allow(GitReflow::Config).to receive(:get).with('bitbucket.api-key', reload: true).and_return('')
|
67
67
|
allow(GitReflow::Config).to receive(:get).with('remote.origin.url').and_return(remote_url)
|
68
68
|
allow(GitReflow::Config).to receive(:get).with('reflow.local-projects').and_return('')
|
69
|
-
bitbucket.
|
69
|
+
allow(bitbucket).to receive(:connection).and_return double(repos: double(all: []))
|
70
70
|
end
|
71
71
|
|
72
72
|
it "prompts me to setup an API key" do
|
73
|
-
expect { subject }.to
|
74
|
-
expect { subject }.to
|
75
|
-
expect { subject }.to
|
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
76
|
end
|
77
77
|
end
|
78
78
|
end
|
@@ -16,6 +16,8 @@ describe GitReflow::GitServer::GitHub::PullRequest do
|
|
16
16
|
let(:existing_pull_requests) { Fixture.new('pull_requests/pull_requests.json').to_json_hashie }
|
17
17
|
let(:existing_pull_commits) { Fixture.new('pull_requests/commits.json').to_json_hashie }
|
18
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[/[^:]+$/] }
|
19
21
|
let(:existing_pull_comments) {
|
20
22
|
Fixture.new('pull_requests/comments.json.erb',
|
21
23
|
repo_owner: user,
|
@@ -40,8 +42,8 @@ describe GitReflow::GitServer::GitHub::PullRequest do
|
|
40
42
|
"Please enter your Enterprise API endpoint (e.g. https://github.company.com/api/v3):" => enterprise_api
|
41
43
|
})
|
42
44
|
|
43
|
-
github.class.
|
44
|
-
github.class.
|
45
|
+
allow(github.class).to receive(:remote_user).and_return(user)
|
46
|
+
allow(github.class).to receive(:remote_repo_name).and_return(repo)
|
45
47
|
allow(GitReflow::GitServer::PullRequest).to receive(:approval_regex).and_return(/(?i-mx:lgtm|looks good to me|:\+1:|:thumbsup:|:shipit:)/)
|
46
48
|
end
|
47
49
|
|
@@ -49,8 +51,8 @@ describe GitReflow::GitServer::GitHub::PullRequest do
|
|
49
51
|
specify { expect(subject.number).to eql(existing_pull_request.number) }
|
50
52
|
specify { expect(subject.description).to eql(existing_pull_request.body) }
|
51
53
|
specify { expect(subject.html_url).to eql(existing_pull_request.html_url) }
|
52
|
-
specify { expect(subject.feature_branch_name).to eql(
|
53
|
-
specify { expect(subject.base_branch_name).to eql(
|
54
|
+
specify { expect(subject.feature_branch_name).to eql(feature_branch_name) }
|
55
|
+
specify { expect(subject.base_branch_name).to eql(base_branch_name) }
|
54
56
|
specify { expect(subject.build_status).to eql('success') }
|
55
57
|
specify { expect(subject.source_object).to eql(existing_pull_request) }
|
56
58
|
end
|
@@ -85,7 +87,7 @@ describe GitReflow::GitServer::GitHub::PullRequest do
|
|
85
87
|
context "Testing Nil Comments" do
|
86
88
|
before do
|
87
89
|
stub_request(:get, "https://api.github.com/repos/reenhanced/repo/pulls/2/comments?access_token=a1b2c3d4e5f6g7h8i9j0").
|
88
|
-
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.
|
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'}).
|
89
91
|
to_return(:status => 200, :body => "", :headers => {})
|
90
92
|
|
91
93
|
FakeGitHub.new(
|
@@ -16,7 +16,7 @@ describe GitReflow::GitServer::GitHub do
|
|
16
16
|
let(:existing_pull_requests) { Fixture.new('pull_requests/pull_requests.json').to_json_hashie }
|
17
17
|
|
18
18
|
before do
|
19
|
-
HighLine.
|
19
|
+
allow_any_instance_of(HighLine).to receive(:ask) do |terminal, question|
|
20
20
|
values = {
|
21
21
|
"Please enter your GitHub username: " => user,
|
22
22
|
"Please enter your GitHub password (we do NOT store this): " => password,
|
@@ -28,17 +28,17 @@ describe GitReflow::GitServer::GitHub do
|
|
28
28
|
return_value
|
29
29
|
end
|
30
30
|
|
31
|
-
github.class.
|
32
|
-
github.class.
|
31
|
+
allow(github.class).to receive(:remote_user).and_return(user)
|
32
|
+
allow(github.class).to receive(:remote_repo_name).and_return(repo)
|
33
33
|
end
|
34
34
|
|
35
35
|
describe '#initialize(options)' do
|
36
36
|
subject { GitReflow::GitServer::GitHub.new({}) }
|
37
37
|
|
38
38
|
it 'sets the reflow git server provider to GitHub in the git config' do
|
39
|
-
GitReflow::Config.
|
40
|
-
GitReflow::Config.
|
41
|
-
GitReflow::Config.
|
39
|
+
expect(GitReflow::Config).to receive(:set).once.with('github.site', github_site, local: false)
|
40
|
+
expect(GitReflow::Config).to receive(:set).once.with('github.endpoint', github_api_endpoint, local: false)
|
41
|
+
expect(GitReflow::Config).to receive(:set).once.with('reflow.git-server', 'GitHub', local: false)
|
42
42
|
subject
|
43
43
|
end
|
44
44
|
|
@@ -46,9 +46,9 @@ describe GitReflow::GitServer::GitHub do
|
|
46
46
|
subject { GitReflow::GitServer::GitHub.new(enterprise: true) }
|
47
47
|
|
48
48
|
it 'sets the enterprise site and api as the site and api endpoints for the GitHub provider in the git config' do
|
49
|
-
GitReflow::Config.
|
50
|
-
GitReflow::Config.
|
51
|
-
GitReflow::Config.
|
49
|
+
expect(GitReflow::Config).to receive(:set).once.with('github.site', enterprise_site, local: false)
|
50
|
+
expect(GitReflow::Config).to receive(:set).once.with('github.endpoint', enterprise_api, local: false)
|
51
|
+
expect(GitReflow::Config).to receive(:set).once.with('reflow.git-server', 'GitHub', local: false)
|
52
52
|
subject
|
53
53
|
end
|
54
54
|
|
@@ -58,13 +58,13 @@ describe GitReflow::GitServer::GitHub do
|
|
58
58
|
subject { GitReflow::GitServer::GitHub.new(project_only: true) }
|
59
59
|
|
60
60
|
before do
|
61
|
-
GitReflow::Config.
|
61
|
+
expect(GitReflow::Config).to receive(:get).twice.with('reflow.local-projects', all: true).and_return("#{user}/#{repo}")
|
62
62
|
end
|
63
63
|
|
64
64
|
it 'sets the enterprise site and api as the site and api endpoints for the GitHub provider in the git config' do
|
65
|
-
GitReflow::Config.
|
66
|
-
GitReflow::Config.
|
67
|
-
GitReflow::Config.
|
65
|
+
expect(GitReflow::Config).to receive(:set).once.with('github.site', github_site, local: true).and_call_original
|
66
|
+
expect(GitReflow::Config).to receive(:set).once.with('github.endpoint', github_api_endpoint, local: true)
|
67
|
+
expect(GitReflow::Config).to receive(:set).once.with('reflow.git-server', 'GitHub', local: true)
|
68
68
|
subject
|
69
69
|
end
|
70
70
|
end
|
@@ -73,32 +73,32 @@ describe GitReflow::GitServer::GitHub do
|
|
73
73
|
|
74
74
|
describe '#authenticate' do
|
75
75
|
let(:github) { GitReflow::GitServer::GitHub.new({}) }
|
76
|
-
let!(:github_api) { Github.new }
|
76
|
+
let!(:github_api) { Github::Client.new }
|
77
77
|
let(:github_authorizations) { Github::Client::Authorizations.new }
|
78
78
|
subject { github.authenticate }
|
79
79
|
|
80
80
|
before do
|
81
|
-
GitReflow::GitServer::GitHub.
|
82
|
-
github_api.
|
83
|
-
github_api.
|
84
|
-
github.
|
81
|
+
allow(GitReflow::GitServer::GitHub).to receive(:user).and_return('reenhanced')
|
82
|
+
allow(github_api).to receive(:oauth).and_return(github_authorizations)
|
83
|
+
allow(github_api).to receive_message_chain(:oauth, :all).and_return([])
|
84
|
+
allow(github).to receive(:run).with('hostname', loud: false).and_return(hostname)
|
85
85
|
end
|
86
86
|
|
87
87
|
context 'not yet authenticated' do
|
88
88
|
context 'with valid GitHub credentials' do
|
89
89
|
|
90
90
|
before do
|
91
|
-
Github.
|
92
|
-
github_authorizations.
|
93
|
-
github_api.oauth.
|
91
|
+
allow(Github::Client).to receive(:new).and_return(github_api)
|
92
|
+
allow(github_authorizations).to receive(:authenticated?).and_return(true)
|
93
|
+
allow(github_api.oauth).to receive(:create).with({ scopes: ['repo'], note: "git-reflow (#{hostname})" }).and_return(oauth_token_hash)
|
94
94
|
end
|
95
95
|
|
96
96
|
it "notifies the user of successful setup" do
|
97
|
-
expect { subject }.to
|
97
|
+
expect { subject }.to have_said "Your GitHub account was successfully setup!", :success
|
98
98
|
end
|
99
99
|
|
100
100
|
it "creates a new GitHub oauth token" do
|
101
|
-
github_api.oauth.
|
101
|
+
expect(github_api.oauth).to receive(:create).and_return(oauth_token_hash)
|
102
102
|
subject
|
103
103
|
end
|
104
104
|
|
@@ -133,7 +133,7 @@ describe GitReflow::GitServer::GitHub do
|
|
133
133
|
|
134
134
|
context "use GitHub enterprise account" do
|
135
135
|
let(:github) { GitReflow::GitServer::GitHub.new(enterprise: true) }
|
136
|
-
before { GitReflow::GitServer::GitHub.
|
136
|
+
before { allow(GitReflow::GitServer::GitHub).to receive(:@using_enterprise).and_return(true) }
|
137
137
|
it "creates git config keys for github connections" do
|
138
138
|
expect{ subject }.to have_run_command_silently "git config -f #{GitReflow::Config::CONFIG_FILE_PATH} --replace-all github.site \"#{enterprise_site}\""
|
139
139
|
expect{ subject }.to have_run_command_silently "git config -f #{GitReflow::Config::CONFIG_FILE_PATH} --replace-all github.endpoint \"#{enterprise_api}\""
|
@@ -152,11 +152,11 @@ describe GitReflow::GitServer::GitHub do
|
|
152
152
|
}}
|
153
153
|
|
154
154
|
before do
|
155
|
-
Github.
|
155
|
+
allow(Github::Client).to receive(:new).and_raise Github::Error::Unauthorized.new(unauthorized_error_response)
|
156
156
|
end
|
157
157
|
|
158
158
|
it "notifies user of invalid login details" do
|
159
|
-
expect { subject }.to
|
159
|
+
expect { subject }.to have_said "Github Authentication Error: #{Github::Error::Unauthorized.new(unauthorized_error_response).inspect}", :error
|
160
160
|
end
|
161
161
|
end
|
162
162
|
end
|
@@ -170,7 +170,7 @@ describe GitReflow::GitServer::GitHub do
|
|
170
170
|
subject { github.create_pull_request({ title: title, body: body, base: 'master' }) }
|
171
171
|
|
172
172
|
before do
|
173
|
-
github.class.
|
173
|
+
allow(github.class).to receive(:current_branch).and_return(current_branch)
|
174
174
|
allow(GitReflow).to receive(:git_server).and_return(github)
|
175
175
|
stub_request(:post, %r{/repos/#{user}/#{repo}/pulls}).
|
176
176
|
to_return(body: Fixture.new('pull_requests/pull_request.json').to_s, status: 201, headers: {content_type: "application/json; charset=utf-8"})
|
@@ -179,7 +179,7 @@ describe GitReflow::GitServer::GitHub do
|
|
179
179
|
specify { expect(subject.class.to_s).to eq('GitReflow::GitServer::GitHub::PullRequest') }
|
180
180
|
|
181
181
|
it 'creates a pull request using the remote user and repo' do
|
182
|
-
github_api.
|
182
|
+
allow(github_api).to receive(:pull_requests)
|
183
183
|
expect(github_api.pull_requests).to receive(:create).with(user, repo, title: title, body: body, head: "#{user}:#{current_branch}", base: 'master').and_return(existing_pull_request)
|
184
184
|
subject
|
185
185
|
end
|
@@ -189,25 +189,25 @@ describe GitReflow::GitServer::GitHub do
|
|
189
189
|
subject { github.find_open_pull_request({ from: 'new-feature', to: 'master'}) }
|
190
190
|
|
191
191
|
it 'looks for an open pull request matching the remote user/repo' do
|
192
|
-
subject.number.
|
192
|
+
expect(subject.number).to eq(existing_pull_requests.first.number)
|
193
193
|
end
|
194
194
|
|
195
195
|
context 'no pull request exists' do
|
196
196
|
before do
|
197
|
-
github_api.
|
198
|
-
github_api.pull_requests.
|
197
|
+
allow(github_api).to receive(:pull_requests)
|
198
|
+
expect(github_api.pull_requests).to receive(:all).and_return([])
|
199
199
|
end
|
200
|
-
it {
|
200
|
+
it { is_expected.to eq(nil) }
|
201
201
|
end
|
202
202
|
end
|
203
203
|
|
204
204
|
describe '#get_build_status(sha)' do
|
205
205
|
let(:sha) { '6dcb09b5b57875f334f61aebed695e2e4193db5e' }
|
206
206
|
subject { github.get_build_status(sha) }
|
207
|
-
before { github_api.
|
207
|
+
before { allow(github_api).to receive_message_chain(:repos, :statuses) }
|
208
208
|
|
209
209
|
it 'gets the latest build status for the given commit hash' do
|
210
|
-
github_api.repos.statuses.
|
210
|
+
expect(github_api.repos.statuses).to receive(:all).with(user, repo, sha).and_return([{ state: 'success'}])
|
211
211
|
subject
|
212
212
|
end
|
213
213
|
end
|