git_reflow 0.8.4 → 0.8.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/Appraisals +1 -1
  3. data/Gemfile.lock +17 -17
  4. data/git_reflow.gemspec +1 -1
  5. data/lib/git_reflow/config.rb +1 -1
  6. data/lib/git_reflow/git_helpers.rb +2 -2
  7. data/lib/git_reflow/git_server/bit_bucket/pull_request.rb +1 -1
  8. data/lib/git_reflow/git_server/git_hub/pull_request.rb +11 -10
  9. data/lib/git_reflow/git_server/pull_request.rb +18 -4
  10. data/lib/git_reflow/rspec/command_line_helpers.rb +9 -9
  11. data/lib/git_reflow/version.rb +1 -1
  12. data/lib/git_reflow/workflow.rb +6 -1
  13. data/lib/git_reflow/workflows/core.rb +1 -3
  14. data/lib/git_reflow/workflows/flat_merge.rb +10 -0
  15. data/lib/git_reflow.rb +9 -1
  16. metadata +7 -70
  17. data/spec/fixtures/git/git_config +0 -7
  18. data/spec/fixtures/issues/comment.json.erb +0 -27
  19. data/spec/fixtures/issues/comments.json +0 -29
  20. data/spec/fixtures/issues/comments.json.erb +0 -15
  21. data/spec/fixtures/pull_requests/comment.json.erb +0 -45
  22. data/spec/fixtures/pull_requests/comments.json +0 -47
  23. data/spec/fixtures/pull_requests/comments.json.erb +0 -15
  24. data/spec/fixtures/pull_requests/commits.json +0 -29
  25. data/spec/fixtures/pull_requests/external_pull_request.json +0 -145
  26. data/spec/fixtures/pull_requests/pull_request.json +0 -142
  27. data/spec/fixtures/pull_requests/pull_request.json.erb +0 -142
  28. data/spec/fixtures/pull_requests/pull_request_exists_error.json +0 -32
  29. data/spec/fixtures/pull_requests/pull_requests.json +0 -136
  30. data/spec/fixtures/repositories/commit.json +0 -53
  31. data/spec/fixtures/repositories/commit.json.erb +0 -53
  32. data/spec/fixtures/repositories/commits.json.erb +0 -13
  33. data/spec/fixtures/repositories/statuses.json +0 -31
  34. data/spec/lib/git_reflow/config_spec.rb +0 -74
  35. data/spec/lib/git_reflow/git_helpers_spec.rb +0 -182
  36. data/spec/lib/git_reflow/git_server_spec.rb +0 -101
  37. data/spec/lib/git_reflow/workflow_spec.rb +0 -56
  38. data/spec/lib/git_reflow/workflows/core_spec.rb +0 -665
  39. data/spec/lib/git_reflow_spec.rb +0 -39
  40. data/spec/lib/git_server/bit_bucket_spec.rb +0 -81
  41. data/spec/lib/git_server/git_hub/pull_request_spec.rb +0 -472
  42. data/spec/lib/git_server/git_hub_spec.rb +0 -221
  43. data/spec/lib/git_server/pull_request_spec.rb +0 -583
  44. data/spec/spec_helper.rb +0 -38
  45. data/spec/support/fake_github.rb +0 -128
  46. data/spec/support/fixtures.rb +0 -54
  47. data/spec/support/github_helpers.rb +0 -109
  48. data/spec/support/web_mocks.rb +0 -39
@@ -1,128 +0,0 @@
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
-
@@ -1,54 +0,0 @@
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
@@ -1,109 +0,0 @@
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,39 +0,0 @@
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