git_reflow 0.8.9 → 0.8.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.ruby-version +1 -0
- data/Gemfile.lock +41 -44
- data/README.md +461 -0
- data/_config.yml +1 -0
- data/circle.yml +5 -5
- data/exe/git-reflow +36 -36
- data/git_reflow.gemspec +6 -11
- data/lib/git_reflow.rb +0 -1
- data/lib/git_reflow/git_server.rb +63 -63
- data/lib/git_reflow/git_server/bit_bucket.rb +101 -101
- data/lib/git_reflow/git_server/bit_bucket/pull_request.rb +84 -84
- data/lib/git_reflow/git_server/git_hub.rb +1 -1
- data/lib/git_reflow/git_server/git_hub/pull_request.rb +1 -1
- data/lib/git_reflow/rspec.rb +2 -2
- data/lib/git_reflow/version.rb +1 -1
- data/lib/git_reflow/workflows/core.rb +235 -238
- data/lib/git_reflow/workflows/flat_merge.rb +10 -10
- data/spec/fixtures/awesome_workflow.rb +7 -7
- data/spec/fixtures/workflow_with_super.rb +8 -8
- data/spec/lib/git_reflow/git_server/bit_bucket_spec.rb +81 -81
- data/spec/lib/git_reflow/git_server/git_hub/pull_request_spec.rb +4 -4
- data/spec/lib/git_reflow/git_server_spec.rb +101 -101
- data/spec/lib/git_reflow/sandbox_spec.rb +1 -1
- data/spec/lib/git_reflow/workflow_spec.rb +59 -59
- data/spec/lib/git_reflow/workflows/core_spec.rb +3 -4
- data/spec/lib/git_reflow/workflows/flat_merge_spec.rb +60 -59
- data/spec/support/fixtures.rb +54 -54
- data/spec/support/github_helpers.rb +99 -109
- metadata +17 -39
- data/README.rdoc +0 -461
- data/lib/git_reflow/os_detector.rb +0 -23
@@ -36,8 +36,7 @@ describe GitReflow::Workflows::Core do
|
|
36
36
|
context "git-reflow has not been setup before" do
|
37
37
|
it "notifies the user of global setup" do
|
38
38
|
expect { subject }.to have_said "We'll walk you through setting up git-reflow's defaults for all your projects.", :notice
|
39
|
-
expect { subject }.to have_said "In the future, you can run \`git-reflow setup\` from the root of any project you want to setup differently.", :notice
|
40
|
-
expect { subject }.to have_said "To adjust these settings globally, you can run \`git-reflow setup --global\`.", :notice
|
39
|
+
expect { subject }.to have_said "In the future, you can run \`git-reflow setup --local\` from the root of any project you want to setup differently.", :notice
|
41
40
|
end
|
42
41
|
|
43
42
|
it "creates a .gitconfig.reflow file and includes it in the user's global git config" do
|
@@ -590,7 +589,7 @@ describe GitReflow::Workflows::Core do
|
|
590
589
|
|
591
590
|
before do
|
592
591
|
allow(existing_gh_pull_request).to receive(:good_to_merge?).with(force: true).and_return(true)
|
593
|
-
allow(existing_gh_pull_request).to receive(:merge!).with(force: true, base: 'master'
|
592
|
+
allow(existing_gh_pull_request).to receive(:merge!).with(force: true, base: 'master')
|
594
593
|
end
|
595
594
|
|
596
595
|
it "displays the status of the PR" do
|
@@ -599,7 +598,7 @@ describe GitReflow::Workflows::Core do
|
|
599
598
|
end
|
600
599
|
|
601
600
|
it "merges the feature branch anyway" do
|
602
|
-
expect(existing_gh_pull_request).to receive(:merge!).with(force: true, base: 'master'
|
601
|
+
expect(existing_gh_pull_request).to receive(:merge!).with(force: true, base: 'master')
|
603
602
|
subject
|
604
603
|
end
|
605
604
|
end
|
@@ -1,59 +1,60 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'FlatMerge' do
|
4
|
-
let(:workflow_path) { File.join(File.expand_path("../../../../../lib/git_reflow/workflows", __FILE__), "/flat_merge.rb") }
|
5
|
-
let(:mergable_pr) { double(good_to_merge?: true, merge!: true) }
|
6
|
-
let(:git_server) { double(find_open_pull_request: mergable_pr) }
|
7
|
-
|
8
|
-
before do
|
9
|
-
allow(GitReflow::Config).to receive(:get).
|
10
|
-
allow(GitReflow::Config).to receive(:get).with("reflow.workflow").and_return(workflow_path)
|
11
|
-
allow(GitReflow).to receive(:git_server).and_return(git_server)
|
12
|
-
allow(GitReflow).to receive(:status)
|
13
|
-
end
|
14
|
-
|
15
|
-
# Makes sure we are loading the right workflow
|
16
|
-
specify { expect( GitReflow.workflow ).to eql(GitReflow::Workflow::FlatMerge) }
|
17
|
-
|
18
|
-
context ".deliver" do
|
19
|
-
subject { GitReflow.deliver }
|
20
|
-
|
21
|
-
context "with Github" do
|
22
|
-
let(:github_pr) { Fixture.new('pull_requests/external_pull_request.json').to_json_hashie }
|
23
|
-
let(:pr) { GitReflow::GitServer::GitHub::PullRequest.new(github_pr) }
|
24
|
-
let(:github) { stub_github_with }
|
25
|
-
let!(:github_api) { github.connection }
|
26
|
-
|
27
|
-
before do
|
28
|
-
allow_any_instance_of(GitReflow::GitServer::PullRequest).to receive(:deliver?).and_return(false)
|
29
|
-
allow(GitReflow::
|
30
|
-
allow(
|
31
|
-
allow(GitReflow::
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
let(:
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
allow(
|
49
|
-
allow(
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'FlatMerge' do
|
4
|
+
let(:workflow_path) { File.join(File.expand_path("../../../../../lib/git_reflow/workflows", __FILE__), "/flat_merge.rb") }
|
5
|
+
let(:mergable_pr) { double(good_to_merge?: true, merge!: true) }
|
6
|
+
let(:git_server) { double(find_open_pull_request: mergable_pr) }
|
7
|
+
|
8
|
+
before do
|
9
|
+
allow(GitReflow::Config).to receive(:get).and_call_original
|
10
|
+
allow(GitReflow::Config).to receive(:get).with("reflow.workflow").and_return(workflow_path)
|
11
|
+
allow(GitReflow).to receive(:git_server).and_return(git_server)
|
12
|
+
allow(GitReflow).to receive(:status)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Makes sure we are loading the right workflow
|
16
|
+
specify { expect( GitReflow.workflow ).to eql(GitReflow::Workflow::FlatMerge) }
|
17
|
+
|
18
|
+
context ".deliver" do
|
19
|
+
subject { GitReflow.deliver }
|
20
|
+
|
21
|
+
context "with Github" do
|
22
|
+
let(:github_pr) { Fixture.new('pull_requests/external_pull_request.json').to_json_hashie }
|
23
|
+
let(:pr) { GitReflow::GitServer::GitHub::PullRequest.new(github_pr) }
|
24
|
+
let(:github) { stub_github_with }
|
25
|
+
let!(:github_api) { github.connection }
|
26
|
+
|
27
|
+
before do
|
28
|
+
allow_any_instance_of(GitReflow::GitServer::PullRequest).to receive(:deliver?).and_return(false)
|
29
|
+
allow(GitReflow::Workflows::Core).to receive(:status)
|
30
|
+
allow(GitReflow.git_server).to receive(:get_build_status).and_return(Struct.new(:state, :description, :url, :target_url).new)
|
31
|
+
allow(GitReflow::GitServer::GitHub::PullRequest).to receive(:find_open).and_return(pr)
|
32
|
+
allow(pr).to receive(:good_to_merge?).and_return(true)
|
33
|
+
end
|
34
|
+
|
35
|
+
it "overrides squash merge in favor of flat merge" do
|
36
|
+
expect(pr).to receive(:merge!).with(base: 'master', squash: false)
|
37
|
+
subject
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context "when force-merging or with bitbucket" do
|
42
|
+
let(:pr_response) { Fixture.new('pull_requests/external_pull_request.json').to_json_hashie }
|
43
|
+
let(:pr) { MockPullRequest.new(pr_response) }
|
44
|
+
|
45
|
+
subject { GitReflow.deliver force: true}
|
46
|
+
|
47
|
+
before do
|
48
|
+
allow(GitReflow.git_server).to receive(:find_open_pull_request).and_return(pr)
|
49
|
+
allow(pr).to receive(:good_to_merge?).and_return(true)
|
50
|
+
allow(GitReflow::Workflows::Core).to receive(:status)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "doesn't squash merge" do
|
54
|
+
expect(pr).to receive(:merge!).with(base: 'master', squash: false, force: true)
|
55
|
+
subject
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
data/spec/support/fixtures.rb
CHANGED
@@ -1,54 +1,54 @@
|
|
1
|
-
# ERB parsing credit:
|
2
|
-
# http://stackoverflow.com/questions/8954706/render-an-erb-template-with-values-from-a-hash/9734736#9734736
|
3
|
-
|
4
|
-
require 'erb'
|
5
|
-
require 'ostruct'
|
6
|
-
|
7
|
-
class Fixture
|
8
|
-
|
9
|
-
|
10
|
-
def initialize(file, locals = {})
|
11
|
-
@file = fixture(file)
|
12
|
-
@locals = locals
|
13
|
-
end
|
14
|
-
|
15
|
-
def fixture_path
|
16
|
-
File.expand_path("../../fixtures", __FILE__)
|
17
|
-
end
|
18
|
-
|
19
|
-
def fixture(file)
|
20
|
-
File.new(File.join(fixture_path, "/", file))
|
21
|
-
end
|
22
|
-
|
23
|
-
def to_s
|
24
|
-
if File.extname(file) == ".erb"
|
25
|
-
ERB.new(template_file_content).result(OpenStruct.new(locals).instance_eval { binding }).to_s
|
26
|
-
else
|
27
|
-
template_file_content.to_s
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def to_json
|
32
|
-
if File.extname(file) == ".erb"
|
33
|
-
rendered_file = ERB.new(template_file_content).result(OpenStruct.new(locals).instance_eval { binding })
|
34
|
-
JSON.parse(rendered_file)
|
35
|
-
else
|
36
|
-
JSON.parse(template_file_content)
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def to_json_hashie
|
41
|
-
json = self.to_json
|
42
|
-
if json.is_a? Array
|
43
|
-
json.map {|json_object| Hashie::Mash.new json_object }
|
44
|
-
else
|
45
|
-
Hashie::Mash.new json
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
private
|
50
|
-
|
51
|
-
def template_file_content
|
52
|
-
@file_content ||= file.read
|
53
|
-
end
|
54
|
-
end
|
1
|
+
# ERB parsing credit:
|
2
|
+
# http://stackoverflow.com/questions/8954706/render-an-erb-template-with-values-from-a-hash/9734736#9734736
|
3
|
+
|
4
|
+
require 'erb'
|
5
|
+
require 'ostruct'
|
6
|
+
|
7
|
+
class Fixture
|
8
|
+
attr_reader :file, :locals
|
9
|
+
|
10
|
+
def initialize(file, locals = {})
|
11
|
+
@file = fixture(file)
|
12
|
+
@locals = locals
|
13
|
+
end
|
14
|
+
|
15
|
+
def fixture_path
|
16
|
+
File.expand_path("../../fixtures", __FILE__)
|
17
|
+
end
|
18
|
+
|
19
|
+
def fixture(file)
|
20
|
+
File.new(File.join(fixture_path, "/", file))
|
21
|
+
end
|
22
|
+
|
23
|
+
def to_s
|
24
|
+
if File.extname(file) == ".erb"
|
25
|
+
ERB.new(template_file_content).result(OpenStruct.new(locals).instance_eval { binding }).to_s
|
26
|
+
else
|
27
|
+
template_file_content.to_s
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def to_json
|
32
|
+
if File.extname(file) == ".erb"
|
33
|
+
rendered_file = ERB.new(template_file_content).result(OpenStruct.new(locals).instance_eval { binding })
|
34
|
+
JSON.parse(rendered_file)
|
35
|
+
else
|
36
|
+
JSON.parse(template_file_content)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_json_hashie
|
41
|
+
json = self.to_json
|
42
|
+
if json.is_a? Array
|
43
|
+
json.map {|json_object| Hashie::Mash.new json_object }
|
44
|
+
else
|
45
|
+
Hashie::Mash.new json
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def template_file_content
|
52
|
+
@file_content ||= file.read
|
53
|
+
end
|
54
|
+
end
|
@@ -1,109 +1,99 @@
|
|
1
|
-
$LOAD_PATH << 'lib'
|
2
|
-
require 'git_reflow'
|
3
|
-
require 'github_api'
|
4
|
-
require 'spec_helper'
|
5
|
-
|
6
|
-
module GithubHelpers
|
7
|
-
def stub_github_with(options = {})
|
8
|
-
|
9
|
-
hostname = options[:hostname] || 'hostname.local'
|
10
|
-
api_endpoint = options[:api_endpoint] || "https://api.github.com"
|
11
|
-
site_url = options[:site_url] || "https://github.com"
|
12
|
-
user = options[:user] || 'reenhanced'
|
13
|
-
password = options[:passwordl] || 'shazam'
|
14
|
-
oauth_token_hash = Hashie::Mash.new({ token: 'a1b2c3d4e5f6g7h8i9j0', note: 'git-reflow (hostname.local)'})
|
15
|
-
repo = options[:repo] || 'repo'
|
16
|
-
branch = options[:branch] || 'new-feature'
|
17
|
-
pull = options[:pull]
|
18
|
-
|
19
|
-
allow_any_instance_of(HighLine).to receive(:ask) do |terminal, question|
|
20
|
-
values = {
|
21
|
-
"Please enter your GitHub username: " => user,
|
22
|
-
"Please enter your GitHub password (we do NOT store this): " => password,
|
23
|
-
"Please enter your Enterprise site URL (e.g. https://github.company.com):" => enterprise_site,
|
24
|
-
"Please enter your Enterprise API endpoint (e.g. https://github.company.com/api/v3):" => enterprise_api
|
25
|
-
}
|
26
|
-
return_value = values[question] || values[terminal]
|
27
|
-
question = ""
|
28
|
-
return_value
|
29
|
-
end
|
30
|
-
|
31
|
-
github = Github.new do |config|
|
32
|
-
config.oauth_token = oauth_token_hash.token
|
33
|
-
config.endpoint = api_endpoint
|
34
|
-
config.site = site_url
|
35
|
-
config.adapter = :net_http
|
36
|
-
config.ssl = {:verify => false}
|
37
|
-
end
|
38
|
-
|
39
|
-
stub_request(:get, "#{api_endpoint}/authorizations?").to_return(:body => [oauth_token_hash].to_json, status: 200, headers: {})
|
40
|
-
allow(Github::Client).to receive(:new).and_return(github)
|
41
|
-
allow(GitReflow).to receive(:push_current_branch).and_return(true)
|
42
|
-
allow(GitReflow).to receive(:github).and_return(github)
|
43
|
-
allow(GitReflow).to receive(:current_branch).and_return(branch)
|
44
|
-
allow(GitReflow).to receive(:remote_repo_name).and_return(repo)
|
45
|
-
allow(GitReflow).to receive(:remote_user).and_return(user)
|
46
|
-
allow(GitReflow).to receive(:fetch_destination).and_return(true)
|
47
|
-
allow(GitReflow).to receive(:update_destination).and_return(true)
|
48
|
-
|
49
|
-
allow_any_instance_of(GitReflow::GitServer::GitHub).to receive(:run).with('hostname', loud: false).and_return(hostname)
|
50
|
-
github_server = GitReflow::GitServer::GitHub.new
|
51
|
-
allow(github_server.class).to receive(:user).and_return(user)
|
52
|
-
allow(github_server.class).to receive(:oauth_token).and_return(oauth_token_hash.token)
|
53
|
-
allow(github_server.class).to receive(:site_url).and_return(site_url)
|
54
|
-
allow(github_server.class).to receive(:api_endpoint).and_return(api_endpoint)
|
55
|
-
allow(github_server.class).to receive(:remote_user).and_return(user)
|
56
|
-
allow(github_server.class).to receive(:remote_repo).and_return(repo)
|
57
|
-
allow(github_server.class).to receive(:oauth_token).and_return(oauth_token_hash.token)
|
58
|
-
allow(github_server.class).to receive(:get_committed_time).and_return(Time.now)
|
59
|
-
|
60
|
-
allow(GitReflow).to receive(:git_server).and_return(github_server)
|
61
|
-
|
62
|
-
# Stubbing statuses for a given commit
|
63
|
-
#stub_request(:get, %r{#{GitReflow.git_server.class.api_endpoint}/repos/#{user}/commits/\w+}).
|
64
|
-
# to_return(:body => Fixture.new('repositories/commit.json.erb', repo_owner: user, repo_name: repo, author: user).to_json.to_s, :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
|
65
|
-
stub_request(:get, %r{/repos/#{user}/(#{repo}/)?commits/\w+/statuses}).
|
66
|
-
to_return(:body => Fixture.new('repositories/statuses.json').to_s, :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
|
67
|
-
|
68
|
-
if pull
|
69
|
-
# Stubbing review
|
70
|
-
stub_post("/repos/#{user}/#{repo}/pulls").
|
71
|
-
to_return(:body => pull.to_s, :status => 201, :headers => {:content_type => "application/json\; charset=utf-8"})
|
72
|
-
|
73
|
-
# Stubbing pull request finder
|
74
|
-
stub_get("/repos/#{user}/#{repo}/pulls/#{pull.number}").with(:query => {'access_token' => 'a1b2c3d4e5f6g7h8i9j0'}).
|
75
|
-
to_return(:body => Fixture.new('pull_requests/pull_request.json').to_s, :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
|
76
|
-
stub_get("/repos/#{user}/pulls").with(:query => {'access_token' => 'a1b2c3d4e5f6g7h8i9j0', 'base' => 'master', 'head' => "#{user}:#{branch}", 'state' => 'open'}).
|
77
|
-
to_return(:body => Fixture.new('pull_requests/pull_requests.json').to_s, :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
|
78
|
-
stub_get("/repos/#{user}/#{repo}/pulls").with(:query => {'access_token' => 'a1b2c3d4e5f6g7h8i9j0', 'base' => 'master', 'head' => "#{user}:#{branch}", 'state' => 'open'}).
|
79
|
-
to_return(:body => Fixture.new('pull_requests/pull_requests.json').to_s, :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
|
80
|
-
# Stubbing pull request comments
|
81
|
-
stub_get("/repos/#{user}/#{repo}/pulls/#{pull.number}/comments?").with(:query => {'access_token' => 'a1b2c3d4e5f6g7h8i9j0'}).
|
82
|
-
to_return(:body => Fixture.new('pull_requests/comments.json.erb', repo_owner: user, repo_name: repo, comments: [{author: user}], pull_request_number: pull.number).to_json.to_s, :status => 201, :headers => {'Accept' => 'application/vnd.github.v3+json,application/vnd.github.beta+json;q=0.5,application/json;q=0.1', :content_type => "application/json; charset=utf-8"})
|
83
|
-
stub_get("/repos/#{user}/pulls/#{pull.number}/comments?").with(:query => {'access_token' => 'a1b2c3d4e5f6g7h8i9j0'}).
|
84
|
-
to_return(:body => Fixture.new('pull_requests/comments.json.erb', repo_owner: user, repo_name: repo, comments: [{author: user}], pull_request_number: pull.number).to_s, :status => 201, :headers => {'Accept' => 'application/vnd.github.v3+json,application/vnd.github.beta+json;q=0.5,application/json;q=0.1', :content_type => "application/json; charset=utf-8"})
|
85
|
-
# Stubbing issue comments
|
86
|
-
stub_get("/repos/#{user}/issues/#{pull.number}/comments?").with(:query => {'access_token' => 'a1b2c3d4e5f6g7h8i9j0'}).
|
87
|
-
to_return(:body => Fixture.new('issues/comments.json.erb', repo_owner: user, repo_name: repo, comments: [{author: user}], pull_request_number: pull.number).to_s, :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
|
88
|
-
stub_get("/repos/#{user}/#{repo}/issues/#{pull.number}/comments?").with(:query => {'access_token' => 'a1b2c3d4e5f6g7h8i9j0'}).
|
89
|
-
to_return(:body => Fixture.new('issues/comments.json.erb', repo_owner: user, repo_name: repo, comments: [{author: user}], pull_request_number: pull.number).to_json.to_s, :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
|
90
|
-
# Stubbing pull request commits
|
91
|
-
stub_get("/repos/#{user}/#{repo}/pulls/#{pull.number}/commits").with(query: {"access_token" => "a1b2c3d4e5f6g7h8i9j0"}).
|
92
|
-
to_return(:body => Fixture.new("pull_requests/commits.json").to_s, status: 201, headers: {content_type: "application/json; charset=utf-8"})
|
93
|
-
stub_request(:get, %r{/repos/#{user}/commits/\w+}).with(query: {"access_token" => "a1b2c3d4e5f6g7h8i9j0"}).
|
94
|
-
to_return(:body => Fixture.new("repositories/commit.json").to_s, status: 201, headers: {content_type: "application/json; charset=utf-8"})
|
95
|
-
end
|
96
|
-
|
97
|
-
github_server
|
98
|
-
end
|
99
|
-
end
|
100
|
-
#
|
101
|
-
# the github_api gem does some overrides to Hash so we have to make sure
|
102
|
-
# this still works here...
|
103
|
-
class Hash
|
104
|
-
def except(*keys)
|
105
|
-
cpy = self.dup
|
106
|
-
keys.each { |key| cpy.delete(key) }
|
107
|
-
cpy
|
108
|
-
end
|
109
|
-
end
|
1
|
+
$LOAD_PATH << 'lib'
|
2
|
+
require 'git_reflow'
|
3
|
+
require 'github_api'
|
4
|
+
require 'spec_helper'
|
5
|
+
|
6
|
+
module GithubHelpers
|
7
|
+
def stub_github_with(options = {})
|
8
|
+
|
9
|
+
hostname = options[:hostname] || 'hostname.local'
|
10
|
+
api_endpoint = options[:api_endpoint] || "https://api.github.com"
|
11
|
+
site_url = options[:site_url] || "https://github.com"
|
12
|
+
user = options[:user] || 'reenhanced'
|
13
|
+
password = options[:passwordl] || 'shazam'
|
14
|
+
oauth_token_hash = Hashie::Mash.new({ token: 'a1b2c3d4e5f6g7h8i9j0', note: 'git-reflow (hostname.local)'})
|
15
|
+
repo = options[:repo] || 'repo'
|
16
|
+
branch = options[:branch] || 'new-feature'
|
17
|
+
pull = options[:pull]
|
18
|
+
|
19
|
+
allow_any_instance_of(HighLine).to receive(:ask) do |terminal, question|
|
20
|
+
values = {
|
21
|
+
"Please enter your GitHub username: " => user,
|
22
|
+
"Please enter your GitHub password (we do NOT store this): " => password,
|
23
|
+
"Please enter your Enterprise site URL (e.g. https://github.company.com):" => enterprise_site,
|
24
|
+
"Please enter your Enterprise API endpoint (e.g. https://github.company.com/api/v3):" => enterprise_api
|
25
|
+
}
|
26
|
+
return_value = values[question] || values[terminal]
|
27
|
+
question = ""
|
28
|
+
return_value
|
29
|
+
end
|
30
|
+
|
31
|
+
github = Github.new do |config|
|
32
|
+
config.oauth_token = oauth_token_hash.token
|
33
|
+
config.endpoint = api_endpoint
|
34
|
+
config.site = site_url
|
35
|
+
config.adapter = :net_http
|
36
|
+
config.ssl = {:verify => false}
|
37
|
+
end
|
38
|
+
|
39
|
+
stub_request(:get, "#{api_endpoint}/authorizations?").to_return(:body => [oauth_token_hash].to_json, status: 200, headers: {})
|
40
|
+
allow(Github::Client).to receive(:new).and_return(github)
|
41
|
+
allow(GitReflow).to receive(:push_current_branch).and_return(true)
|
42
|
+
allow(GitReflow).to receive(:github).and_return(github)
|
43
|
+
allow(GitReflow).to receive(:current_branch).and_return(branch)
|
44
|
+
allow(GitReflow).to receive(:remote_repo_name).and_return(repo)
|
45
|
+
allow(GitReflow).to receive(:remote_user).and_return(user)
|
46
|
+
allow(GitReflow).to receive(:fetch_destination).and_return(true)
|
47
|
+
allow(GitReflow).to receive(:update_destination).and_return(true)
|
48
|
+
|
49
|
+
allow_any_instance_of(GitReflow::GitServer::GitHub).to receive(:run).with('hostname', loud: false).and_return(hostname)
|
50
|
+
github_server = GitReflow::GitServer::GitHub.new
|
51
|
+
allow(github_server.class).to receive(:user).and_return(user)
|
52
|
+
allow(github_server.class).to receive(:oauth_token).and_return(oauth_token_hash.token)
|
53
|
+
allow(github_server.class).to receive(:site_url).and_return(site_url)
|
54
|
+
allow(github_server.class).to receive(:api_endpoint).and_return(api_endpoint)
|
55
|
+
allow(github_server.class).to receive(:remote_user).and_return(user)
|
56
|
+
allow(github_server.class).to receive(:remote_repo).and_return(repo)
|
57
|
+
allow(github_server.class).to receive(:oauth_token).and_return(oauth_token_hash.token)
|
58
|
+
allow(github_server.class).to receive(:get_committed_time).and_return(Time.now)
|
59
|
+
|
60
|
+
allow(GitReflow).to receive(:git_server).and_return(github_server)
|
61
|
+
|
62
|
+
# Stubbing statuses for a given commit
|
63
|
+
#stub_request(:get, %r{#{GitReflow.git_server.class.api_endpoint}/repos/#{user}/commits/\w+}).
|
64
|
+
# to_return(:body => Fixture.new('repositories/commit.json.erb', repo_owner: user, repo_name: repo, author: user).to_json.to_s, :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
|
65
|
+
stub_request(:get, %r{/repos/#{user}/(#{repo}/)?commits/\w+/statuses}).
|
66
|
+
to_return(:body => Fixture.new('repositories/statuses.json').to_s, :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
|
67
|
+
|
68
|
+
if pull
|
69
|
+
# Stubbing review
|
70
|
+
stub_post("/repos/#{user}/#{repo}/pulls").
|
71
|
+
to_return(:body => pull.to_s, :status => 201, :headers => {:content_type => "application/json\; charset=utf-8"})
|
72
|
+
|
73
|
+
# Stubbing pull request finder
|
74
|
+
stub_get("/repos/#{user}/#{repo}/pulls/#{pull.number}").with(:query => {'access_token' => 'a1b2c3d4e5f6g7h8i9j0'}).
|
75
|
+
to_return(:body => Fixture.new('pull_requests/pull_request.json').to_s, :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
|
76
|
+
stub_get("/repos/#{user}/pulls").with(:query => {'access_token' => 'a1b2c3d4e5f6g7h8i9j0', 'base' => 'master', 'head' => "#{user}:#{branch}", 'state' => 'open'}).
|
77
|
+
to_return(:body => Fixture.new('pull_requests/pull_requests.json').to_s, :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
|
78
|
+
stub_get("/repos/#{user}/#{repo}/pulls").with(:query => {'access_token' => 'a1b2c3d4e5f6g7h8i9j0', 'base' => 'master', 'head' => "#{user}:#{branch}", 'state' => 'open'}).
|
79
|
+
to_return(:body => Fixture.new('pull_requests/pull_requests.json').to_s, :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
|
80
|
+
# Stubbing pull request comments
|
81
|
+
stub_get("/repos/#{user}/#{repo}/pulls/#{pull.number}/comments?").with(:query => {'access_token' => 'a1b2c3d4e5f6g7h8i9j0'}).
|
82
|
+
to_return(:body => Fixture.new('pull_requests/comments.json.erb', repo_owner: user, repo_name: repo, comments: [{author: user}], pull_request_number: pull.number).to_json.to_s, :status => 201, :headers => {'Accept' => 'application/vnd.github.v3+json,application/vnd.github.beta+json;q=0.5,application/json;q=0.1', :content_type => "application/json; charset=utf-8"})
|
83
|
+
stub_get("/repos/#{user}/pulls/#{pull.number}/comments?").with(:query => {'access_token' => 'a1b2c3d4e5f6g7h8i9j0'}).
|
84
|
+
to_return(:body => Fixture.new('pull_requests/comments.json.erb', repo_owner: user, repo_name: repo, comments: [{author: user}], pull_request_number: pull.number).to_s, :status => 201, :headers => {'Accept' => 'application/vnd.github.v3+json,application/vnd.github.beta+json;q=0.5,application/json;q=0.1', :content_type => "application/json; charset=utf-8"})
|
85
|
+
# Stubbing issue comments
|
86
|
+
stub_get("/repos/#{user}/issues/#{pull.number}/comments?").with(:query => {'access_token' => 'a1b2c3d4e5f6g7h8i9j0'}).
|
87
|
+
to_return(:body => Fixture.new('issues/comments.json.erb', repo_owner: user, repo_name: repo, comments: [{author: user}], pull_request_number: pull.number).to_s, :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
|
88
|
+
stub_get("/repos/#{user}/#{repo}/issues/#{pull.number}/comments?").with(:query => {'access_token' => 'a1b2c3d4e5f6g7h8i9j0'}).
|
89
|
+
to_return(:body => Fixture.new('issues/comments.json.erb', repo_owner: user, repo_name: repo, comments: [{author: user}], pull_request_number: pull.number).to_json.to_s, :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
|
90
|
+
# Stubbing pull request commits
|
91
|
+
stub_get("/repos/#{user}/#{repo}/pulls/#{pull.number}/commits").with(query: {"access_token" => "a1b2c3d4e5f6g7h8i9j0"}).
|
92
|
+
to_return(:body => Fixture.new("pull_requests/commits.json").to_s, status: 201, headers: {content_type: "application/json; charset=utf-8"})
|
93
|
+
stub_request(:get, %r{/repos/#{user}/commits/\w+}).with(query: {"access_token" => "a1b2c3d4e5f6g7h8i9j0"}).
|
94
|
+
to_return(:body => Fixture.new("repositories/commit.json").to_s, status: 201, headers: {content_type: "application/json; charset=utf-8"})
|
95
|
+
end
|
96
|
+
|
97
|
+
github_server
|
98
|
+
end
|
99
|
+
end
|