git_helper 3.4.1 → 3.6.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 295a48c82962b1acd95510653a2c7430ef50c3773d0cd2da78d55d0f428e6dd0
4
- data.tar.gz: 72d909f998d63f307487d278f365fd14d6380d213f10fe11f6cf1b0f7f07ba64
3
+ metadata.gz: 9d9274d7a8c49375a44027dc69e8edbdc0e10ba9f3cc292feb62af0ef7bbd862
4
+ data.tar.gz: 8f22422ba8dfb69137eacca33cead4681ce48f9bd87c5e2428c8fbf0a4f3d874
5
5
  SHA512:
6
- metadata.gz: aafbbfdda563a9a5c3086c1d393564993c8856900e32b3444ba9ddef8ff01f4ef5d919f4108f3a4fceebb94de3f963d5f98e7aa02c66d9157643ce91f1c3ead4
7
- data.tar.gz: 50b732f26e32581cf9a33de9398a00c54e75aa8eebb600d73e59f07218dc26e5aa3cf5e9339830b9fefe876180bc86f2eca877cf7fe238397c0a84764514b3ba
6
+ metadata.gz: 1252ef15165f44e88dda2043278c42bf89fba68db1bc88e77388687fe235495e4290cce17564bfe399795e4037bc229fed1f1ac636fd16b7636e90dc09e1a057
7
+ data.tar.gz: f16b88584257d417545eaa3bfaa073a8b6776b8ad1e77678ed48bea70e57193fc1d427127172aed0c5a6df201980e63b3bf5dbd9465521db0db317d7841dd7bd
data/Gemfile.lock ADDED
@@ -0,0 +1,102 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ git_helper (3.6.1)
5
+ gli (~> 2.13)
6
+ highline_wrapper (~> 1.1)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ ast (2.4.2)
12
+ coderay (1.1.3)
13
+ concurrent-ruby (1.1.9)
14
+ diff-lcs (1.4.4)
15
+ faker (2.19.0)
16
+ i18n (>= 1.6, < 2)
17
+ ffi (1.15.4)
18
+ formatador (0.3.0)
19
+ gli (2.20.1)
20
+ guard (2.18.0)
21
+ formatador (>= 0.2.4)
22
+ listen (>= 2.7, < 4.0)
23
+ lumberjack (>= 1.0.12, < 2.0)
24
+ nenv (~> 0.1)
25
+ notiffany (~> 0.0)
26
+ pry (>= 0.13.0)
27
+ shellany (~> 0.0)
28
+ thor (>= 0.18.1)
29
+ guard-compat (1.2.1)
30
+ guard-rspec (4.7.3)
31
+ guard (~> 2.1)
32
+ guard-compat (~> 1.1)
33
+ rspec (>= 2.99.0, < 4.0)
34
+ highline (2.0.3)
35
+ highline_wrapper (1.3.0)
36
+ highline (~> 2.0)
37
+ i18n (1.8.11)
38
+ concurrent-ruby (~> 1.0)
39
+ listen (3.7.0)
40
+ rb-fsevent (~> 0.10, >= 0.10.3)
41
+ rb-inotify (~> 0.9, >= 0.9.10)
42
+ lumberjack (1.2.8)
43
+ method_source (1.0.0)
44
+ nenv (0.3.0)
45
+ notiffany (0.1.3)
46
+ nenv (~> 0.1)
47
+ shellany (~> 0.0)
48
+ parallel (1.21.0)
49
+ parser (3.0.3.1)
50
+ ast (~> 2.4.1)
51
+ pry (0.14.1)
52
+ coderay (~> 1.1)
53
+ method_source (~> 1.0)
54
+ rainbow (3.0.0)
55
+ rb-fsevent (0.11.0)
56
+ rb-inotify (0.10.1)
57
+ ffi (~> 1.0)
58
+ regexp_parser (2.1.1)
59
+ rexml (3.2.5)
60
+ rspec (3.10.0)
61
+ rspec-core (~> 3.10.0)
62
+ rspec-expectations (~> 3.10.0)
63
+ rspec-mocks (~> 3.10.0)
64
+ rspec-core (3.10.1)
65
+ rspec-support (~> 3.10.0)
66
+ rspec-expectations (3.10.1)
67
+ diff-lcs (>= 1.2.0, < 2.0)
68
+ rspec-support (~> 3.10.0)
69
+ rspec-mocks (3.10.2)
70
+ diff-lcs (>= 1.2.0, < 2.0)
71
+ rspec-support (~> 3.10.0)
72
+ rspec-support (3.10.3)
73
+ rubocop (1.23.0)
74
+ parallel (~> 1.10)
75
+ parser (>= 3.0.0.0)
76
+ rainbow (>= 2.2.2, < 4.0)
77
+ regexp_parser (>= 1.8, < 3.0)
78
+ rexml
79
+ rubocop-ast (>= 1.12.0, < 2.0)
80
+ ruby-progressbar (~> 1.7)
81
+ unicode-display_width (>= 1.4.0, < 3.0)
82
+ rubocop-ast (1.13.0)
83
+ parser (>= 3.0.1.1)
84
+ ruby-progressbar (1.11.0)
85
+ shellany (0.0.1)
86
+ thor (1.1.0)
87
+ unicode-display_width (2.1.0)
88
+
89
+ PLATFORMS
90
+ x86_64-darwin-19
91
+
92
+ DEPENDENCIES
93
+ bundler (~> 2.2)
94
+ faker (~> 2.15)
95
+ git_helper!
96
+ guard-rspec (~> 4.3)
97
+ pry (~> 0.13)
98
+ rspec (~> 3.9)
99
+ rubocop (~> 1.10)
100
+
101
+ BUNDLED WITH
102
+ 2.2.31
data/Guardfile CHANGED
@@ -2,6 +2,6 @@
2
2
 
3
3
  guard :rspec, cmd: 'bundle exec rspec', all_on_start: true do
4
4
  watch(%r{^spec/.+_spec\.rb$})
5
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
5
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
6
6
  watch('spec/spec_helper.rb') { 'spec' }
7
7
  end
data/LICENSE.md CHANGED
@@ -1,11 +1,29 @@
1
- Copyright (c) 2020 Emma Sax. All rights reserved.
1
+ BSD 3-Clause "New" or "Revised" License
2
2
 
3
- Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
3
+ Copyright (c) 2020 Emma Sax.
4
+ All rights reserved.
4
5
 
5
- 1. Redistributions of source code must retain the above copyright notice, this list of conditions, and the following disclaimer.
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
6
8
 
7
- 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions, and the following disclaimer in the documentation and/or other materials provided with the distribution.
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions, and the following disclaimer.
8
11
 
9
- 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions, and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
10
15
 
11
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Git Helper [![Main](https://github.com/emmahsax/git_helper/actions/workflows/main.yml/badge.svg)](https://github.com/emmahsax/git_helper/actions/workflows/main.yml)
1
+ # Git Helper
2
2
 
3
3
  ## Gem Usage
4
4
 
@@ -115,7 +115,7 @@ git-helper clean-branches
115
115
 
116
116
  ### `code-request`
117
117
 
118
- This command can be used to handily make new GitHub/GitLab pull/merge requests from the command-line. The command uses either the [`Octokit::Client`](https://octokit.github.io/octokit.rb/Octokit/Client.html) or [`Gitlab` client](https://github.com/NARKOZ/gitlab) to do this, so make sure you have a `~/.git_helper/config.yml` file set up in the home directory of your computer. For instructions on how to do that, see [Gem Usage](#gem-usage).
118
+ This command can be used to handily make new GitHub/GitLab pull/merge requests from the command-line. The command uses either the [GitHub REST API](https://docs.github.com/en/rest) or [GitLab API](https://docs.gitlab.com/ee/api/) to do this, so make sure you have a `~/.git_helper/config.yml` file set up in the home directory of your computer. For instructions on how to do that, see [Gem Usage](#gem-usage). Furthermore, this project will use [JSON](https://www.npmjs.com/package/json), [YAML](https://www.cloudbees.com/blog/yaml-tutorial-everything-you-need-get-started), and [cURL](https://developer.zendesk.com/documentation/developer-tools/getting-started/installing-and-using-curl/).
119
119
 
120
120
  After setup is complete, you can call the command like this:
121
121
 
@@ -149,7 +149,7 @@ git-helper forget-local-commits
149
149
 
150
150
  ### `merge-code-request`
151
151
 
152
- This command can be used to merge pull/merge requests from the command-line. The command uses either the [`Octokit::Client`](https://octokit.github.io/octokit.rb/Octokit/Client.html) or [`Gitlab` client](https://github.com/NARKOZ/gitlab) to do this, so make sure you have a `~/.git_helper/config.yml` file set up in the home directory of your computer. For instructions on how to do that, see [Gem Usage](#gem-usage).
152
+ This command can be used to merge pull/merge requests from the command-line. The command uses either the [GitHub REST API](https://docs.github.com/en/rest) or [GitLab API](https://docs.gitlab.com/ee/api/) to do this, so make sure you have a `~/.git_helper/config.yml` file set up in the home directory of your computer. For instructions on how to do that, see [Gem Usage](#gem-usage). Furthermore, this project will use [JSON](https://www.npmjs.com/package/json), [YAML](https://www.cloudbees.com/blog/yaml-tutorial-everything-you-need-get-started), and [cURL](https://developer.zendesk.com/documentation/developer-tools/getting-started/installing-and-using-curl/).
153
153
 
154
154
  After setup is complete, you can call the proper command like this:
155
155
 
@@ -180,7 +180,9 @@ The command either accepts a branch name right away or it will ask you for the n
180
180
 
181
181
  ### Contributing
182
182
 
183
- To submit a feature request, bug ticket, etc, please submit an official [GitHub Issue](https://github.com/emmahsax/git_helper/issues/new).
183
+ To submit a feature request, bug ticket, etc, please submit an official [GitHub issue](https://github.com/emmahsax/git_helper/issues/new). To copy or make changes, please [fork this repository](https://github.com/emmahsax/git_helper/fork). When/if you'd like to contribute back to this upstream, please create a pull request on this repository.
184
+
185
+ Please follow included Issue Template(s) and Pull Request Template(s) when creating issues or pull requests.
184
186
 
185
187
  ### Security Policy
186
188
 
@@ -0,0 +1,70 @@
1
+ # frozen_string_literal: true
2
+
3
+ module GitHelper
4
+ class GitHubClient
5
+ def repository(repo_name)
6
+ run(repo_name.split('/').first, nil, "/repos/#{repo_name}")
7
+ end
8
+
9
+ def pull_request(repo_name, pull_request_id)
10
+ run(repo_name.split('/').first, nil, "/repos/#{repo_name}/pulls/#{pull_request_id}")
11
+ end
12
+
13
+ def create_pull_request(repo_name, options)
14
+ opts_as_string = format_options(options)
15
+ run(
16
+ repo_name.split('/').first,
17
+ 'POST',
18
+ "/repos/#{repo_name}/pulls",
19
+ opts_as_string
20
+ )
21
+ end
22
+
23
+ def merge_pull_request(repo_name, pull_request_id, options)
24
+ opts_as_string = format_options(options)
25
+ run(
26
+ repo_name.split('/').first,
27
+ 'PUT',
28
+ "/repos/#{repo_name}/pulls/#{pull_request_id}/merge",
29
+ opts_as_string
30
+ )
31
+ end
32
+
33
+ private def format_options(options)
34
+ opts_as_string = ''.dup
35
+ options.each do |key, value|
36
+ next if value == ''
37
+
38
+ opts_as_string << "#{key.to_json}:#{value.to_json.gsub("'", "'\\\\''")},"
39
+ end
40
+ opts_as_string = opts_as_string.reverse.sub(',', '').reverse
41
+ opts_as_string.empty? ? '' : "{#{opts_as_string}}"
42
+ end
43
+
44
+ # rubocop:disable Layout/LineLength
45
+ private def run(username, request_type, curl_url, options = '')
46
+ OpenStruct.new(
47
+ JSON.parse(
48
+ if request_type
49
+ `curl -s -u #{username}:#{github_token} -H "Accept: application/vnd.github.v3+json" -X #{request_type} -d '#{options}' "#{github_endpoint}#{curl_url}"`
50
+ else
51
+ `curl -s -u #{username}:#{github_token} -H "Accept: application/vnd.github.v3+json" "#{github_endpoint}#{curl_url}"`
52
+ end
53
+ )
54
+ )
55
+ end
56
+ # rubocop:enable Layout/LineLength
57
+
58
+ private def github_token
59
+ git_config_reader.github_token
60
+ end
61
+
62
+ private def git_config_reader
63
+ @git_config_reader ||= GitHelper::GitConfigReader.new
64
+ end
65
+
66
+ private def github_endpoint
67
+ 'https://api.github.com'
68
+ end
69
+ end
70
+ end
@@ -2,8 +2,52 @@
2
2
 
3
3
  module GitHelper
4
4
  class GitLabClient
5
- def client
6
- Gitlab.client(endpoint: gitlab_endpoint, private_token: git_config_reader.gitlab_token)
5
+ def project(project_name)
6
+ run('GET', "/projects/#{url_encode(project_name)}")
7
+ end
8
+
9
+ def merge_request(project_name, merge_request_id)
10
+ run('GET', "/projects/#{url_encode(project_name)}/merge_requests/#{merge_request_id}")
11
+ end
12
+
13
+ def create_merge_request(project_name, options)
14
+ opts_as_string = format_options(options)
15
+ run('POST', "/projects/#{url_encode(project_name)}/merge_requests#{opts_as_string}")
16
+ end
17
+
18
+ def accept_merge_request(project_name, merge_request_id, options)
19
+ opts_as_string = format_options(options)
20
+ run(
21
+ 'PUT',
22
+ "/projects/#{url_encode(project_name)}/merge_requests/#{merge_request_id}/merge#{opts_as_string}"
23
+ )
24
+ end
25
+
26
+ private def format_options(options)
27
+ opts_as_string = ''.dup
28
+ options.each do |key, value|
29
+ next if value == ''
30
+
31
+ opts_as_string << "#{key}=#{url_encode(value.to_s)}&"
32
+ end
33
+ opts_as_string = opts_as_string.reverse.sub('&', '').reverse
34
+ opts_as_string.empty? ? '' : "?#{opts_as_string}"
35
+ end
36
+
37
+ private def run(request_type, curl_url)
38
+ OpenStruct.new(
39
+ JSON.parse(
40
+ `curl -s -X #{request_type} -H "PRIVATE-TOKEN: #{gitlab_token}" "#{gitlab_endpoint}#{curl_url}"`
41
+ )
42
+ )
43
+ end
44
+
45
+ private def url_encode(string)
46
+ string.b.gsub(/[^a-zA-Z0-9_\-.~]/n) { |m| format('%%%<val>02X', val: m.unpack1('C')) }
47
+ end
48
+
49
+ private def gitlab_token
50
+ git_config_reader.gitlab_token
7
51
  end
8
52
 
9
53
  private def git_config_reader
@@ -22,23 +22,28 @@ module GitHelper
22
22
  target_branch: base_branch,
23
23
  squash: squash_merge_request,
24
24
  remove_source_branch: remove_source_branch,
25
- description: new_mr_body
25
+ description: new_mr_body,
26
+ title: new_mr_title
26
27
  }
27
28
 
28
29
  puts "Creating merge request: #{new_mr_title}"
29
- mr = gitlab_client.create_merge_request(local_project, new_mr_title, options)
30
+ mr = gitlab_client.create_merge_request(local_project, options)
30
31
 
31
- if mr.diff_refs.base_sha == mr.diff_refs.head_sha
32
+ raise StandardError, mr.message if mr.diff_refs.nil? || mr.web_url.nil?
33
+
34
+ if mr.diff_refs['base_sha'] == mr.diff_refs['head_sha']
32
35
  puts "Merge request was created, but no commits have been pushed to GitLab: #{mr.web_url}"
33
36
  else
34
37
  puts "Merge request successfully created: #{mr.web_url}"
35
38
  end
36
- rescue Gitlab::Error::Conflict
37
- puts 'Could not create merge request:'
38
- puts ' A merge request already exists for this branch'
39
39
  rescue StandardError => e
40
40
  puts 'Could not create merge request:'
41
- puts e.message
41
+
42
+ if e.message.include?('Another open merge request already exists')
43
+ puts ' A merge request already exists for this branch'
44
+ else
45
+ puts " #{e.message}"
46
+ end
42
47
  end
43
48
  # rubocop:enable Metrics/AbcSize
44
49
  # rubocop:enable Metrics/MethodLength
@@ -61,21 +66,19 @@ module GitHelper
61
66
  merge = gitlab_client.accept_merge_request(local_project, mr_id, options)
62
67
  end
63
68
 
64
- if merge.merge_commit_sha.nil?
65
- puts 'Could not merge merge request:'
66
- puts " #{merge.merge_error}"
67
- else
68
- puts "Merge request successfully merged: #{merge.merge_commit_sha}"
69
- end
70
- rescue Gitlab::Error::MethodNotAllowed
71
- puts 'Could not merge merge request:'
72
- puts ' The merge request is not mergeable'
73
- rescue Gitlab::Error::NotFound
74
- puts 'Could not merge merge request:'
75
- puts " Could not a locate a merge request to merge with ID #{mr_id}"
69
+ raise StandardError, merge.message if merge.merge_commit_sha.nil?
70
+
71
+ puts "Merge request successfully merged: #{merge.merge_commit_sha}"
76
72
  rescue StandardError => e
77
73
  puts 'Could not merge merge request:'
78
- puts e.message
74
+
75
+ if e.message.include?('404 Not found')
76
+ puts ' Could not a locate a merge request to merge with given ID'
77
+ elsif e.message.include?('405 Method Not Allowed')
78
+ puts ' The merge request is not mergeable'
79
+ else
80
+ puts " #{e.message}"
81
+ end
79
82
  end
80
83
  # rubocop:enable Metrics/AbcSize
81
84
  # rubocop:enable Metrics/MethodLength
@@ -121,20 +124,21 @@ module GitHelper
121
124
  end
122
125
 
123
126
  private def mr_id
124
- @mr_id ||= highline.ask('Merge Request ID?')
127
+ @mr_id ||= highline.ask('Merge Request ID?', { required: true })
125
128
  end
126
129
 
127
130
  private def squash_merge_request
128
131
  return @squash_merge_request if @squash_merge_request
129
132
 
130
- case existing_project.squash_option
131
- when 'always', 'default_on'
132
- @squash_merge_request = true
133
- when 'never'
134
- @squash_merge_request = false
135
- else # 'default_off' or anything else
136
- @squash_merge_request = highline.ask_yes_no('Squash merge request? (y/n)')
137
- end
133
+ @squash_merge_request =
134
+ case existing_project.squash_option
135
+ when 'always', 'default_on'
136
+ true
137
+ when 'never'
138
+ false
139
+ else # 'default_off' or anything else
140
+ highline.ask_yes_no('Squash merge request? (y/n)')
141
+ end
138
142
  end
139
143
 
140
144
  private def remove_source_branch
@@ -153,7 +157,7 @@ module GitHelper
153
157
  end
154
158
 
155
159
  private def gitlab_client
156
- @gitlab_client ||= GitHelper::GitLabClient.new.client
160
+ @gitlab_client ||= GitHelper::GitLabClient.new
157
161
  end
158
162
  end
159
163
  end
@@ -17,29 +17,29 @@ module GitHelper
17
17
  @base_branch = options[:base_branch]
18
18
  @new_pr_title = options[:new_title]
19
19
 
20
- new_pr_body
20
+ options = {
21
+ head: local_branch,
22
+ base: base_branch,
23
+ body: new_pr_body,
24
+ title: new_pr_title
25
+ }
21
26
 
22
27
  puts "Creating pull request: #{new_pr_title}"
23
- pr = octokit_client.create_pull_request(
24
- local_repo,
25
- base_branch,
26
- local_branch,
27
- new_pr_title,
28
- new_pr_body
29
- )
28
+ pr = github_client.create_pull_request(local_repo, options)
29
+
30
+ raise StandardError, pr.errors.first['message'] if pr.html_url.nil?
31
+
30
32
  puts "Pull request successfully created: #{pr.html_url}"
31
- rescue Octokit::UnprocessableEntity => e
33
+ rescue StandardError => e
32
34
  puts 'Could not create pull request:'
33
- if e.message.include?('pull request already exists')
35
+
36
+ if e.message.include?('A pull request already exists')
34
37
  puts ' A pull request already exists for this branch'
35
38
  elsif e.message.include?('No commits between')
36
39
  puts ' No commits have been pushed to GitHub'
37
40
  else
38
- puts e.message
41
+ puts " #{e.message}"
39
42
  end
40
- rescue StandardError => e
41
- puts 'Could not create pull request:'
42
- puts e.message
43
43
  end
44
44
  # rubocop:enable Metrics/AbcSize
45
45
  # rubocop:enable Metrics/MethodLength
@@ -48,39 +48,26 @@ module GitHelper
48
48
  # rubocop:disable Metrics/AbcSize
49
49
  def merge
50
50
  pr_id
51
- merge_method
51
+
52
+ options = {
53
+ merge_method: merge_method,
54
+ commit_title: existing_pr.title
55
+ }
52
56
 
53
57
  puts "Merging pull request: #{pr_id}"
54
- merge = octokit_client.merge_pull_request(
55
- local_repo,
56
- pr_id,
57
- existing_pr.title,
58
- { merge_method: merge_method }
59
- )
58
+ merge = github_client.merge_pull_request(local_repo, pr_id, options)
59
+
60
+ raise StandardError, merge.message if merge.sha.nil?
61
+
60
62
  puts "Pull request successfully merged: #{merge.sha}"
61
- rescue Octokit::NotFound
62
- puts 'Could not merge pull request:'
63
- puts " Could not a locate a pull request to merge with ID #{pr_id}"
64
- rescue Octokit::MethodNotAllowed => e
63
+ rescue StandardError => e
65
64
  puts 'Could not merge pull request:'
66
- if e.message.include?('405 - Required status check')
67
- puts ' A required status check has not passed'
68
- elsif e.message.include?('405 - Base branch was modified')
69
- puts ' The base branch has been modified'
70
- elsif e.message.include?('405 - Pull Request is not mergeable')
71
- puts ' The pull request is not mergeable'
72
- elsif e.message.include?('405 - Rebase merges are not allowed on this repository')
73
- puts ' Rebase merges are not allowed on this repository'
74
- elsif e.message.include?('405 - Merge commits are not allowed on this repository')
75
- puts ' Merge commits are not allowed on this repository'
76
- elsif e.message.include?('405 - Squash commits are not allowed on this repository')
77
- puts ' Squash merges are not allowed on this repository'
65
+
66
+ if e.message.include?('Not found')
67
+ puts ' Could not a locate a pull request to merge with given ID'
78
68
  else
79
- puts e.message
69
+ puts " #{e.message}"
80
70
  end
81
- rescue StandardError => e
82
- puts 'Could not merge pull request:'
83
- puts e.message
84
71
  end
85
72
  # rubocop:enable Metrics/AbcSize
86
73
  # rubocop:enable Metrics/MethodLength
@@ -126,7 +113,7 @@ module GitHelper
126
113
  end
127
114
 
128
115
  private def pr_id
129
- @pr_id ||= highline.ask('Pull Request ID?')
116
+ @pr_id ||= highline.ask('Pull Request ID?', { required: true })
130
117
  end
131
118
 
132
119
  private def merge_method
@@ -149,15 +136,15 @@ module GitHelper
149
136
  end
150
137
 
151
138
  private def existing_project
152
- @existing_project ||= octokit_client.repository(local_repo)
139
+ @existing_project ||= github_client.repository(local_repo)
153
140
  end
154
141
 
155
142
  private def existing_pr
156
- @existing_pr ||= octokit_client.pull_request(local_repo, pr_id)
143
+ @existing_pr ||= github_client.pull_request(local_repo, pr_id)
157
144
  end
158
145
 
159
- private def octokit_client
160
- @octokit_client ||= GitHelper::OctokitClient.new.client
146
+ private def github_client
147
+ @github_client ||= GitHelper::GitHubClient.new
161
148
  end
162
149
  end
163
150
  end
@@ -33,7 +33,7 @@ module GitHelper
33
33
 
34
34
  create_or_update_plugin_files
35
35
  puts "\nNow add this line to your ~/.bash_profile:\n" \
36
- ' export PATH=/path/to/computer/home/.git_helper/plugins:$PATH'
36
+ ' export PATH=/path/to/computer/home/.git_helper/plugins:$PATH'
37
37
  puts "\nDone!"
38
38
  end
39
39
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GitHelper
4
- VERSION = '3.4.1'
4
+ VERSION = '3.6.1'
5
5
  end
data/lib/git_helper.rb CHANGED
@@ -1,9 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'yaml'
4
- require 'gitlab'
4
+ require 'json'
5
5
  require 'highline_wrapper'
6
- require 'octokit'
7
6
 
8
7
  files = "#{File.expand_path(File.join(File.dirname(File.absolute_path(__FILE__)), 'git_helper'))}/**/*.rb"
9
8
 
@@ -250,7 +250,7 @@ describe GitHelper::CodeRequest do
250
250
  end
251
251
 
252
252
  describe '#local_code' do
253
- it 'should call the octokit client' do
253
+ it 'should call the GitHub client' do
254
254
  expect(GitHelper::LocalCode).to receive(:new).and_return(local_code)
255
255
  subject.send(:local_code)
256
256
  end
@@ -0,0 +1,131 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'spec_helper'
4
+ require 'git_helper'
5
+
6
+ describe GitHelper::GitHubClient do
7
+ let(:git_config_reader) { double(:git_config_reader, github_token: :token) }
8
+
9
+ subject { GitHelper::GitHubClient.new }
10
+
11
+ before do
12
+ allow(GitHelper::GitConfigReader).to receive(:new).and_return(git_config_reader)
13
+ end
14
+
15
+ describe '#repository' do
16
+ it 'should call to run a query' do
17
+ expect(subject).to receive(:run)
18
+ subject.repository(Faker::Lorem.word)
19
+ end
20
+
21
+ it "should return the run command's answer" do
22
+ expect(subject).to receive(:run).and_return(:command_complete)
23
+ expect(subject.repository(Faker::Lorem.word)).to eq(:command_complete)
24
+ end
25
+ end
26
+
27
+ describe '#pull_request' do
28
+ it 'should call to run a query' do
29
+ expect(subject).to receive(:run)
30
+ subject.pull_request(Faker::Lorem.word, Faker::Number.number)
31
+ end
32
+
33
+ it "should return the run command's answer" do
34
+ expect(subject).to receive(:run).and_return(:command_complete)
35
+ expect(subject.pull_request(Faker::Lorem.word, Faker::Number.number)).to eq(:command_complete)
36
+ end
37
+ end
38
+
39
+ describe '#create_pull_request' do
40
+ it 'should call to run a query' do
41
+ expect(subject).to receive(:run)
42
+ subject.create_pull_request(Faker::Lorem.word, {})
43
+ end
44
+
45
+ it 'should generate a string list of options' do
46
+ expect(subject).to receive(:format_options).with({})
47
+ subject.create_pull_request(Faker::Lorem.word, {})
48
+ end
49
+
50
+ it "should return the run command's answer" do
51
+ expect(subject).to receive(:run).and_return(:command_complete)
52
+ expect(subject.create_pull_request(Faker::Lorem.word, {})).to eq(:command_complete)
53
+ end
54
+ end
55
+
56
+ describe '#merge_pull_request' do
57
+ it 'should call to run a query' do
58
+ expect(subject).to receive(:run)
59
+ subject.merge_pull_request(Faker::Lorem.word, Faker::Number.number, {})
60
+ end
61
+
62
+ it 'should generate a string list of options' do
63
+ expect(subject).to receive(:format_options).with({})
64
+ subject.merge_pull_request(Faker::Lorem.word, Faker::Number.number, {})
65
+ end
66
+
67
+ it "should return the run command's answer" do
68
+ expect(subject).to receive(:run).and_return(:command_complete)
69
+ expect(subject.merge_pull_request(Faker::Lorem.word, Faker::Number.number, {})).to eq(:command_complete)
70
+ end
71
+ end
72
+
73
+ describe '#format_options' do
74
+ it 'will make a list of hash options into a JSON parsed chunk of key/value pairs as string' do
75
+ options = {
76
+ key1: 'value1',
77
+ key2: true,
78
+ key3: '',
79
+ key4: false,
80
+ key5: 'value5'
81
+ }
82
+ # rubocop:disable Style/StringLiterals
83
+ result = "{\"key1\":\"value1\",\"key2\":true,\"key4\":false,\"key5\":\"value5\"}"
84
+ # rubocop:enable Style/StringLiterals
85
+ expect(subject.send(:format_options, options)).to eq(result)
86
+ end
87
+
88
+ it 'will return an empty string if an empty hash is given' do
89
+ expect(subject.send(:format_options, {})).to eq('')
90
+ end
91
+
92
+ it 'will return an empty string if all values are empty strings' do
93
+ options = {
94
+ key1: '',
95
+ key2: '',
96
+ key3: ''
97
+ }
98
+ expect(subject.send(:format_options, options)).to eq('')
99
+ end
100
+ end
101
+
102
+ describe '#run' do
103
+ it 'should call CURL' do
104
+ expect(subject).to receive(:`).and_return('{}')
105
+ subject.send(:run, Faker::Lorem.word, 'GET', "/projects/#{Faker::Lorem.word}")
106
+ end
107
+
108
+ it 'should use JSON to parse the response' do
109
+ expect(JSON).to receive(:parse).and_return({})
110
+ subject.send(:run, Faker::Lorem.word, 'GET', "/projects/#{Faker::Lorem.word}")
111
+ end
112
+
113
+ it 'should use OpenStruct to turn the hash into an object' do
114
+ expect(OpenStruct).to receive(:new).and_return(OpenStruct.new)
115
+ subject.send(:run, Faker::Lorem.word, 'GET', "/projects/#{Faker::Lorem.word}")
116
+ end
117
+ end
118
+
119
+ describe '#github_token' do
120
+ it 'should return a token' do
121
+ expect(subject.send(:github_token)).to eq(:token)
122
+ end
123
+ end
124
+
125
+ describe '#git_config_reader' do
126
+ it 'should make a new git config reader' do
127
+ expect(GitHelper::GitConfigReader).to receive(:new)
128
+ subject.send(:git_config_reader)
129
+ end
130
+ end
131
+ end
@@ -12,10 +12,126 @@ describe GitHelper::GitLabClient do
12
12
  allow(GitHelper::GitConfigReader).to receive(:new).and_return(git_config_reader)
13
13
  end
14
14
 
15
- describe '#client' do
16
- it 'should call the GitLab client to make a new client' do
17
- expect(Gitlab).to receive(:client)
18
- subject.client
15
+ describe '#project' do
16
+ it 'should call to run a query' do
17
+ expect(subject).to receive(:run)
18
+ subject.project(Faker::Lorem.word)
19
+ end
20
+
21
+ it "should return the run command's answer" do
22
+ expect(subject).to receive(:run).and_return(:command_complete)
23
+ expect(subject.project(Faker::Lorem.word)).to eq(:command_complete)
24
+ end
25
+ end
26
+
27
+ describe '#merge_request' do
28
+ it 'should call to run a query' do
29
+ expect(subject).to receive(:run)
30
+ subject.merge_request(Faker::Lorem.word, Faker::Number.number)
31
+ end
32
+
33
+ it "should return the run command's answer" do
34
+ expect(subject).to receive(:run).and_return(:command_complete)
35
+ expect(subject.merge_request(Faker::Lorem.word, Faker::Number.number)).to eq(:command_complete)
36
+ end
37
+ end
38
+
39
+ describe '#create_merge_request' do
40
+ it 'should call to run a query' do
41
+ expect(subject).to receive(:run)
42
+ subject.create_merge_request(Faker::Lorem.word, {})
43
+ end
44
+
45
+ it 'should generate a string list of options' do
46
+ expect(subject).to receive(:format_options).with({})
47
+ subject.create_merge_request(Faker::Lorem.word, {})
48
+ end
49
+
50
+ it "should return the run command's answer" do
51
+ expect(subject).to receive(:run).and_return(:command_complete)
52
+ expect(subject.create_merge_request(Faker::Lorem.word, {})).to eq(:command_complete)
53
+ end
54
+ end
55
+
56
+ describe '#accept_merge_request' do
57
+ it 'should call to run a query' do
58
+ expect(subject).to receive(:run)
59
+ subject.accept_merge_request(Faker::Lorem.word, Faker::Number.number, {})
60
+ end
61
+
62
+ it 'should generate a string list of options' do
63
+ expect(subject).to receive(:format_options).with({})
64
+ subject.accept_merge_request(Faker::Lorem.word, Faker::Number.number, {})
65
+ end
66
+
67
+ it "should return the run command's answer" do
68
+ expect(subject).to receive(:run).and_return(:command_complete)
69
+ expect(subject.accept_merge_request(Faker::Lorem.word, Faker::Number.number, {})).to eq(:command_complete)
70
+ end
71
+ end
72
+
73
+ describe '#format_options' do
74
+ it 'will make a list of hash options into a URL string' do
75
+ options = {
76
+ key1: 'value1',
77
+ key2: true,
78
+ key3: '',
79
+ key4: false,
80
+ key5: 'value5'
81
+ }
82
+ result = '?key1=value1&key2=true&key4=false&key5=value5'
83
+ expect(subject.send(:format_options, options)).to eq(result)
84
+ end
85
+
86
+ it 'will return an empty string if an empty hash is given' do
87
+ expect(subject.send(:format_options, {})).to eq('')
88
+ end
89
+
90
+ it 'will return an empty string if all values are empty strings' do
91
+ options = {
92
+ key1: '',
93
+ key2: '',
94
+ key3: ''
95
+ }
96
+ expect(subject.send(:format_options, options)).to eq('')
97
+ end
98
+ end
99
+
100
+ describe '#run' do
101
+ it 'should call CURL' do
102
+ expect(subject).to receive(:`).and_return('{}')
103
+ subject.send(:run, 'GET', "/projects/#{Faker::Lorem.word}")
104
+ end
105
+
106
+ it 'should use JSON to parse the response' do
107
+ expect(JSON).to receive(:parse).and_return({})
108
+ subject.send(:run, 'GET', "/projects/#{Faker::Lorem.word}")
109
+ end
110
+
111
+ it 'should use OpenStruct to turn the hash into an object' do
112
+ expect(OpenStruct).to receive(:new).and_return(OpenStruct.new)
113
+ subject.send(:run, 'GET', "/projects/#{Faker::Lorem.word}")
114
+ end
115
+ end
116
+
117
+ describe '#url_encode' do
118
+ let(:group_name) { Faker::Lorem.word }
119
+ let(:project_name) { Faker::Lorem.word }
120
+
121
+ it 'should return the same string as passed in but with no spaces' do
122
+ expect(subject.send(:url_encode, "#{group_name}/#{project_name}")).to eq("#{group_name}%2F#{project_name}")
123
+ end
124
+
125
+ it 'should never include a space or a slash' do
126
+ resp = subject.send(:url_encode, "#{group_name} #{Faker::Lorem.word}/#{project_name}")
127
+ expect(resp).not_to include(' ')
128
+ expect(resp).not_to include('/')
129
+ end
130
+ end
131
+
132
+ describe '#gitlab_token' do
133
+ it 'should return a token' do
134
+ expect(subject.send(:gitlab_token)).to eq(:token)
19
135
  end
20
136
  end
21
137
 
@@ -6,13 +6,12 @@ require 'git_helper'
6
6
  describe GitHelper::GitLabMergeRequest do
7
7
  let(:local_code) { double(:local_code, read_template: Faker::Lorem.word) }
8
8
  let(:highline_wrapper) { double(:highline_wrapper) }
9
- let(:gitlab_client_client) { double(:gitlab_client_client, project: :project, merge_request: :merge_request, create_merge_request: :created) }
10
- let(:gitlab_client) { double(:gitlab_client, client: gitlab_client_client) }
11
- let(:diff_refs) { double(:diff_refs, base_sha: :base, head_sha: :head) }
9
+ let(:gitlab_client) { double(:gitlab_client) }
12
10
 
13
11
  let(:merge_request) do
14
12
  double(:merge_request,
15
- diff_refs: diff_refs,
13
+ message: Faker::Lorem.sentence,
14
+ diff_refs: { base_sha: Faker::Lorem.word, head_sha: Faker::Lorem.word },
16
15
  web_url: Faker::Internet.url,
17
16
  merge_commit_sha: Faker::Internet.password)
18
17
  end
@@ -38,7 +37,7 @@ describe GitHelper::GitLabMergeRequest do
38
37
  allow(subject).to receive(:squash_merge_request).and_return(true)
39
38
  allow(subject).to receive(:remove_source_branch).and_return(false)
40
39
  allow(subject).to receive(:new_mr_body).and_return('')
41
- expect(gitlab_client_client).to receive(:create_merge_request).and_return(merge_request)
40
+ expect(gitlab_client).to receive(:create_merge_request).and_return(merge_request)
42
41
  subject.create({ base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word })
43
42
  end
44
43
 
@@ -46,7 +45,7 @@ describe GitHelper::GitLabMergeRequest do
46
45
  expect(subject).to receive(:squash_merge_request).and_return(true)
47
46
  expect(subject).to receive(:remove_source_branch).and_return(false)
48
47
  expect(subject).to receive(:new_mr_body).and_return('')
49
- allow(gitlab_client_client).to receive(:create_merge_request).and_return(merge_request)
48
+ allow(gitlab_client).to receive(:create_merge_request).and_return(merge_request)
50
49
  subject.create({ base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word })
51
50
  end
52
51
 
@@ -54,7 +53,7 @@ describe GitHelper::GitLabMergeRequest do
54
53
  allow(subject).to receive(:squash_merge_request).and_return(true)
55
54
  allow(subject).to receive(:remove_source_branch).and_return(false)
56
55
  allow(subject).to receive(:new_mr_body).and_return('')
57
- allow(gitlab_client_client).to receive(:create_merge_request).and_raise(StandardError)
56
+ allow(gitlab_client).to receive(:create_merge_request).and_raise(StandardError)
58
57
  expect(subject.create({ base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word })).to eq(nil)
59
58
  end
60
59
  end
@@ -63,28 +62,28 @@ describe GitHelper::GitLabMergeRequest do
63
62
  it 'should call the gitlab client to merge' do
64
63
  allow(subject).to receive(:existing_mr).and_return(double(should_remove_source_branch: true, squash: false, title: 'title'))
65
64
  allow(subject).to receive(:mr_id).and_return(Faker::Number.number)
66
- expect(gitlab_client_client).to receive(:accept_merge_request).and_return(merge_request)
65
+ expect(gitlab_client).to receive(:accept_merge_request).and_return(merge_request)
67
66
  subject.merge
68
67
  end
69
68
 
70
69
  it 'should call various other methods' do
71
70
  expect(subject).to receive(:existing_mr).and_return(double(should_remove_source_branch: true, squash: false, title: 'title')).at_least(:once)
72
71
  expect(subject).to receive(:mr_id).and_return(Faker::Number.number).at_least(:once)
73
- allow(gitlab_client_client).to receive(:accept_merge_request).and_return(merge_request)
72
+ allow(gitlab_client).to receive(:accept_merge_request).and_return(merge_request)
74
73
  subject.merge
75
74
  end
76
75
 
77
76
  it 'should catch the raised error if the merge does not work' do
78
77
  allow(subject).to receive(:existing_mr).and_return(double(should_remove_source_branch: true, squash: false, title: 'title'))
79
78
  allow(subject).to receive(:mr_id).and_return(Faker::Number.number)
80
- allow(gitlab_client_client).to receive(:accept_merge_request).and_raise(StandardError)
79
+ allow(gitlab_client).to receive(:accept_merge_request).and_raise(StandardError)
81
80
  expect(subject.merge).to eq(nil)
82
81
  end
83
82
 
84
83
  it 'should try to merge multiple times if the first merge errors' do
85
84
  allow(subject).to receive(:existing_mr).and_return(double(should_remove_source_branch: true, squash: false, title: 'title'))
86
85
  allow(subject).to receive(:mr_id).and_return(Faker::Number.number)
87
- expect(gitlab_client_client).to receive(:accept_merge_request).and_return(double(merge_commit_sha: nil, merge_error: Faker::Lorem.word)).exactly(2).times
86
+ expect(gitlab_client).to receive(:accept_merge_request).and_return(double(merge_commit_sha: nil, merge_error: Faker::Lorem.word, message: Faker::Lorem.sentence)).exactly(2).times
88
87
  expect(subject.merge).to eq(nil)
89
88
  end
90
89
  end
@@ -257,7 +256,7 @@ describe GitHelper::GitLabMergeRequest do
257
256
 
258
257
  describe '#existing_project' do
259
258
  it 'should call the gitlab client' do
260
- expect(gitlab_client_client).to receive(:project).and_return(:project)
259
+ expect(gitlab_client).to receive(:project).and_return(:project)
261
260
  subject.send(:existing_project)
262
261
  end
263
262
  end
@@ -265,7 +264,7 @@ describe GitHelper::GitLabMergeRequest do
265
264
  describe '#existing_mr' do
266
265
  it 'should call the gitlab client' do
267
266
  allow(highline_wrapper).to receive(:ask).and_return(Faker::Number.number)
268
- expect(gitlab_client_client).to receive(:merge_request).and_return(:merge_request)
267
+ expect(gitlab_client).to receive(:merge_request).and_return(:merge_request)
269
268
  subject.send(:existing_mr)
270
269
  end
271
270
  end
@@ -6,8 +6,7 @@ require 'git_helper'
6
6
  describe GitHelper::GitHubPullRequest do
7
7
  let(:local_code) { double(:local_code, read_template: Faker::Lorem.word) }
8
8
  let(:highline_wrapper) { double(:highline_wrapper) }
9
- let(:octokit_client_client) { double(:octokit_client_client, project: :project, merge_request: :merge_request, create_merge_request: :created) }
10
- let(:octokit_client) { double(:octokit_client, client: octokit_client_client) }
9
+ let(:github_client) { double(:github_client) }
11
10
 
12
11
  let(:options) do
13
12
  {
@@ -21,36 +20,36 @@ describe GitHelper::GitHubPullRequest do
21
20
  subject { GitHelper::GitHubPullRequest.new(options) }
22
21
 
23
22
  before do
24
- allow(GitHelper::OctokitClient).to receive(:new).and_return(octokit_client)
23
+ allow(GitHelper::GitHubClient).to receive(:new).and_return(github_client)
25
24
  allow(subject).to receive(:puts)
26
25
  end
27
26
 
28
27
  describe '#create' do
29
- it 'should call the octokit client to create' do
28
+ it 'should call the GitHub client to create' do
30
29
  allow(subject).to receive(:new_pr_body).and_return('')
31
- expect(octokit_client_client).to receive(:create_pull_request).and_return(double(html_url: Faker::Internet.url))
30
+ expect(github_client).to receive(:create_pull_request).and_return(double(html_url: Faker::Internet.url))
32
31
  subject.create({ base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word })
33
32
  end
34
33
 
35
34
  it 'should call various other methods' do
36
35
  expect(subject).to receive(:new_pr_body).and_return('').at_least(:once)
37
- allow(octokit_client_client).to receive(:create_pull_request).and_return(double(html_url: Faker::Internet.url))
36
+ allow(github_client).to receive(:create_pull_request).and_return(double(html_url: Faker::Internet.url))
38
37
  subject.create({ base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word })
39
38
  end
40
39
 
41
40
  it 'should catch the raised error if the creation does not work' do
42
41
  allow(subject).to receive(:new_pr_body).and_return('')
43
- allow(octokit_client_client).to receive(:create_pull_request).and_raise(StandardError)
42
+ allow(github_client).to receive(:create_pull_request).and_raise(StandardError)
44
43
  expect(subject.create({ base_branch: Faker::Lorem.word, new_title: Faker::Lorem.word })).to eq(nil)
45
44
  end
46
45
  end
47
46
 
48
47
  describe '#merge' do
49
- it 'should call the octokit client to merge' do
48
+ it 'should call the GitHub client to merge' do
50
49
  allow(subject).to receive(:existing_pr).and_return(double(title: Faker::Lorem.word))
51
50
  allow(subject).to receive(:merge_method).and_return('rebase')
52
51
  allow(subject).to receive(:pr_id).and_return(Faker::Number.number)
53
- expect(octokit_client_client).to receive(:merge_pull_request).and_return(double(sha: Faker::Internet.password))
52
+ expect(github_client).to receive(:merge_pull_request).and_return(double(sha: Faker::Internet.password))
54
53
  subject.merge
55
54
  end
56
55
 
@@ -58,7 +57,7 @@ describe GitHelper::GitHubPullRequest do
58
57
  expect(subject).to receive(:existing_pr).and_return(double(title: Faker::Lorem.word)).at_least(:once)
59
58
  expect(subject).to receive(:merge_method).and_return('rebase').at_least(:once)
60
59
  expect(subject).to receive(:pr_id).and_return(Faker::Number.number).at_least(:once)
61
- allow(octokit_client_client).to receive(:merge_pull_request).and_return(double(sha: Faker::Internet.password))
60
+ allow(github_client).to receive(:merge_pull_request).and_return(double(sha: Faker::Internet.password))
62
61
  subject.merge
63
62
  end
64
63
 
@@ -66,7 +65,7 @@ describe GitHelper::GitHubPullRequest do
66
65
  allow(subject).to receive(:existing_pr).and_return(double(title: Faker::Lorem.word))
67
66
  allow(subject).to receive(:merge_method).and_return('rebase')
68
67
  allow(subject).to receive(:pr_id).and_return(Faker::Number.number)
69
- allow(octokit_client_client).to receive(:merge_pull_request).and_raise(StandardError)
68
+ allow(github_client).to receive(:merge_pull_request).and_raise(StandardError)
70
69
  expect(subject.merge).to eq(nil)
71
70
  end
72
71
  end
@@ -233,24 +232,24 @@ describe GitHelper::GitHubPullRequest do
233
232
  end
234
233
 
235
234
  describe '#existing_project' do
236
- it 'should call the octokit client' do
237
- expect(octokit_client_client).to receive(:repository).and_return(:repository)
235
+ it 'should call the GitHub client' do
236
+ expect(github_client).to receive(:repository).and_return(:repository)
238
237
  subject.send(:existing_project)
239
238
  end
240
239
  end
241
240
 
242
241
  describe '#existing_pr' do
243
- it 'should call the octokit client' do
242
+ it 'should call the GitHub client' do
244
243
  allow(highline_wrapper).to receive(:ask).and_return(Faker::Number.number)
245
- expect(octokit_client_client).to receive(:pull_request).and_return(:pull_request)
244
+ expect(github_client).to receive(:pull_request).and_return(:pull_request)
246
245
  subject.send(:existing_pr)
247
246
  end
248
247
  end
249
248
 
250
- describe '#octokit_client' do
251
- it 'should call the octokit client' do
252
- expect(GitHelper::OctokitClient).to receive(:new).and_return(octokit_client)
253
- subject.send(:octokit_client)
249
+ describe '#github_client' do
250
+ it 'should call the GitHub client' do
251
+ expect(GitHelper::GitHubClient).to receive(:new).and_return(github_client)
252
+ subject.send(:github_client)
254
253
  end
255
254
  end
256
255
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: git_helper
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.1
4
+ version: 3.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Emma Sax
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-24 00:00:00.000000000 Z
11
+ date: 2021-12-01 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: gitlab
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - "~>"
18
- - !ruby/object:Gem::Version
19
- version: '4.16'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - "~>"
25
- - !ruby/object:Gem::Version
26
- version: '4.16'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: gli
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -52,34 +38,6 @@ dependencies:
52
38
  - - "~>"
53
39
  - !ruby/object:Gem::Version
54
40
  version: '1.1'
55
- - !ruby/object:Gem::Dependency
56
- name: octokit
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '4.18'
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '4.18'
69
- - !ruby/object:Gem::Dependency
70
- name: psych
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "<"
74
- - !ruby/object:Gem::Version
75
- version: '4'
76
- type: :runtime
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "<"
81
- - !ruby/object:Gem::Version
82
- version: '4'
83
41
  - !ruby/object:Gem::Dependency
84
42
  name: bundler
85
43
  requirement: !ruby/object:Gem::Requirement
@@ -136,20 +94,6 @@ dependencies:
136
94
  - - "~>"
137
95
  - !ruby/object:Gem::Version
138
96
  version: '0.13'
139
- - !ruby/object:Gem::Dependency
140
- name: rake
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - "~>"
144
- - !ruby/object:Gem::Version
145
- version: '13.0'
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - "~>"
151
- - !ruby/object:Gem::Version
152
- version: '13.0'
153
97
  - !ruby/object:Gem::Dependency
154
98
  name: rspec
155
99
  requirement: !ruby/object:Gem::Requirement
@@ -187,6 +131,7 @@ extensions: []
187
131
  extra_rdoc_files: []
188
132
  files:
189
133
  - Gemfile
134
+ - Gemfile.lock
190
135
  - Guardfile
191
136
  - LICENSE.md
192
137
  - README.md
@@ -200,11 +145,11 @@ files:
200
145
  - lib/git_helper/empty_commit.rb
201
146
  - lib/git_helper/forget_local_commits.rb
202
147
  - lib/git_helper/git_config_reader.rb
148
+ - lib/git_helper/github_client.rb
203
149
  - lib/git_helper/gitlab_client.rb
204
150
  - lib/git_helper/local_code.rb
205
151
  - lib/git_helper/merge_request.rb
206
152
  - lib/git_helper/new_branch.rb
207
- - lib/git_helper/octokit_client.rb
208
153
  - lib/git_helper/pull_request.rb
209
154
  - lib/git_helper/setup.rb
210
155
  - lib/git_helper/version.rb
@@ -216,18 +161,19 @@ files:
216
161
  - spec/git_helper/empty_commit_spec.rb
217
162
  - spec/git_helper/forget_local_commits_spec.rb
218
163
  - spec/git_helper/git_config_reader_spec.rb
164
+ - spec/git_helper/github_client_spec.rb
219
165
  - spec/git_helper/gitlab_client_spec.rb
220
166
  - spec/git_helper/local_code_spec.rb
221
167
  - spec/git_helper/merge_request_spec.rb
222
168
  - spec/git_helper/new_branch_spec.rb
223
- - spec/git_helper/octokit_client_spec.rb
224
169
  - spec/git_helper/pull_request_spec.rb
225
170
  - spec/git_helper/setup_spec.rb
226
171
  - spec/spec_helper.rb
227
172
  homepage: https://github.com/emmahsax/git_helper
228
173
  licenses:
229
174
  - BSD-3-Clause
230
- metadata: {}
175
+ metadata:
176
+ rubygems_mfa_required: 'true'
231
177
  post_install_message:
232
178
  rdoc_options: []
233
179
  require_paths:
@@ -243,10 +189,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
243
189
  - !ruby/object:Gem::Version
244
190
  version: '0'
245
191
  requirements: []
246
- rubygems_version: 3.2.15
192
+ rubygems_version: 3.2.22
247
193
  signing_key:
248
194
  specification_version: 4
249
- summary: A set of GitHub and GitLab workflow scripts.
195
+ summary: A set of GitHub and GitLab workflow scripts
250
196
  test_files:
251
197
  - spec/spec_helper.rb
252
198
  - spec/git_helper/change_remote_spec.rb
@@ -256,10 +202,10 @@ test_files:
256
202
  - spec/git_helper/empty_commit_spec.rb
257
203
  - spec/git_helper/forget_local_commits_spec.rb
258
204
  - spec/git_helper/git_config_reader_spec.rb
205
+ - spec/git_helper/github_client_spec.rb
259
206
  - spec/git_helper/gitlab_client_spec.rb
260
207
  - spec/git_helper/local_code_spec.rb
261
208
  - spec/git_helper/merge_request_spec.rb
262
209
  - spec/git_helper/new_branch_spec.rb
263
- - spec/git_helper/octokit_client_spec.rb
264
210
  - spec/git_helper/pull_request_spec.rb
265
211
  - spec/git_helper/setup_spec.rb
@@ -1,13 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module GitHelper
4
- class OctokitClient
5
- def client
6
- Octokit::Client.new(access_token: git_config_reader.github_token)
7
- end
8
-
9
- private def git_config_reader
10
- @git_config_reader ||= GitHelper::GitConfigReader.new
11
- end
12
- end
13
- end
@@ -1,28 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'spec_helper'
4
- require 'git_helper'
5
-
6
- describe GitHelper::OctokitClient do
7
- let(:git_config_reader) { double(:git_config_reader, github_token: :token) }
8
-
9
- subject { GitHelper::OctokitClient.new }
10
-
11
- before do
12
- allow(GitHelper::GitConfigReader).to receive(:new).and_return(git_config_reader)
13
- end
14
-
15
- describe '#client' do
16
- it 'should call the GitLab client to make a new client' do
17
- expect(Octokit::Client).to receive(:new)
18
- subject.client
19
- end
20
- end
21
-
22
- describe '#git_config_reader' do
23
- it 'should make a new git config reader' do
24
- expect(GitHelper::GitConfigReader).to receive(:new)
25
- subject.send(:git_config_reader)
26
- end
27
- end
28
- end