git_helper 3.4.0 → 3.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +45 -40
- data/Guardfile +1 -1
- data/LICENSE.md +29 -0
- data/README.md +19 -7
- data/lib/git_helper/github_client.rb +70 -0
- data/lib/git_helper/gitlab_client.rb +46 -2
- data/lib/git_helper/merge_request.rb +34 -30
- data/lib/git_helper/pull_request.rb +33 -46
- data/lib/git_helper/setup.rb +1 -1
- data/lib/git_helper/version.rb +1 -1
- data/lib/git_helper.rb +1 -2
- data/spec/git_helper/code_request_spec.rb +1 -1
- data/spec/git_helper/github_client_spec.rb +131 -0
- data/spec/git_helper/gitlab_client_spec.rb +120 -4
- data/spec/git_helper/merge_request_spec.rb +12 -13
- data/spec/git_helper/pull_request_spec.rb +18 -19
- metadata +9 -65
- data/LICENSE +0 -22
- data/lib/git_helper/octokit_client.rb +0 -13
- data/spec/git_helper/octokit_client_spec.rb +0 -28
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e4cab8515ee7c8c8e345b477178e3352c600ff5db7bab81e8c3479c7db13bc7a
|
4
|
+
data.tar.gz: 53d031494e6e52826f7911c8f06337e82853f069e3cbfc18275d5f918886a443
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 446213efbe6058b0ab790750b390a05dfb7b47793554667ceb20a1c2720a9140c10e2aa9368d2127b62dce538b60b19826c9a9b6380ca88ff7046194e4cf20b9
|
7
|
+
data.tar.gz: 9db27ee02e2cc0a5f343b4c0f32b022cc9cbab48e152bb03c38ce8c8360258d9ff68be8154955653fd14b5d3f0c2184ea778ce0fe820b955a3e0b16f00bb78ca
|
data/Gemfile.lock
CHANGED
@@ -1,46 +1,55 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
git_helper (3.
|
5
|
-
gitlab
|
6
|
-
gli
|
7
|
-
highline_wrapper
|
8
|
-
octokit
|
9
|
-
psych (< 4)
|
4
|
+
git_helper (3.5.1)
|
5
|
+
gitlab
|
6
|
+
gli
|
7
|
+
highline_wrapper
|
8
|
+
octokit
|
10
9
|
|
11
10
|
GEM
|
12
11
|
remote: https://rubygems.org/
|
13
12
|
specs:
|
14
|
-
addressable (2.
|
13
|
+
addressable (2.8.0)
|
15
14
|
public_suffix (>= 2.0.2, < 5.0)
|
16
15
|
ast (2.4.2)
|
17
16
|
coderay (1.1.3)
|
18
|
-
concurrent-ruby (1.1.
|
17
|
+
concurrent-ruby (1.1.9)
|
19
18
|
diff-lcs (1.4.4)
|
20
|
-
faker (2.
|
19
|
+
faker (2.19.0)
|
21
20
|
i18n (>= 1.6, < 2)
|
22
|
-
faraday (1.
|
21
|
+
faraday (1.8.0)
|
22
|
+
faraday-em_http (~> 1.0)
|
23
|
+
faraday-em_synchrony (~> 1.0)
|
23
24
|
faraday-excon (~> 1.1)
|
25
|
+
faraday-httpclient (~> 1.0.1)
|
24
26
|
faraday-net_http (~> 1.0)
|
25
27
|
faraday-net_http_persistent (~> 1.1)
|
28
|
+
faraday-patron (~> 1.0)
|
29
|
+
faraday-rack (~> 1.0)
|
26
30
|
multipart-post (>= 1.2, < 3)
|
27
31
|
ruby2_keywords (>= 0.0.4)
|
32
|
+
faraday-em_http (1.0.0)
|
33
|
+
faraday-em_synchrony (1.0.0)
|
28
34
|
faraday-excon (1.1.0)
|
35
|
+
faraday-httpclient (1.0.1)
|
29
36
|
faraday-net_http (1.0.1)
|
30
|
-
faraday-net_http_persistent (1.
|
31
|
-
|
32
|
-
|
37
|
+
faraday-net_http_persistent (1.2.0)
|
38
|
+
faraday-patron (1.0.0)
|
39
|
+
faraday-rack (1.0.0)
|
40
|
+
ffi (1.15.4)
|
41
|
+
formatador (0.3.0)
|
33
42
|
gitlab (4.17.0)
|
34
43
|
httparty (~> 0.18)
|
35
44
|
terminal-table (~> 1.5, >= 1.5.1)
|
36
|
-
gli (2.20.
|
37
|
-
guard (2.
|
45
|
+
gli (2.20.1)
|
46
|
+
guard (2.18.0)
|
38
47
|
formatador (>= 0.2.4)
|
39
48
|
listen (>= 2.7, < 4.0)
|
40
49
|
lumberjack (>= 1.0.12, < 2.0)
|
41
50
|
nenv (~> 0.1)
|
42
51
|
notiffany (~> 0.0)
|
43
|
-
pry (>= 0.
|
52
|
+
pry (>= 0.13.0)
|
44
53
|
shellany (~> 0.0)
|
45
54
|
thor (>= 0.18.1)
|
46
55
|
guard-compat (1.2.1)
|
@@ -49,21 +58,21 @@ GEM
|
|
49
58
|
guard-compat (~> 1.1)
|
50
59
|
rspec (>= 2.99.0, < 4.0)
|
51
60
|
highline (2.0.3)
|
52
|
-
highline_wrapper (1.
|
61
|
+
highline_wrapper (1.3.0)
|
53
62
|
highline (~> 2.0)
|
54
|
-
httparty (0.
|
63
|
+
httparty (0.20.0)
|
55
64
|
mime-types (~> 3.0)
|
56
65
|
multi_xml (>= 0.5.2)
|
57
66
|
i18n (1.8.10)
|
58
67
|
concurrent-ruby (~> 1.0)
|
59
|
-
listen (3.
|
68
|
+
listen (3.7.0)
|
60
69
|
rb-fsevent (~> 0.10, >= 0.10.3)
|
61
70
|
rb-inotify (~> 0.9, >= 0.9.10)
|
62
71
|
lumberjack (1.2.8)
|
63
72
|
method_source (1.0.0)
|
64
73
|
mime-types (3.3.1)
|
65
74
|
mime-types-data (~> 3.2015)
|
66
|
-
mime-types-data (3.2021.
|
75
|
+
mime-types-data (3.2021.0901)
|
67
76
|
multi_xml (0.6.0)
|
68
77
|
multipart-post (2.1.1)
|
69
78
|
nenv (0.3.0)
|
@@ -73,17 +82,15 @@ GEM
|
|
73
82
|
octokit (4.21.0)
|
74
83
|
faraday (>= 0.9)
|
75
84
|
sawyer (~> 0.8.0, >= 0.5.3)
|
76
|
-
parallel (1.
|
77
|
-
parser (3.0.
|
85
|
+
parallel (1.21.0)
|
86
|
+
parser (3.0.2.0)
|
78
87
|
ast (~> 2.4.1)
|
79
88
|
pry (0.14.1)
|
80
89
|
coderay (~> 1.1)
|
81
90
|
method_source (~> 1.0)
|
82
|
-
psych (3.3.2)
|
83
91
|
public_suffix (4.0.6)
|
84
92
|
rainbow (3.0.0)
|
85
|
-
|
86
|
-
rb-fsevent (0.10.4)
|
93
|
+
rb-fsevent (0.11.0)
|
87
94
|
rb-inotify (0.10.1)
|
88
95
|
ffi (~> 1.0)
|
89
96
|
regexp_parser (2.1.1)
|
@@ -101,40 +108,38 @@ GEM
|
|
101
108
|
diff-lcs (>= 1.2.0, < 2.0)
|
102
109
|
rspec-support (~> 3.10.0)
|
103
110
|
rspec-support (3.10.2)
|
104
|
-
rubocop (1.
|
111
|
+
rubocop (1.22.1)
|
105
112
|
parallel (~> 1.10)
|
106
113
|
parser (>= 3.0.0.0)
|
107
114
|
rainbow (>= 2.2.2, < 4.0)
|
108
115
|
regexp_parser (>= 1.8, < 3.0)
|
109
116
|
rexml
|
110
|
-
rubocop-ast (>= 1.
|
117
|
+
rubocop-ast (>= 1.12.0, < 2.0)
|
111
118
|
ruby-progressbar (~> 1.7)
|
112
119
|
unicode-display_width (>= 1.4.0, < 3.0)
|
113
|
-
rubocop-ast (1.
|
120
|
+
rubocop-ast (1.12.0)
|
114
121
|
parser (>= 3.0.1.1)
|
115
122
|
ruby-progressbar (1.11.0)
|
116
|
-
ruby2_keywords (0.0.
|
123
|
+
ruby2_keywords (0.0.5)
|
117
124
|
sawyer (0.8.2)
|
118
125
|
addressable (>= 2.3.5)
|
119
126
|
faraday (> 0.8, < 2.0)
|
120
127
|
shellany (0.0.1)
|
121
|
-
terminal-table (1.
|
122
|
-
unicode-display_width (~> 1.1, >= 1.1.1)
|
128
|
+
terminal-table (1.6.0)
|
123
129
|
thor (1.1.0)
|
124
|
-
unicode-display_width (1.
|
130
|
+
unicode-display_width (2.1.0)
|
125
131
|
|
126
132
|
PLATFORMS
|
127
133
|
x86_64-darwin-19
|
128
134
|
|
129
135
|
DEPENDENCIES
|
130
|
-
bundler
|
131
|
-
faker
|
136
|
+
bundler
|
137
|
+
faker
|
132
138
|
git_helper!
|
133
|
-
guard-rspec
|
134
|
-
pry
|
135
|
-
|
136
|
-
|
137
|
-
rubocop (~> 1.10)
|
139
|
+
guard-rspec
|
140
|
+
pry
|
141
|
+
rspec
|
142
|
+
rubocop
|
138
143
|
|
139
144
|
BUNDLED WITH
|
140
|
-
2.2.
|
145
|
+
2.2.29
|
data/Guardfile
CHANGED
data/LICENSE.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
BSD 3-Clause "New" or "Revised" License
|
2
|
+
|
3
|
+
Copyright (c) 2020 Emma Sax.
|
4
|
+
All rights reserved.
|
5
|
+
|
6
|
+
Redistribution and use in source and binary forms, with or without
|
7
|
+
modification, are permitted provided that the following conditions are met:
|
8
|
+
|
9
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
10
|
+
list of conditions, and the following disclaimer.
|
11
|
+
|
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.
|
15
|
+
|
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
|
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 [
|
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 [
|
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
|
|
@@ -176,15 +176,27 @@ git-helper new-branch NEW_BRANCH_NAME
|
|
176
176
|
|
177
177
|
The command either accepts a branch name right away or it will ask you for the name of your new branch. Make sure your input does not contain any spaces or special characters.
|
178
178
|
|
179
|
-
|
179
|
+
---
|
180
180
|
|
181
|
-
|
181
|
+
### Contributing
|
182
182
|
|
183
|
-
To
|
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.
|
186
|
+
|
187
|
+
### Security Policy
|
188
|
+
|
189
|
+
To report any security vulnerabilities, please view this repository's [Security Policy](https://github.com/emmahsax/git_helper/security/policy).
|
190
|
+
|
191
|
+
### Licensing
|
192
|
+
|
193
|
+
For information on licensing, please see [LICENSE.md](https://github.com/emmahsax/git_helper/blob/main/LICENSE.md).
|
194
|
+
|
195
|
+
### Code of Conduct
|
184
196
|
|
185
197
|
When interacting with this repository, please follow [Contributor Covenant's Code of Conduct](https://contributor-covenant.org).
|
186
198
|
|
187
|
-
|
199
|
+
### Releasing
|
188
200
|
|
189
201
|
To make a new release of this gem:
|
190
202
|
|
@@ -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
|
6
|
-
|
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,
|
30
|
+
mr = gitlab_client.create_merge_request(local_project, options)
|
30
31
|
|
31
|
-
if mr.diff_refs.
|
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
|
-
|
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
|
-
|
66
|
-
|
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
|
-
|
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
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
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
|
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
|
-
|
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 =
|
24
|
-
|
25
|
-
|
26
|
-
|
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
|
33
|
+
rescue StandardError => e
|
32
34
|
puts 'Could not create pull request:'
|
33
|
-
|
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
|
-
|
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 =
|
55
|
-
|
56
|
-
|
57
|
-
|
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
|
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
|
-
|
67
|
-
|
68
|
-
|
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 ||=
|
139
|
+
@existing_project ||= github_client.repository(local_repo)
|
153
140
|
end
|
154
141
|
|
155
142
|
private def existing_pr
|
156
|
-
@existing_pr ||=
|
143
|
+
@existing_pr ||= github_client.pull_request(local_repo, pr_id)
|
157
144
|
end
|
158
145
|
|
159
|
-
private def
|
160
|
-
@
|
146
|
+
private def github_client
|
147
|
+
@github_client ||= GitHelper::GitHubClient.new
|
161
148
|
end
|
162
149
|
end
|
163
150
|
end
|
data/lib/git_helper/setup.rb
CHANGED
@@ -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
|
-
|
36
|
+
' export PATH=/path/to/computer/home/.git_helper/plugins:$PATH'
|
37
37
|
puts "\nDone!"
|
38
38
|
end
|
39
39
|
|
data/lib/git_helper/version.rb
CHANGED
data/lib/git_helper.rb
CHANGED