git_helper 3.5.1 → 3.6.0

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: ffcb2655eb57e6b7a6ea293fa815ecfcc4d4eb52bfdd8eb4a003ce5f7e0ed5a2
4
- data.tar.gz: c3d0bbc2018ecf87cd486331e7d7643409c57b083d2b41ecfdc96bdf3bb9fcd8
3
+ metadata.gz: e4cab8515ee7c8c8e345b477178e3352c600ff5db7bab81e8c3479c7db13bc7a
4
+ data.tar.gz: 53d031494e6e52826f7911c8f06337e82853f069e3cbfc18275d5f918886a443
5
5
  SHA512:
6
- metadata.gz: acc45c11fb46082119da17cfbf66d5baddd4c45e5c9d0757abc9cf2537f3b0a5067b025da48c4a34bd5dee5b137bb241245b6d2a746aa4d263d29e4fc852a79c
7
- data.tar.gz: 2daef5b537909e00ab2c978e42367ab00c49c400bfe044caa1d0a940a8c2c790d14b3832033119b34c3006d919fea85dee810d216d1149f1815fb19bca1e7094
6
+ metadata.gz: 446213efbe6058b0ab790750b390a05dfb7b47793554667ceb20a1c2720a9140c10e2aa9368d2127b62dce538b60b19826c9a9b6380ca88ff7046194e4cf20b9
7
+ data.tar.gz: 9db27ee02e2cc0a5f343b4c0f32b022cc9cbab48e152bb03c38ce8c8360258d9ff68be8154955653fd14b5d3f0c2184ea778ce0fe820b955a3e0b16f00bb78ca
data/Gemfile.lock CHANGED
@@ -1,11 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- git_helper (3.5.1.pre.test)
5
- gitlab (~> 4.16)
6
- gli (~> 2.13)
7
- highline_wrapper (~> 1.1)
8
- octokit (~> 4.18)
4
+ git_helper (3.5.1)
5
+ gitlab
6
+ gli
7
+ highline_wrapper
8
+ octokit
9
9
 
10
10
  GEM
11
11
  remote: https://rubygems.org/
@@ -16,9 +16,9 @@ GEM
16
16
  coderay (1.1.3)
17
17
  concurrent-ruby (1.1.9)
18
18
  diff-lcs (1.4.4)
19
- faker (2.18.0)
19
+ faker (2.19.0)
20
20
  i18n (>= 1.6, < 2)
21
- faraday (1.7.1)
21
+ faraday (1.8.0)
22
22
  faraday-em_http (~> 1.0)
23
23
  faraday-em_synchrony (~> 1.0)
24
24
  faraday-excon (~> 1.1)
@@ -37,7 +37,7 @@ GEM
37
37
  faraday-net_http_persistent (1.2.0)
38
38
  faraday-patron (1.0.0)
39
39
  faraday-rack (1.0.0)
40
- ffi (1.15.3)
40
+ ffi (1.15.4)
41
41
  formatador (0.3.0)
42
42
  gitlab (4.17.0)
43
43
  httparty (~> 0.18)
@@ -60,12 +60,12 @@ GEM
60
60
  highline (2.0.3)
61
61
  highline_wrapper (1.3.0)
62
62
  highline (~> 2.0)
63
- httparty (0.18.1)
63
+ httparty (0.20.0)
64
64
  mime-types (~> 3.0)
65
65
  multi_xml (>= 0.5.2)
66
66
  i18n (1.8.10)
67
67
  concurrent-ruby (~> 1.0)
68
- listen (3.6.0)
68
+ listen (3.7.0)
69
69
  rb-fsevent (~> 0.10, >= 0.10.3)
70
70
  rb-inotify (~> 0.9, >= 0.9.10)
71
71
  lumberjack (1.2.8)
@@ -82,7 +82,7 @@ GEM
82
82
  octokit (4.21.0)
83
83
  faraday (>= 0.9)
84
84
  sawyer (~> 0.8.0, >= 0.5.3)
85
- parallel (1.20.1)
85
+ parallel (1.21.0)
86
86
  parser (3.0.2.0)
87
87
  ast (~> 2.4.1)
88
88
  pry (0.14.1)
@@ -108,16 +108,16 @@ GEM
108
108
  diff-lcs (>= 1.2.0, < 2.0)
109
109
  rspec-support (~> 3.10.0)
110
110
  rspec-support (3.10.2)
111
- rubocop (1.18.4)
111
+ rubocop (1.22.1)
112
112
  parallel (~> 1.10)
113
113
  parser (>= 3.0.0.0)
114
114
  rainbow (>= 2.2.2, < 4.0)
115
115
  regexp_parser (>= 1.8, < 3.0)
116
116
  rexml
117
- rubocop-ast (>= 1.8.0, < 2.0)
117
+ rubocop-ast (>= 1.12.0, < 2.0)
118
118
  ruby-progressbar (~> 1.7)
119
119
  unicode-display_width (>= 1.4.0, < 3.0)
120
- rubocop-ast (1.9.0)
120
+ rubocop-ast (1.12.0)
121
121
  parser (>= 3.0.1.1)
122
122
  ruby-progressbar (1.11.0)
123
123
  ruby2_keywords (0.0.5)
@@ -125,22 +125,21 @@ GEM
125
125
  addressable (>= 2.3.5)
126
126
  faraday (> 0.8, < 2.0)
127
127
  shellany (0.0.1)
128
- terminal-table (1.8.0)
129
- unicode-display_width (~> 1.1, >= 1.1.1)
128
+ terminal-table (1.6.0)
130
129
  thor (1.1.0)
131
- unicode-display_width (1.7.0)
130
+ unicode-display_width (2.1.0)
132
131
 
133
132
  PLATFORMS
134
133
  x86_64-darwin-19
135
134
 
136
135
  DEPENDENCIES
137
- bundler (~> 2.2)
138
- faker (~> 2.15)
136
+ bundler
137
+ faker
139
138
  git_helper!
140
- guard-rspec (~> 4.3)
141
- pry (~> 0.13)
142
- rspec (~> 3.9)
143
- rubocop (~> 1.10)
139
+ guard-rspec
140
+ pry
141
+ rspec
142
+ rubocop
144
143
 
145
144
  BUNDLED WITH
146
- 2.2.25
145
+ 2.2.29
data/README.md CHANGED
@@ -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
 
@@ -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,7 +124,7 @@ 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
@@ -154,7 +157,7 @@ module GitHelper
154
157
  end
155
158
 
156
159
  private def gitlab_client
157
- @gitlab_client ||= GitHelper::GitLabClient.new.client
160
+ @gitlab_client ||= GitHelper::GitLabClient.new
158
161
  end
159
162
  end
160
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GitHelper
4
- VERSION = '3.5.1'
4
+ VERSION = '3.6.0'
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.5.1
4
+ version: 3.6.0
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-09-09 00:00:00.000000000 Z
11
+ date: 2021-10-09 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,20 +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
41
  - !ruby/object:Gem::Dependency
70
42
  name: bundler
71
43
  requirement: !ruby/object:Gem::Requirement
@@ -173,11 +145,11 @@ files:
173
145
  - lib/git_helper/empty_commit.rb
174
146
  - lib/git_helper/forget_local_commits.rb
175
147
  - lib/git_helper/git_config_reader.rb
148
+ - lib/git_helper/github_client.rb
176
149
  - lib/git_helper/gitlab_client.rb
177
150
  - lib/git_helper/local_code.rb
178
151
  - lib/git_helper/merge_request.rb
179
152
  - lib/git_helper/new_branch.rb
180
- - lib/git_helper/octokit_client.rb
181
153
  - lib/git_helper/pull_request.rb
182
154
  - lib/git_helper/setup.rb
183
155
  - lib/git_helper/version.rb
@@ -189,11 +161,11 @@ files:
189
161
  - spec/git_helper/empty_commit_spec.rb
190
162
  - spec/git_helper/forget_local_commits_spec.rb
191
163
  - spec/git_helper/git_config_reader_spec.rb
164
+ - spec/git_helper/github_client_spec.rb
192
165
  - spec/git_helper/gitlab_client_spec.rb
193
166
  - spec/git_helper/local_code_spec.rb
194
167
  - spec/git_helper/merge_request_spec.rb
195
168
  - spec/git_helper/new_branch_spec.rb
196
- - spec/git_helper/octokit_client_spec.rb
197
169
  - spec/git_helper/pull_request_spec.rb
198
170
  - spec/git_helper/setup_spec.rb
199
171
  - spec/spec_helper.rb
@@ -229,10 +201,10 @@ test_files:
229
201
  - spec/git_helper/empty_commit_spec.rb
230
202
  - spec/git_helper/forget_local_commits_spec.rb
231
203
  - spec/git_helper/git_config_reader_spec.rb
204
+ - spec/git_helper/github_client_spec.rb
232
205
  - spec/git_helper/gitlab_client_spec.rb
233
206
  - spec/git_helper/local_code_spec.rb
234
207
  - spec/git_helper/merge_request_spec.rb
235
208
  - spec/git_helper/new_branch_spec.rb
236
- - spec/git_helper/octokit_client_spec.rb
237
209
  - spec/git_helper/pull_request_spec.rb
238
210
  - 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