git_reflow 0.8.9 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.github/workflows/multi-ruby-tests.yml +33 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +2 -0
- data/.ruby-version +1 -0
- data/Appraisals +1 -6
- data/CHANGELOG.md +466 -348
- data/Gemfile.lock +99 -72
- data/LICENSE +20 -20
- data/README.md +481 -0
- data/Rakefile +15 -8
- data/Workflow +3 -0
- data/_config.yml +1 -0
- data/bin/console +7 -7
- data/bin/setup +6 -6
- data/exe/git-reflow +20 -36
- data/git_reflow.gemspec +26 -30
- data/lib/git_reflow.rb +3 -15
- data/lib/git_reflow/config.rb +48 -13
- data/lib/git_reflow/git_helpers.rb +69 -22
- data/lib/git_reflow/git_server.rb +63 -63
- data/lib/git_reflow/git_server/base.rb +68 -68
- 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 +53 -41
- data/lib/git_reflow/git_server/git_hub/pull_request.rb +16 -14
- data/lib/git_reflow/git_server/pull_request.rb +4 -2
- data/lib/git_reflow/merge_error.rb +9 -9
- data/lib/git_reflow/rspec.rb +3 -2
- data/lib/git_reflow/rspec/command_line_helpers.rb +23 -6
- data/lib/git_reflow/rspec/stub_helpers.rb +13 -13
- data/lib/git_reflow/rspec/workflow_helpers.rb +18 -0
- data/lib/git_reflow/sandbox.rb +16 -6
- data/lib/git_reflow/version.rb +1 -1
- data/lib/git_reflow/workflow.rb +304 -9
- data/lib/git_reflow/workflows/FlatMergeWorkflow +38 -0
- data/lib/git_reflow/workflows/core.rb +364 -238
- data/spec/fixtures/authentication_failure.json +3 -0
- data/spec/fixtures/awesome_workflow.rb +3 -7
- data/spec/fixtures/git/git_config +7 -7
- data/spec/fixtures/issues/comment.json.erb +27 -27
- data/spec/fixtures/issues/comments.json +29 -29
- data/spec/fixtures/issues/comments.json.erb +15 -15
- data/spec/fixtures/pull_requests/comment.json.erb +45 -45
- data/spec/fixtures/pull_requests/comments.json +47 -47
- data/spec/fixtures/pull_requests/comments.json.erb +15 -15
- data/spec/fixtures/pull_requests/commits.json +29 -29
- data/spec/fixtures/pull_requests/external_pull_request.json +145 -145
- data/spec/fixtures/pull_requests/pull_request.json +142 -142
- data/spec/fixtures/pull_requests/pull_request.json.erb +142 -142
- data/spec/fixtures/pull_requests/pull_request_branch_nonexistent_error.json +32 -0
- data/spec/fixtures/pull_requests/pull_request_exists_error.json +32 -32
- data/spec/fixtures/pull_requests/pull_requests.json +136 -136
- data/spec/fixtures/repositories/commit.json +53 -53
- data/spec/fixtures/repositories/commit.json.erb +53 -53
- data/spec/fixtures/repositories/commits.json.erb +13 -13
- data/spec/fixtures/repositories/statuses.json +31 -31
- data/spec/fixtures/users/user.json +32 -0
- data/spec/lib/git_reflow/git_helpers_spec.rb +115 -12
- 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 +10 -10
- data/spec/lib/git_reflow/git_server/git_hub_spec.rb +77 -3
- data/spec/lib/git_reflow/git_server/pull_request_spec.rb +9 -3
- 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 +304 -59
- data/spec/lib/git_reflow/workflows/core_spec.rb +225 -67
- data/spec/lib/git_reflow/workflows/flat_merge_spec.rb +71 -59
- data/spec/lib/git_reflow_spec.rb +2 -25
- data/spec/spec_helper.rb +3 -0
- data/spec/support/fixtures.rb +54 -54
- data/spec/support/github_helpers.rb +99 -109
- data/spec/support/mock_pull_request.rb +17 -17
- data/spec/support/web_mocks.rb +39 -39
- metadata +51 -74
- data/README.rdoc +0 -461
- data/circle.yml +0 -26
- data/lib/git_reflow/commands/deliver.rb +0 -10
- data/lib/git_reflow/commands/refresh.rb +0 -20
- data/lib/git_reflow/commands/review.rb +0 -13
- data/lib/git_reflow/commands/setup.rb +0 -11
- data/lib/git_reflow/commands/stage.rb +0 -9
- data/lib/git_reflow/commands/start.rb +0 -18
- data/lib/git_reflow/commands/status.rb +0 -7
- data/lib/git_reflow/os_detector.rb +0 -23
- data/lib/git_reflow/workflows/flat_merge.rb +0 -10
- data/spec/fixtures/workflow_with_super.rb +0 -8
@@ -1,59 +1,71 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe 'FlatMerge' do
|
4
|
-
let(:
|
5
|
-
let(:
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
allow(GitReflow
|
10
|
-
allow(GitReflow
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
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
|
-
|
29
|
-
|
30
|
-
allow(
|
31
|
-
allow(GitReflow
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'FlatMerge' do
|
4
|
+
let(:mergable_pr) { double(good_to_merge?: true, merge!: true) }
|
5
|
+
let(:git_server) { double(find_open_pull_request: mergable_pr) }
|
6
|
+
|
7
|
+
before do
|
8
|
+
allow(GitReflow::Config).to receive(:get).and_call_original
|
9
|
+
allow(GitReflow).to receive(:git_server).and_return(git_server)
|
10
|
+
allow(GitReflow).to receive(:status)
|
11
|
+
# Makes sure we are loading the right workflow
|
12
|
+
workflow_path = File.join(File.expand_path("../../../../../lib/git_reflow/workflows", __FILE__), "FlatMergeWorkflow")
|
13
|
+
use_workflow(workflow_path)
|
14
|
+
end
|
15
|
+
|
16
|
+
after { GitReflow::Workflow.reset! }
|
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(File).to receive(:read).and_call_original
|
29
|
+
allow_any_instance_of(GitReflow::GitServer::PullRequest).to receive(:deliver?).and_return(false)
|
30
|
+
allow(GitReflow::Workflows::Core).to receive(:status)
|
31
|
+
allow(GitReflow.git_server).to receive(:get_build_status).and_return(Struct.new(:state, :description, :url, :target_url).new)
|
32
|
+
allow(GitReflow::GitServer::GitHub::PullRequest).to receive(:find_open).and_return(pr)
|
33
|
+
allow(pr).to receive(:good_to_merge?).and_return(true)
|
34
|
+
end
|
35
|
+
|
36
|
+
it "overrides squash merge in favor of flat merge" do
|
37
|
+
expect(pr).to receive(:merge!).with(
|
38
|
+
base: "master",
|
39
|
+
merge_method: "merge",
|
40
|
+
force: false,
|
41
|
+
skip_lgtm: false
|
42
|
+
)
|
43
|
+
subject
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "when force-merging or with bitbucket" do
|
48
|
+
let(:pr_response) { Fixture.new('pull_requests/external_pull_request.json').to_json_hashie }
|
49
|
+
let(:pr) { MockPullRequest.new(pr_response) }
|
50
|
+
|
51
|
+
subject { GitReflow.deliver force: true}
|
52
|
+
|
53
|
+
before do
|
54
|
+
allow(GitReflow.git_server).to receive(:find_open_pull_request).and_return(pr)
|
55
|
+
allow(pr).to receive(:good_to_merge?).and_return(true)
|
56
|
+
allow(GitReflow::Workflows::Core).to receive(:status)
|
57
|
+
end
|
58
|
+
|
59
|
+
it "doesn't squash merge" do
|
60
|
+
expect(pr).to receive(:merge!).with(
|
61
|
+
base: "master",
|
62
|
+
merge_method: "merge",
|
63
|
+
force: true,
|
64
|
+
skip_lgtm: false
|
65
|
+
)
|
66
|
+
subject
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
data/spec/lib/git_reflow_spec.rb
CHANGED
@@ -17,24 +17,11 @@ describe GitReflow do
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
describe ".default_editor" do
|
21
|
-
subject { GitReflow.default_editor }
|
22
|
-
|
23
|
-
context "when the environment has EDITOR set" do
|
24
|
-
before { allow(ENV).to receive(:[]).with('EDITOR').and_return('emacs') }
|
25
|
-
specify { expect( subject ).to eql('emacs') }
|
26
|
-
end
|
27
|
-
|
28
|
-
context "when the environment has no EDITOR set" do
|
29
|
-
before { allow(ENV).to receive(:[]).with('EDITOR').and_return(nil) }
|
30
|
-
specify { expect( subject ).to eql('vi') }
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
20
|
describe ".git_server" do
|
35
21
|
subject { GitReflow.git_server }
|
36
22
|
|
37
23
|
before do
|
24
|
+
allow(GitReflow::Config).to receive(:get)
|
38
25
|
allow(GitReflow::Config).to receive(:get).with('reflow.git-server').and_return('GitHub ')
|
39
26
|
end
|
40
27
|
|
@@ -52,23 +39,13 @@ describe GitReflow do
|
|
52
39
|
end
|
53
40
|
|
54
41
|
context "when a workflow is set" do
|
55
|
-
|
56
42
|
it "calls the defined workflow methods instead of the default core" do
|
57
43
|
workflow_path = File.join(File.expand_path("../../fixtures", __FILE__), "/awesome_workflow.rb")
|
58
44
|
allow(GitReflow::Config).to receive(:get).with("reflow.workflow").and_return(workflow_path)
|
45
|
+
expect(GitReflow::Workflows::Core).to receive(:load_raw_workflow).with(File.read(workflow_path)).and_call_original
|
59
46
|
|
60
|
-
expect(GitReflow.workflow).to eql(GitReflow::Workflow::AwesomeWorkflow)
|
61
47
|
expect{ subject.start }.to have_said "Awesome."
|
62
48
|
end
|
63
|
-
|
64
|
-
it "the workflow can call super" do
|
65
|
-
workflow_path = File.join(File.expand_path("../../fixtures", __FILE__), "/workflow_with_super.rb")
|
66
|
-
allow(GitReflow::Config).to receive(:get).with("reflow.workflow").and_return(workflow_path)
|
67
|
-
|
68
|
-
expect(GitReflow.workflow).to eql(GitReflow::Workflow::WorkflowWithSuper)
|
69
|
-
expect{ subject.start }.to have_said "Super."
|
70
|
-
expect{ subject.start }.to have_said "usage: git-reflow start [new-branch-name]", :error
|
71
|
-
end
|
72
49
|
end
|
73
50
|
|
74
51
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -16,6 +16,7 @@ RSpec.configure do |config|
|
|
16
16
|
config.include GitReflow::RSpec::CommandLineHelpers
|
17
17
|
config.include GithubHelpers
|
18
18
|
config.include GitReflow::RSpec::StubHelpers
|
19
|
+
config.include GitReflow::RSpec::WorkflowHelpers
|
19
20
|
|
20
21
|
config.expect_with :rspec do |c|
|
21
22
|
c.syntax = [:should, :expect]
|
@@ -28,6 +29,8 @@ RSpec.configure do |config|
|
|
28
29
|
config.before(:each) do
|
29
30
|
WebMock.reset!
|
30
31
|
stub_command_line
|
32
|
+
suppress_loading_of_external_workflows
|
33
|
+
GitReflow::Workflow.reset!
|
31
34
|
allow_message_expectations_on_nil
|
32
35
|
end
|
33
36
|
|
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(:
|
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(:git_server).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
|