git_reflow 0.8.6 → 0.8.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/CHANGELOG.md +348 -348
  4. data/Gemfile.lock +13 -15
  5. data/LICENSE +20 -20
  6. data/README.rdoc +461 -461
  7. data/Rakefile +8 -8
  8. data/bin/console +7 -7
  9. data/bin/setup +6 -6
  10. data/circle.yml +5 -5
  11. data/exe/git-reflow +36 -36
  12. data/git_reflow.gemspec +1 -1
  13. data/lib/git_reflow/commands/deliver.rb +10 -10
  14. data/lib/git_reflow/commands/refresh.rb +20 -20
  15. data/lib/git_reflow/commands/review.rb +13 -13
  16. data/lib/git_reflow/commands/setup.rb +11 -11
  17. data/lib/git_reflow/commands/stage.rb +9 -9
  18. data/lib/git_reflow/commands/start.rb +22 -22
  19. data/lib/git_reflow/commands/status.rb +7 -7
  20. data/lib/git_reflow/config.rb +9 -9
  21. data/lib/git_reflow/git_server/base.rb +68 -68
  22. data/lib/git_reflow/git_server/bit_bucket/pull_request.rb +84 -84
  23. data/lib/git_reflow/git_server/bit_bucket.rb +101 -101
  24. data/lib/git_reflow/git_server/git_hub/pull_request.rb +4 -1
  25. data/lib/git_reflow/git_server/pull_request.rb +11 -2
  26. data/lib/git_reflow/git_server.rb +63 -63
  27. data/lib/git_reflow/logger.rb +49 -0
  28. data/lib/git_reflow/merge_error.rb +9 -9
  29. data/lib/git_reflow/os_detector.rb +23 -23
  30. data/lib/git_reflow/rspec/command_line_helpers.rb +12 -8
  31. data/lib/git_reflow/rspec/stub_helpers.rb +13 -13
  32. data/lib/git_reflow/rspec.rb +2 -2
  33. data/lib/git_reflow/sandbox.rb +11 -6
  34. data/lib/git_reflow/version.rb +1 -1
  35. data/lib/git_reflow/workflow.rb +59 -59
  36. data/lib/git_reflow/workflows/core.rb +238 -238
  37. data/lib/git_reflow/workflows/flat_merge.rb +10 -10
  38. data/lib/git_reflow.rb +11 -0
  39. data/spec/fixtures/awesome_workflow.rb +7 -0
  40. data/spec/fixtures/git/git_config +7 -0
  41. data/spec/fixtures/issues/comment.json.erb +27 -0
  42. data/spec/fixtures/issues/comments.json +29 -0
  43. data/spec/fixtures/issues/comments.json.erb +15 -0
  44. data/spec/fixtures/pull_requests/comment.json.erb +45 -0
  45. data/spec/fixtures/pull_requests/comments.json +47 -0
  46. data/spec/fixtures/pull_requests/comments.json.erb +15 -0
  47. data/spec/fixtures/pull_requests/commits.json +29 -0
  48. data/spec/fixtures/pull_requests/external_pull_request.json +145 -0
  49. data/spec/fixtures/pull_requests/pull_request.json +142 -0
  50. data/spec/fixtures/pull_requests/pull_request.json.erb +142 -0
  51. data/spec/fixtures/pull_requests/pull_request_exists_error.json +32 -0
  52. data/spec/fixtures/pull_requests/pull_requests.json +136 -0
  53. data/spec/fixtures/repositories/commit.json +53 -0
  54. data/spec/fixtures/repositories/commit.json.erb +53 -0
  55. data/spec/fixtures/repositories/commits.json.erb +13 -0
  56. data/spec/fixtures/repositories/statuses.json +31 -0
  57. data/spec/fixtures/workflow_with_super.rb +8 -0
  58. data/spec/lib/git_reflow/config_spec.rb +74 -0
  59. data/spec/lib/git_reflow/git_helpers_spec.rb +182 -0
  60. data/spec/lib/git_reflow/git_server/bit_bucket_spec.rb +81 -0
  61. data/spec/lib/git_reflow/git_server/git_hub/pull_request_spec.rb +587 -0
  62. data/spec/lib/git_reflow/git_server/git_hub_spec.rb +221 -0
  63. data/spec/lib/git_reflow/git_server/pull_request_spec.rb +524 -0
  64. data/spec/lib/git_reflow/git_server_spec.rb +101 -0
  65. data/spec/lib/git_reflow/logger_spec.rb +18 -0
  66. data/spec/lib/git_reflow/sandbox_spec.rb +15 -0
  67. data/spec/lib/git_reflow/workflow_spec.rb +59 -0
  68. data/spec/lib/git_reflow/workflows/core_spec.rb +665 -0
  69. data/spec/lib/git_reflow/workflows/flat_merge_spec.rb +59 -0
  70. data/spec/lib/git_reflow_spec.rb +75 -0
  71. data/spec/spec_helper.rb +38 -0
  72. data/spec/support/fake_github.rb +128 -0
  73. data/spec/support/fixtures.rb +54 -0
  74. data/spec/support/github_helpers.rb +109 -0
  75. data/spec/support/mock_pull_request.rb +17 -0
  76. data/spec/support/web_mocks.rb +39 -0
  77. metadata +83 -6
@@ -0,0 +1,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_return('')
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::GitServer::GitHub::PullRequest).to receive(:find_open).and_return(pr)
30
+ allow(pr).to receive(:good_to_merge?).and_return(true)
31
+ allow(GitReflow::Workflows::Core).to receive(:status)
32
+ end
33
+
34
+ it "overrides squash merge in favor of flat merge" do
35
+ expect(pr).to receive(:merge!).with(base: 'master', squash: false)
36
+ subject
37
+ end
38
+ end
39
+
40
+ context "when force-merging or with bitbucket" do
41
+ let(:pr_response) { Fixture.new('pull_requests/external_pull_request.json').to_json_hashie }
42
+ let(:pr) { MockPullRequest.new(pr_response) }
43
+
44
+ subject { GitReflow.deliver force: true}
45
+
46
+ before do
47
+ allow(GitReflow.git_server).to receive(:find_open_pull_request).and_return(pr)
48
+ allow(pr).to receive(:good_to_merge?).and_return(true)
49
+ allow(GitReflow::Workflows::Core).to receive(:status)
50
+ end
51
+
52
+ it "doesn't squash merge" do
53
+ expect(pr).to receive(:merge!).with(base: 'master', squash: false, force: true, skip_lgtm: true)
54
+ subject
55
+ end
56
+ end
57
+ end
58
+
59
+ end
@@ -0,0 +1,75 @@
1
+ require 'spec_helper'
2
+
3
+ describe GitReflow do
4
+
5
+ describe ".logger" do
6
+ # Ignore memoization for tests
7
+ before { GitReflow.instance_variable_set("@logger", nil) }
8
+
9
+ it "initializes a new logger" do
10
+ expect(GitReflow::Logger).to receive(:new)
11
+ described_class.logger
12
+ end
13
+
14
+ it "allows for custom loggers" do
15
+ logger = described_class.logger("kenny-loggins.log")
16
+ expect(logger.instance_variable_get("@logdev").dev.path).to eq "kenny-loggins.log"
17
+ end
18
+ end
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
+ describe ".git_server" do
35
+ subject { GitReflow.git_server }
36
+
37
+ before do
38
+ allow(GitReflow::Config).to receive(:get).with('reflow.git-server').and_return('GitHub ')
39
+ end
40
+
41
+ it "attempts to connect to the provider" do
42
+ expect(GitReflow::GitServer).to receive(:connect).with(provider: 'GitHub', silent: true)
43
+ subject
44
+ end
45
+ end
46
+
47
+ context "aliases workflow commands" do
48
+ %w{deliver refresh review setup stage start status}.each do |command|
49
+ it "aliases the command to the workflow" do
50
+ expect( subject.respond_to?(command.to_sym) ).to be_truthy
51
+ end
52
+ end
53
+
54
+ context "when a workflow is set" do
55
+
56
+ it "calls the defined workflow methods instead of the default core" do
57
+ workflow_path = File.join(File.expand_path("../../fixtures", __FILE__), "/awesome_workflow.rb")
58
+ allow(GitReflow::Config).to receive(:get).with("reflow.workflow").and_return(workflow_path)
59
+
60
+ expect(GitReflow.workflow).to eql(GitReflow::Workflow::AwesomeWorkflow)
61
+ expect{ subject.start }.to have_said "Awesome."
62
+ 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
+ end
73
+
74
+ end
75
+ end
@@ -0,0 +1,38 @@
1
+ require 'rubygems'
2
+ require 'rspec'
3
+ require 'multi_json'
4
+ require 'webmock/rspec'
5
+ require 'pry'
6
+
7
+ $LOAD_PATH << 'lib'
8
+ require 'git_reflow'
9
+
10
+ require 'git_reflow/rspec'
11
+
12
+ Dir[File.expand_path('../support/**/*.rb', __FILE__)].each {|f| require f}
13
+
14
+ RSpec.configure do |config|
15
+ config.include WebMock::API
16
+ config.include GitReflow::RSpec::CommandLineHelpers
17
+ config.include GithubHelpers
18
+ config.include GitReflow::RSpec::StubHelpers
19
+
20
+ config.expect_with :rspec do |c|
21
+ c.syntax = [:should, :expect]
22
+ end
23
+
24
+ config.mock_with :rspec do |c|
25
+ c.syntax = [:should, :expect]
26
+ end
27
+
28
+ config.before(:each) do
29
+ WebMock.reset!
30
+ stub_command_line
31
+ allow_message_expectations_on_nil
32
+ end
33
+
34
+ config.after(:each) do
35
+ WebMock.reset!
36
+ reset_stubbed_command_line
37
+ end
38
+ end
@@ -0,0 +1,128 @@
1
+ require 'rspec/mocks'
2
+ require 'webmock'
3
+ require 'chronic'
4
+
5
+ class FakeGitHub
6
+ include WebMock::API
7
+
8
+ attr_accessor :repo_owner, :repo_name
9
+
10
+ DEFAULT_COMMIT_AUTHOR = "reenhanced".freeze
11
+ DEFAULT_COMMIT_TIME = "October 21, 2015 07:28:00".freeze
12
+
13
+ # EXAMPLE:
14
+ #
15
+ # FakeGitHub.new(repo_owner: user, repo_name: repo,
16
+ # pull_request: {
17
+ # number: existing_pull_request.number,
18
+ # comments: [{author: comment_author}]
19
+ # },
20
+ # issue: {
21
+ # comments: [{author: comment_author}]
22
+ # })
23
+ #
24
+ def initialize(repo_owner: nil, repo_name: nil, pull_request: {}, issue: {}, commits: [])
25
+ raise "FakeGitHub#new: repo_owner AND repo_name keywords are required" unless repo_owner and repo_name
26
+
27
+ self.repo_owner = repo_owner
28
+ self.repo_name = repo_name
29
+
30
+ stub_github_request(:pull_request, pull_request) if pull_request
31
+ stub_github_request(:issue, issue) if issue
32
+ stub_github_request(:commits, commits) if commits.any?
33
+
34
+ if pull_request and (issue.none? or !issue[:comments])
35
+ stub_github_request(:issue, pull_request.merge({comments: []}))
36
+ end
37
+
38
+ if pull_request and commits.none?
39
+ stub_github_request(:commits, [{
40
+ author: pull_request[:owner] || DEFAULT_COMMIT_AUTHOR,
41
+ created_at: Chronic.parse(DEFAULT_COMMIT_TIME)
42
+ }])
43
+ end
44
+
45
+ self
46
+ end
47
+
48
+ def stub_github_request(object_to_stub, object_data)
49
+ case object_to_stub
50
+ when :commits
51
+ commits_response = Fixture.new('repositories/commits.json.erb',
52
+ repo_owner: repo_owner,
53
+ repo_name: repo_name,
54
+ commits: object_data)
55
+ commits_response.to_json_hashie.each_with_index do |commit, index|
56
+ stub_request(:get, %r{/repos/#{self.repo_owner}/(#{self.repo_name}/)?commits/#{commit.sha}\?}).
57
+ to_return(
58
+ body: commit.to_json.to_s,
59
+ status: 201,
60
+ headers: {content_type: "application/json; charset=utf-8"})
61
+ stub_request(:get, %r{/repos/#{self.repo_owner}/commits\Z}).
62
+ to_return(
63
+ body: commits_response.to_s,
64
+ status: 201,
65
+ headers: {content_type: "application/json; charset=utf-8"})
66
+ end
67
+ when :issue
68
+ # Stubbing issue comments
69
+ if object_data[:comments]
70
+ stub_request(:get, %r{/repos/#{self.repo_owner}/(#{self.repo_name}/)?issues/#{object_data[:number] || 1}/comments}).
71
+ with(query: {'access_token' => 'a1b2c3d4e5f6g7h8i9j0'}).
72
+ to_return(body: Fixture.new('issues/comments.json.erb',
73
+ repo_owner: self.repo_owner,
74
+ repo_name: self.repo_name,
75
+ comments: object_data[:comments],
76
+ pull_request_number: object_data[:number] || 1,
77
+ body: object_data[:body] || 'Hammer time',
78
+ created_at: object_data[:created_at] || Chronic.parse(DEFAULT_COMMIT_TIME)).to_s,
79
+ status: 201,
80
+ headers: {content_type: "application/json; charset=utf-8"})
81
+ else
82
+ stub_request(:get, %r{/repos/#{self.repo_owner}/(#{self.repo_name}/)?issues/#{object_data[:number] || 1}/comments}).
83
+ with(query: {'access_token' => 'a1b2c3d4e5f6g7h8i9j0'}).
84
+ to_return(body: '[]', status: 201, headers: {content_type: "application/json; charset=utf-8"})
85
+ end
86
+ when :pull_request
87
+ # EXAMPLES
88
+ stubbed_pull_request_response = Fixture.new('pull_requests/pull_request.json.erb',
89
+ number: object_data[:number] || 1,
90
+ title: object_data[:title] || 'Please merge these changes',
91
+ body: object_data[:body] || 'Bone saw is ready.',
92
+ state: object_data[:state] || 'open',
93
+ owner: object_data[:owner] || 'octocat',
94
+ feature_repo_owner: object_data[:feature_repo_owner] || self.repo_owner,
95
+ feature_branch: object_data[:feature_branch] || 'new-feature',
96
+ base_branch: object_data[:base_branch] || 'master',
97
+ repo_owner: self.repo_owner,
98
+ repo_name: self.repo_name)
99
+
100
+ stub_request(:get, "#{GitReflow::GitServer::GitHub.api_endpoint}/repos/#{self.repo_owner}/#{self.repo_name}/pulls/#{object_data[:number]}").
101
+ with(query: {'access_token' => 'a1b2c3d4e5f6g7h8i9j0'}).
102
+ to_return(body: stubbed_pull_request_response.to_s, status: 201, headers: {content_type: "application/json; charset=utf-8"})
103
+ stub_request(:get, "#{GitReflow::GitServer::GitHub.api_endpoint}/repos/#{self.repo_owner}/#{self.repo_name}/pulls")
104
+ .with(:query => {'access_token' => 'a1b2c3d4e5f6g7h8i9j0', 'base' => object_data[:base_branch] || 'master', 'head' => "#{object_data[:feature_repo_owner] || self.repo_owner}:#{object_data[:feature_branch] || "new-feature"}", 'state' => object_data[:state] || 'open'}).
105
+ to_return(:body => "[#{stubbed_pull_request_response.to_s}]", :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
106
+
107
+ # Stubbing pull request comments
108
+ if object_data[:comments]
109
+ stub_request(:get, %r{/repos/#{self.repo_owner}/(#{self.repo_name}/)?pulls/#{object_data[:number] || 1}/comments}).
110
+ with(query: {'access_token' => 'a1b2c3d4e5f6g7h8i9j0'}).
111
+ to_return(body: Fixture.new('pull_requests/comments.json.erb',
112
+ repo_owner: self.repo_owner,
113
+ repo_name: self.repo_name,
114
+ comments: object_data[:comments],
115
+ pull_request_number: object_data[:number] || 1,
116
+ created_at: object_data[:created_at] || Chronic.parse(DEFAULT_COMMIT_TIME)).to_s,
117
+ status: 201,
118
+ headers: {content_type: "application/json; charset=utf-8"})
119
+ end
120
+
121
+ # Stubbing pull request commits
122
+ #stub_get(%r{#{GitReflow::GitServer::GitHub.api_endpoint}/repos/#{user}/#{repo}/pulls/#{existing_pull_request.number}/commits}).
123
+ # with(query: {"access_token" => "a1b2c3d4e5f6g7h8i9j0"}).
124
+ # to_return(:body => Fixture.new("pull_requests/commits.json").to_s, status: 201, headers: {content_type: "application/json; charset=utf-8"})
125
+ end
126
+ end
127
+ end
128
+
@@ -0,0 +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
+ attr_accessor :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
@@ -0,0 +1,109 @@
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
@@ -0,0 +1,17 @@
1
+ class MockPullRequest < GitReflow::GitServer::PullRequest
2
+ DESCRIPTION = "Bingo! Unity."
3
+ HTML_URL = "https://github.com/reenhanced/gitreflow/pulls/0"
4
+ FEATURE_BRANCH_NAME = "feature_branch"
5
+ BASE_BRANCH_NAME = "base"
6
+ NUMBER = 0
7
+
8
+ def initialize(attributes = Struct.new(:description, :html_url, :feature_branch_name, :base_branch_name, :number).new)
9
+ self.description = attributes.description || DESCRIPTION
10
+ self.html_url = attributes.html_url || HTML_URL
11
+ self.feature_branch_name = attributes.feature_branch_name || FEATURE_BRANCH_NAME
12
+ self.base_branch_name = attributes.base_branch_name || BASE_BRANCH_NAME
13
+ self.build = Build.new
14
+ self.number = attributes.number || NUMBER
15
+ self.source_object = attributes
16
+ end
17
+ end
@@ -0,0 +1,39 @@
1
+ def stub_get(path, endpoint = GitReflow.git_server.class.api_endpoint)
2
+ stub_request(:get, endpoint + path)
3
+ end
4
+
5
+ def stub_post(path, endpoint = GitReflow.git_server.class.api_endpoint)
6
+ stub_request(:post, endpoint + path)
7
+ end
8
+
9
+ def stub_patch(path, endpoint = Github.endpoint.to_s)
10
+ stub_request(:patch, endpoint + path)
11
+ end
12
+
13
+ def stub_put(path, endpoint = Github.endpoint.to_s)
14
+ stub_request(:put, endpoint + path)
15
+ end
16
+
17
+ def stub_delete(path, endpoint = Github.endpoint.to_s)
18
+ stub_request(:delete, endpoint + path)
19
+ end
20
+
21
+ def a_get(path, endpoint = Github.endpoint.to_s)
22
+ a_request(:get, endpoint + path)
23
+ end
24
+
25
+ def a_post(path, endpoint = Github.endpoint.to_s)
26
+ a_request(:post, endpoint + path)
27
+ end
28
+
29
+ def a_patch(path, endpoint = Github.endpoint.to_s)
30
+ a_request(:patch, endpoint + path)
31
+ end
32
+
33
+ def a_put(path, endpoint = Github.endpoint)
34
+ a_request(:put, endpoint + path)
35
+ end
36
+
37
+ def a_delete(path, endpoint = Github.endpoint)
38
+ a_request(:delete, endpoint + path)
39
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_reflow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.6
4
+ version: 0.8.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Valentino Stoll
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2017-03-28 00:00:00.000000000 Z
13
+ date: 2017-04-21 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: appraisal
@@ -158,14 +158,14 @@ dependencies:
158
158
  requirements:
159
159
  - - '='
160
160
  - !ruby/object:Gem::Version
161
- version: 2.14.0
161
+ version: 2.15.0
162
162
  type: :runtime
163
163
  prerelease: false
164
164
  version_requirements: !ruby/object:Gem::Requirement
165
165
  requirements:
166
166
  - - '='
167
167
  - !ruby/object:Gem::Version
168
- version: 2.14.0
168
+ version: 2.15.0
169
169
  - !ruby/object:Gem::Dependency
170
170
  name: highline
171
171
  requirement: !ruby/object:Gem::Requirement
@@ -282,6 +282,7 @@ files:
282
282
  - lib/git_reflow/git_server/git_hub.rb
283
283
  - lib/git_reflow/git_server/git_hub/pull_request.rb
284
284
  - lib/git_reflow/git_server/pull_request.rb
285
+ - lib/git_reflow/logger.rb
285
286
  - lib/git_reflow/merge_error.rb
286
287
  - lib/git_reflow/os_detector.rb
287
288
  - lib/git_reflow/rspec.rb
@@ -292,6 +293,44 @@ files:
292
293
  - lib/git_reflow/workflow.rb
293
294
  - lib/git_reflow/workflows/core.rb
294
295
  - lib/git_reflow/workflows/flat_merge.rb
296
+ - spec/fixtures/awesome_workflow.rb
297
+ - spec/fixtures/git/git_config
298
+ - spec/fixtures/issues/comment.json.erb
299
+ - spec/fixtures/issues/comments.json
300
+ - spec/fixtures/issues/comments.json.erb
301
+ - spec/fixtures/pull_requests/comment.json.erb
302
+ - spec/fixtures/pull_requests/comments.json
303
+ - spec/fixtures/pull_requests/comments.json.erb
304
+ - spec/fixtures/pull_requests/commits.json
305
+ - spec/fixtures/pull_requests/external_pull_request.json
306
+ - spec/fixtures/pull_requests/pull_request.json
307
+ - spec/fixtures/pull_requests/pull_request.json.erb
308
+ - spec/fixtures/pull_requests/pull_request_exists_error.json
309
+ - spec/fixtures/pull_requests/pull_requests.json
310
+ - spec/fixtures/repositories/commit.json
311
+ - spec/fixtures/repositories/commit.json.erb
312
+ - spec/fixtures/repositories/commits.json.erb
313
+ - spec/fixtures/repositories/statuses.json
314
+ - spec/fixtures/workflow_with_super.rb
315
+ - spec/lib/git_reflow/config_spec.rb
316
+ - spec/lib/git_reflow/git_helpers_spec.rb
317
+ - spec/lib/git_reflow/git_server/bit_bucket_spec.rb
318
+ - spec/lib/git_reflow/git_server/git_hub/pull_request_spec.rb
319
+ - spec/lib/git_reflow/git_server/git_hub_spec.rb
320
+ - spec/lib/git_reflow/git_server/pull_request_spec.rb
321
+ - spec/lib/git_reflow/git_server_spec.rb
322
+ - spec/lib/git_reflow/logger_spec.rb
323
+ - spec/lib/git_reflow/sandbox_spec.rb
324
+ - spec/lib/git_reflow/workflow_spec.rb
325
+ - spec/lib/git_reflow/workflows/core_spec.rb
326
+ - spec/lib/git_reflow/workflows/flat_merge_spec.rb
327
+ - spec/lib/git_reflow_spec.rb
328
+ - spec/spec_helper.rb
329
+ - spec/support/fake_github.rb
330
+ - spec/support/fixtures.rb
331
+ - spec/support/github_helpers.rb
332
+ - spec/support/mock_pull_request.rb
333
+ - spec/support/web_mocks.rb
295
334
  homepage: http://github.com/reenhanced/gitreflow
296
335
  licenses:
297
336
  - MIT
@@ -319,8 +358,46 @@ required_rubygems_version: !ruby/object:Gem::Requirement
319
358
  version: '0'
320
359
  requirements: []
321
360
  rubyforge_project:
322
- rubygems_version: 2.5.2
361
+ rubygems_version: 2.6.11
323
362
  signing_key:
324
363
  specification_version: 4
325
364
  summary: A better git process
326
- test_files: []
365
+ test_files:
366
+ - spec/fixtures/awesome_workflow.rb
367
+ - spec/fixtures/git/git_config
368
+ - spec/fixtures/issues/comment.json.erb
369
+ - spec/fixtures/issues/comments.json
370
+ - spec/fixtures/issues/comments.json.erb
371
+ - spec/fixtures/pull_requests/comment.json.erb
372
+ - spec/fixtures/pull_requests/comments.json
373
+ - spec/fixtures/pull_requests/comments.json.erb
374
+ - spec/fixtures/pull_requests/commits.json
375
+ - spec/fixtures/pull_requests/external_pull_request.json
376
+ - spec/fixtures/pull_requests/pull_request.json
377
+ - spec/fixtures/pull_requests/pull_request.json.erb
378
+ - spec/fixtures/pull_requests/pull_request_exists_error.json
379
+ - spec/fixtures/pull_requests/pull_requests.json
380
+ - spec/fixtures/repositories/commit.json
381
+ - spec/fixtures/repositories/commit.json.erb
382
+ - spec/fixtures/repositories/commits.json.erb
383
+ - spec/fixtures/repositories/statuses.json
384
+ - spec/fixtures/workflow_with_super.rb
385
+ - spec/lib/git_reflow/config_spec.rb
386
+ - spec/lib/git_reflow/git_helpers_spec.rb
387
+ - spec/lib/git_reflow/git_server/bit_bucket_spec.rb
388
+ - spec/lib/git_reflow/git_server/git_hub/pull_request_spec.rb
389
+ - spec/lib/git_reflow/git_server/git_hub_spec.rb
390
+ - spec/lib/git_reflow/git_server/pull_request_spec.rb
391
+ - spec/lib/git_reflow/git_server_spec.rb
392
+ - spec/lib/git_reflow/logger_spec.rb
393
+ - spec/lib/git_reflow/sandbox_spec.rb
394
+ - spec/lib/git_reflow/workflow_spec.rb
395
+ - spec/lib/git_reflow/workflows/core_spec.rb
396
+ - spec/lib/git_reflow/workflows/flat_merge_spec.rb
397
+ - spec/lib/git_reflow_spec.rb
398
+ - spec/spec_helper.rb
399
+ - spec/support/fake_github.rb
400
+ - spec/support/fixtures.rb
401
+ - spec/support/github_helpers.rb
402
+ - spec/support/mock_pull_request.rb
403
+ - spec/support/web_mocks.rb