git_helper 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -2
- data/lib/git_helper/highline_cli.rb +68 -6
- data/lib/git_helper/local_code.rb +76 -0
- data/lib/git_helper/merge_request.rb +52 -103
- data/lib/git_helper/new_branch.rb +7 -5
- data/lib/git_helper/pull_request.rb +45 -87
- data/lib/git_helper/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7959639f26bda279bb9154f76ba1d5041802d5ac63fbb02d6df3ca85d55040ca
|
4
|
+
data.tar.gz: 59144b9c94dd74ac2bc8c05417363ee37f926a2266fe623e3c13032750910025
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 104ed8f0605c4471b0e4163dfe7148a4a5b2139871150e5577ed371035419122d9c64571aa2ff0897d812e5a08982c3cbd544e6d9936d36d792df2f0fbe9248d
|
7
|
+
data.tar.gz: 4eef1f32e7c147279228388ade7056a46568cacae9fe61dcd58534b42b50c2eb422a8fd9c043ff9fdf138595dccf8a17d7771be877fa2c2ba6bf13eaaa9ec5ff
|
data/README.md
CHANGED
@@ -119,7 +119,11 @@ git-helper merge-request -c
|
|
119
119
|
git-helper merge-request -m
|
120
120
|
```
|
121
121
|
|
122
|
-
If you're trying to create a merge request, the command will provide an autogenerated merge request title based on your branch name
|
122
|
+
If you're trying to create a merge request, the command will provide an autogenerated merge request title based on your branch name. It will separate the branch name by `'_'` if underscores are in the branch, or `'-'` if dashes are present. Then it will join the list of words together by spaces. If there's a pattern in the form of `jira-123` or `jira_123` in the first part of the branch name, then it'll add `JIRA-123` to the first part of the pull request. You can respond 'yes' or 'no'. If you respond 'no', you can provide your own merge request title.
|
123
|
+
|
124
|
+
The command will also ask you if the default branch of the repository is the proper base branch to use. You can say 'yes' or 'no'. If you respond 'no', then you can give the command your chosen base base.
|
125
|
+
|
126
|
+
Lastly, it'll ask the user to apply any merge request templates found at any `*/merge_request_template.md` file or any file in `.gitlab/merge_request_templates/*.md`. Applying any template is optional, and from the command's standpoint, a user can make an empty merge request if they desire. If a GitLab project automatically adds a template, then it may create a merge request with a default template anyway.
|
123
127
|
|
124
128
|
If you're requesting to merge a merge request, the command will ask you the number ID of the merge request you wish to accept. The command will also ask you what type of merge to do: regular merging or squashing. The commit message to use during the merge/squash will be the title of the pull request.
|
125
129
|
|
@@ -149,7 +153,11 @@ git-helper pull-request -c
|
|
149
153
|
git-helper pull-request -m
|
150
154
|
```
|
151
155
|
|
152
|
-
If you're trying to create a pull request, the command will provide an autogenerated pull request title based on your branch name
|
156
|
+
If you're trying to create a pull request, the command will provide an autogenerated pull request title based on your branch name. It will separate the branch name by `'_'` if underscores are in the branch, or `'-'` if dashes are present. Then it will join the list of words together by spaces. If there's a pattern in the form of `jira-123` or `jira_123` in the first part of the branch name, then it'll add `JIRA-123` to the first part of the pull request. You can respond 'yes' or 'no'. If you respond 'no', you can provide your own pull request title.
|
157
|
+
|
158
|
+
The command will also ask you if the default branch of the repository is the proper base branch to use. You can say 'yes' or 'no'. If you respond 'no', then you can give the command your chosen base base.
|
159
|
+
|
160
|
+
Lastly, it'll ask the user to apply any pull request templates found at any `*/pull_request_template.md` file or any file in `.github/PULL_REQUEST_TEMPLATE/*.md`. Applying any template is optional, and a user can make an empty pull request if they desire.
|
153
161
|
|
154
162
|
If you're requesting to merge a pull request, the command will ask you the number ID of the pull request you wish to merge. The command will also ask you what type of merge to do: regular merging, squashing, or rebasing. The commit message to use during the merge/squash/rebase will be the title of the pull request.
|
155
163
|
|
@@ -2,24 +2,86 @@ require 'highline'
|
|
2
2
|
|
3
3
|
module GitHelper
|
4
4
|
class HighlineCli
|
5
|
-
def
|
6
|
-
|
5
|
+
def new_branch_name
|
6
|
+
ask('New branch name?')
|
7
|
+
end
|
8
|
+
|
9
|
+
def title
|
10
|
+
ask('Title?')
|
11
|
+
end
|
12
|
+
|
13
|
+
def base_branch
|
14
|
+
ask('Base branch?')
|
15
|
+
end
|
16
|
+
|
17
|
+
def merge_request_id
|
18
|
+
ask('Merge Request ID?')
|
19
|
+
end
|
20
|
+
|
21
|
+
def pull_request_id
|
22
|
+
ask('Pull Request ID?')
|
23
|
+
end
|
24
|
+
|
25
|
+
def accept_autogenerated_title?(autogenerated_title)
|
26
|
+
return false unless autogenerated_title
|
27
|
+
answer = ask("Accept the autogenerated merge request title '#{autogenerated_title}'? (y/n)")
|
28
|
+
!!(answer =~ /^y/i)
|
29
|
+
end
|
30
|
+
|
31
|
+
def base_branch_default?(default_branch)
|
32
|
+
answer = ask("Is '#{default_branch}' the correct base branch for your new merge request? (y/n)")
|
33
|
+
!!(answer =~ /^y/i)
|
34
|
+
end
|
35
|
+
|
36
|
+
def squash_merge_request?
|
37
|
+
answer = ask('Squash merge request? (y/n)')
|
38
|
+
!!(answer =~ /^y/i)
|
39
|
+
end
|
40
|
+
|
41
|
+
def remove_source_branch?
|
42
|
+
answer = ask('Remove source branch after merging? (y/n)')
|
43
|
+
!!(answer =~ /^y/i)
|
44
|
+
end
|
45
|
+
|
46
|
+
def merge_method
|
47
|
+
merge_options = [ 'merge', 'squash', 'rebase' ]
|
48
|
+
index = ask_options("Merge method?", merge_options)
|
49
|
+
merge_options[index]
|
50
|
+
end
|
51
|
+
|
52
|
+
def apply_template?(template_file_name)
|
53
|
+
answer = ask("Apply the merge request template from #{template_file_name}? (y/n)")
|
54
|
+
!!(answer =~ /^y/i)
|
55
|
+
end
|
56
|
+
|
57
|
+
def template_to_apply(template_options, request_type)
|
58
|
+
complete_options = template_options << 'None'
|
59
|
+
index = ask_options("Which #{request_type} request template should be applied?", complete_options)
|
60
|
+
complete_options[index]
|
61
|
+
end
|
62
|
+
|
63
|
+
#######################
|
64
|
+
### GENERAL METHODS ###
|
65
|
+
#######################
|
66
|
+
|
67
|
+
private def ask(prompt)
|
68
|
+
highline_client.ask(prompt) do |conf|
|
7
69
|
conf.readline = true
|
8
70
|
end.to_s
|
9
71
|
end
|
10
72
|
|
11
|
-
def ask_options(prompt, choices)
|
73
|
+
private def ask_options(prompt, choices)
|
12
74
|
choices_as_string_options = ''
|
13
75
|
choices.each { |choice| choices_as_string_options << "#{choices.index(choice) + 1}. #{choice}\n" }
|
14
76
|
compiled_prompt = "#{prompt}\n#{choices_as_string_options.strip}"
|
15
77
|
|
16
|
-
|
78
|
+
highline_client.ask(compiled_prompt) do |conf|
|
17
79
|
conf.readline = true
|
18
80
|
end.to_i - 1
|
19
81
|
end
|
20
82
|
|
21
|
-
private def
|
22
|
-
@
|
83
|
+
private def highline_client
|
84
|
+
@highline_client ||= HighLine.new
|
23
85
|
end
|
24
86
|
end
|
25
87
|
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
module GitHelper
|
2
|
+
class LocalCode
|
3
|
+
def new_branch(branch_name)
|
4
|
+
system("git pull")
|
5
|
+
system("git branch --no-track #{branch_name}")
|
6
|
+
system("git checkout #{branch_name}")
|
7
|
+
system("git push --set-upstream origin #{branch_name}")
|
8
|
+
end
|
9
|
+
|
10
|
+
def name
|
11
|
+
# Get the repo/project name by looking in the remote URLs for the full name
|
12
|
+
`git remote -v`.scan(/\S[\s]*[\S]+.com[\S]{1}([\S]*).git/).first.first
|
13
|
+
end
|
14
|
+
|
15
|
+
def branch
|
16
|
+
# Get the current branch by looking in the list of branches for the *
|
17
|
+
`git branch`.scan(/\*\s([\S]*)/).first.first
|
18
|
+
end
|
19
|
+
|
20
|
+
def default_branch(project_name, external_client, client_type)
|
21
|
+
if client_type == :octokit # GitHub repository
|
22
|
+
external_client.repository(project_name).default_branch
|
23
|
+
elsif client_type == :gitlab # GitLab project
|
24
|
+
page_number = 1
|
25
|
+
counter = 1
|
26
|
+
branches = []
|
27
|
+
|
28
|
+
while counter > 0
|
29
|
+
break if default_branch = branches.select { |branch| branch.default }.first
|
30
|
+
page_branches = external_client.branches(project_name, page: page_number, per_page: 100)
|
31
|
+
branches = page_branches
|
32
|
+
counter = page_branches.count
|
33
|
+
page_number += 1
|
34
|
+
end
|
35
|
+
|
36
|
+
default_branch.name
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def template_options(template_identifiers)
|
41
|
+
nested_templates = Dir.glob(
|
42
|
+
File.join("**/#{template_identifiers[:nested_directory_name]}", "*.md"),
|
43
|
+
File::FNM_DOTMATCH | File::FNM_CASEFOLD
|
44
|
+
)
|
45
|
+
non_nested_templates = Dir.glob(
|
46
|
+
File.join("**", "#{template_identifiers[:non_nested_file_name]}.md"),
|
47
|
+
File::FNM_DOTMATCH | File::FNM_CASEFOLD
|
48
|
+
)
|
49
|
+
nested_templates.concat(non_nested_templates).uniq
|
50
|
+
end
|
51
|
+
|
52
|
+
def read_template(file_name)
|
53
|
+
File.open(file_name).read
|
54
|
+
end
|
55
|
+
|
56
|
+
def generate_title(local_branch)
|
57
|
+
branch_arr = local_branch.split(local_branch.include?('_') ? '_' : '-')
|
58
|
+
|
59
|
+
return if branch_arr.empty?
|
60
|
+
|
61
|
+
if branch_arr.length == 1
|
62
|
+
branch_arr.first.capitalize
|
63
|
+
elsif branch_arr[0].scan(/([\w]+)/).any? && branch_arr[1].scan(/([\d]+)/).any? # branch includes jira_123 at beginning
|
64
|
+
issue = "#{branch_arr[0].upcase}-#{branch_arr[1]}"
|
65
|
+
description = branch_arr[2..-1].join(' ')
|
66
|
+
"#{issue} #{description.capitalize}"
|
67
|
+
elsif branch_arr[0].scan(/([\w]+-[\d]+)/).any? # branch includes string jira-123 at beginning
|
68
|
+
issue = branch_arr[0].upcase
|
69
|
+
description = branch_arr[1..-1].join(' ')
|
70
|
+
"#{issue} #{description.capitalize}"
|
71
|
+
else # plain words
|
72
|
+
branch_arr[0..-1].join(' ').capitalize
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require_relative './gitlab_client.rb'
|
2
2
|
require_relative './highline_cli.rb'
|
3
|
+
require_relative './local_code.rb'
|
3
4
|
|
4
5
|
module GitHelper
|
5
6
|
class GitLabMergeRequest
|
@@ -36,8 +37,8 @@ module GitHelper
|
|
36
37
|
# Ask these questions right away
|
37
38
|
mr_id
|
38
39
|
options = {}
|
39
|
-
options[:should_remove_source_branch] = remove_source_branch
|
40
|
-
options[:squash] = squash_merge_request
|
40
|
+
options[:should_remove_source_branch] = remove_source_branch
|
41
|
+
options[:squash] = squash_merge_request
|
41
42
|
options[:squash_commit_message] = existing_mr_title
|
42
43
|
|
43
44
|
puts "Merging merge request: #{mr_id}"
|
@@ -56,135 +57,79 @@ module GitHelper
|
|
56
57
|
end
|
57
58
|
|
58
59
|
private def local_project
|
59
|
-
|
60
|
-
remotes = `git remote -v`
|
61
|
-
return remotes.scan(/\S[\s]*[\S]+.com[\S]{1}([\S]*).git/).first.first
|
60
|
+
@local_project ||= local_code.name
|
62
61
|
end
|
63
62
|
|
64
63
|
private def local_branch
|
65
|
-
|
66
|
-
branches = `git branch`
|
67
|
-
return branches.scan(/\*\s([\S]*)/).first.first
|
64
|
+
@local_branch ||= local_code.branch
|
68
65
|
end
|
69
66
|
|
70
|
-
private def
|
71
|
-
|
72
|
-
apply_template?(mr_template_options.first) ? File.open(mr_template_options.first).read : ''
|
73
|
-
else
|
74
|
-
template_file_name_to_apply = template_to_apply
|
75
|
-
template_file_name_to_apply == "None" ? '' : File.open(template_file_name_to_apply).read
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
private def mr_id
|
80
|
-
@mr_id ||= cli.ask('Merge Request ID?')
|
67
|
+
private def autogenerated_title
|
68
|
+
@autogenerated_title ||= local_code.generate_title(local_branch)
|
81
69
|
end
|
82
70
|
|
83
|
-
private def
|
84
|
-
@
|
71
|
+
private def default_branch
|
72
|
+
@default_branch ||= local_code.default_branch(local_project, gitlab_client, :gitlab)
|
85
73
|
end
|
86
74
|
|
87
|
-
private def
|
88
|
-
@
|
75
|
+
private def mr_template_options
|
76
|
+
@mr_template_options ||= local_code.template_options({
|
77
|
+
nested_directory_name: "merge_request_templates",
|
78
|
+
non_nested_file_name: "merge_request_template"
|
79
|
+
})
|
89
80
|
end
|
90
81
|
|
91
|
-
private def
|
92
|
-
@
|
82
|
+
private def mr_id
|
83
|
+
@mr_id ||= cli.merge_request_id
|
93
84
|
end
|
94
85
|
|
95
|
-
private def
|
96
|
-
@
|
86
|
+
private def squash_merge_request
|
87
|
+
@squash_merge_request ||= cli.squash_merge_request?
|
97
88
|
end
|
98
89
|
|
99
|
-
private def
|
100
|
-
@
|
90
|
+
private def remove_source_branch
|
91
|
+
@remove_source_branch ||= cli.remove_source_branch?
|
101
92
|
end
|
102
93
|
|
103
|
-
private def
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
return branch_arr.first.capitalize
|
110
|
-
end
|
111
|
-
|
112
|
-
if branch_arr[0].scan(/([\w]+)/).empty? || branch_arr[1].scan(/([\d]+)/).empty?
|
113
|
-
branch_arr[0..-1].join(' ').capitalize
|
114
|
-
else
|
115
|
-
issue = branch_arr[0].upcase
|
116
|
-
|
117
|
-
if issue.include?('-')
|
118
|
-
description = branch_arr[1..-1].join(' ')
|
119
|
-
else
|
120
|
-
issue = "#{issue}-#{branch_arr[1]}"
|
121
|
-
description = branch_arr[2..-1].join(' ')
|
122
|
-
end
|
123
|
-
|
124
|
-
"#{issue} #{description.capitalize}"
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
private def default_branch
|
129
|
-
return @default_branch if @default_branch
|
130
|
-
page_number = 1
|
131
|
-
counter = 1
|
132
|
-
branches = []
|
133
|
-
|
134
|
-
while counter > 0
|
135
|
-
break if default_branch = branches.select { |branch| branch.default }.first
|
136
|
-
page_branches = gitlab_client.branches(local_project, page: page_number, per_page: 100)
|
137
|
-
branches = page_branches
|
138
|
-
counter = page_branches.count
|
139
|
-
page_number += 1
|
140
|
-
end
|
141
|
-
|
142
|
-
@default_branch = default_branch.name
|
143
|
-
end
|
144
|
-
|
145
|
-
private def template_to_apply
|
146
|
-
return @template_to_apply if @template_to_apply
|
147
|
-
complete_options = mr_template_options << 'None'
|
148
|
-
index = cli.ask_options("Which merge request template should be applied?", complete_options)
|
149
|
-
@template_to_apply = complete_options[index]
|
94
|
+
private def new_mr_title
|
95
|
+
@new_mr_title ||= if cli.accept_autogenerated_title?(autogenerated_title)
|
96
|
+
autogenerated_title
|
97
|
+
else
|
98
|
+
cli.title
|
99
|
+
end
|
150
100
|
end
|
151
101
|
|
152
|
-
private def
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
102
|
+
private def base_branch
|
103
|
+
@base_branch ||= if cli.base_branch_default?(default_branch)
|
104
|
+
default_branch
|
105
|
+
else
|
106
|
+
cli.base_branch
|
107
|
+
end
|
157
108
|
end
|
158
109
|
|
159
|
-
private def
|
160
|
-
|
161
|
-
!!(answer =~ /^y/i)
|
110
|
+
private def new_mr_body
|
111
|
+
@new_mr_body ||= template_name_to_apply ? local_code.read_template(template_name_to_apply) : ''
|
162
112
|
end
|
163
113
|
|
164
|
-
private def
|
165
|
-
|
114
|
+
private def template_name_to_apply
|
115
|
+
return @template_name_to_apply if @template_name_to_apply
|
116
|
+
@template_name_to_apply = nil
|
166
117
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
118
|
+
unless mr_template_options.empty?
|
119
|
+
if mr_template_options.count == 1
|
120
|
+
apply_single_template = cli.apply_template?(mr_template_options.first)
|
121
|
+
@template_name_to_apply = mr_template_options.first if apply_single_template
|
122
|
+
else
|
123
|
+
response = cli.template_to_apply(mr_template_options, 'merge')
|
124
|
+
@template_name_to_apply = response unless response == "None"
|
125
|
+
end
|
172
126
|
end
|
173
|
-
end
|
174
|
-
|
175
|
-
private def squash_merge_request?
|
176
|
-
answer = cli.ask('Squash merge request? (y/n)')
|
177
|
-
!!(answer =~ /^y/i)
|
178
|
-
end
|
179
127
|
|
180
|
-
|
181
|
-
answer = cli.ask('Remove source branch after merging? (y/n)')
|
182
|
-
!!(answer =~ /^y/i)
|
128
|
+
@template_name_to_apply
|
183
129
|
end
|
184
130
|
|
185
|
-
private def
|
186
|
-
|
187
|
-
!!(answer =~ /^y/i)
|
131
|
+
private def existing_mr_title
|
132
|
+
@existing_mr_title ||= gitlab_client.merge_request(local_project, mr_id).title
|
188
133
|
end
|
189
134
|
|
190
135
|
private def gitlab_client
|
@@ -194,5 +139,9 @@ module GitHelper
|
|
194
139
|
private def cli
|
195
140
|
@cli ||= GitHelper::HighlineCli.new
|
196
141
|
end
|
142
|
+
|
143
|
+
private def local_code
|
144
|
+
@local_code ||= GitHelper::LocalCode.new
|
145
|
+
end
|
197
146
|
end
|
198
147
|
end
|
@@ -1,18 +1,20 @@
|
|
1
1
|
require_relative './highline_cli.rb'
|
2
|
+
require_relative './local_code.rb'
|
2
3
|
|
3
4
|
module GitHelper
|
4
5
|
class NewBranch
|
5
6
|
def execute(new_branch_name = nil)
|
6
|
-
branch_name = new_branch_name || cli.
|
7
|
+
branch_name = new_branch_name || cli.new_branch_name
|
7
8
|
puts "Attempting to create a new branch: #{branch_name}"
|
8
|
-
|
9
|
-
system("git branch --no-track #{branch_name}")
|
10
|
-
system("git checkout #{branch_name}")
|
11
|
-
system("git push --set-upstream origin #{branch_name}")
|
9
|
+
local_code.new_branch(branch_name)
|
12
10
|
end
|
13
11
|
|
14
12
|
private def cli
|
15
13
|
@cli ||= GitHelper::HighlineCli.new
|
16
14
|
end
|
15
|
+
|
16
|
+
private def local_code
|
17
|
+
@local_code ||= GitHelper::LocalCode.new
|
18
|
+
end
|
17
19
|
end
|
18
20
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require_relative './octokit_client.rb'
|
2
2
|
require_relative './highline_cli.rb'
|
3
|
+
require_relative './local_code.rb'
|
3
4
|
|
4
5
|
module GitHelper
|
5
6
|
class GitHubPullRequest
|
@@ -67,122 +68,75 @@ module GitHelper
|
|
67
68
|
end
|
68
69
|
|
69
70
|
private def local_repo
|
70
|
-
|
71
|
-
remotes = `git remote -v`
|
72
|
-
return remotes.scan(/\S[\s]*[\S]+.com[\S]{1}([\S]*).git/).first.first
|
71
|
+
@local_project ||= local_code.name
|
73
72
|
end
|
74
73
|
|
75
74
|
private def local_branch
|
76
|
-
|
77
|
-
branches = `git branch`
|
78
|
-
return branches.scan(/\*\s([\S]*)/).first.first
|
75
|
+
@local_branch ||= local_code.branch
|
79
76
|
end
|
80
77
|
|
81
|
-
private def
|
82
|
-
|
83
|
-
apply_template?(pr_template_options.first) ? File.open(pr_template_options.first).read : ''
|
84
|
-
else
|
85
|
-
template_file_name_to_apply = template_to_apply
|
86
|
-
template_file_name_to_apply == "None" ? '' : File.open(template_file_name_to_apply).read
|
87
|
-
end
|
78
|
+
private def autogenerated_title
|
79
|
+
@autogenerated_title ||= local_code.generate_title(local_branch)
|
88
80
|
end
|
89
81
|
|
90
|
-
private def
|
91
|
-
|
82
|
+
private def default_branch
|
83
|
+
@default_branch ||= local_code.default_branch(local_repo, octokit_client, :octokit)
|
92
84
|
end
|
93
85
|
|
94
|
-
private def
|
95
|
-
@
|
86
|
+
private def pr_template_options
|
87
|
+
@pr_template_options ||= local_code.template_options({
|
88
|
+
nested_directory_name: "PULL_REQUEST_TEMPLATE",
|
89
|
+
non_nested_file_name: "pull_request_template"
|
90
|
+
})
|
96
91
|
end
|
97
92
|
|
98
|
-
private def
|
99
|
-
@
|
93
|
+
private def pr_id
|
94
|
+
@pr_id ||= cli.pull_request_id
|
100
95
|
end
|
101
96
|
|
102
|
-
private def
|
103
|
-
@
|
97
|
+
private def merge_method
|
98
|
+
@merge_method ||= cli.merge_method
|
104
99
|
end
|
105
100
|
|
106
|
-
private def
|
107
|
-
@
|
101
|
+
private def new_pr_title
|
102
|
+
@new_pr_title ||= if cli.accept_autogenerated_title?(autogenerated_title)
|
103
|
+
autogenerated_title
|
104
|
+
else
|
105
|
+
cli.title
|
106
|
+
end
|
108
107
|
end
|
109
108
|
|
110
109
|
private def base_branch
|
111
|
-
@base_branch ||=
|
110
|
+
@base_branch ||= if cli.base_branch_default?(default_branch)
|
111
|
+
default_branch
|
112
|
+
else
|
113
|
+
cli.base_branch
|
114
|
+
end
|
112
115
|
end
|
113
116
|
|
114
|
-
private def
|
115
|
-
@
|
117
|
+
private def new_pr_body
|
118
|
+
@new_pr_body ||= template_name_to_apply ? local_code.read_template(template_name_to_apply) : ''
|
116
119
|
end
|
117
120
|
|
118
|
-
private def
|
119
|
-
|
120
|
-
|
121
|
-
return if branch_arr.empty?
|
121
|
+
private def template_name_to_apply
|
122
|
+
return @template_name_to_apply if @template_name_to_apply
|
123
|
+
@template_name_to_apply = nil
|
122
124
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
if branch_arr[0].scan(/([\w]+)/).empty? || branch_arr[1].scan(/([\d]+)/).empty?
|
128
|
-
branch_arr[0..-1].join(' ').capitalize
|
129
|
-
else
|
130
|
-
issue = branch_arr[0].upcase
|
131
|
-
|
132
|
-
if issue.include?('-')
|
133
|
-
description = branch_arr[1..-1].join(' ')
|
125
|
+
unless pr_template_options.empty?
|
126
|
+
if pr_template_options.count == 1
|
127
|
+
apply_single_template = cli.apply_template?(pr_template_options.first)
|
128
|
+
@template_name_to_apply = pr_template_options.first if apply_single_template
|
134
129
|
else
|
135
|
-
|
136
|
-
|
130
|
+
response = cli.template_to_apply(pr_template_options, 'pull')
|
131
|
+
@template_name_to_apply = response unless response == "None"
|
137
132
|
end
|
138
|
-
|
139
|
-
"#{issue} #{description.capitalize}"
|
140
133
|
end
|
141
|
-
end
|
142
134
|
|
143
|
-
|
144
|
-
@default_branch ||= octokit_client.repository(local_repo).default_branch
|
145
|
-
end
|
146
|
-
|
147
|
-
private def merge_method
|
148
|
-
return @merge_method if @merge_method
|
149
|
-
index = cli.ask_options("Merge method?", merge_options)
|
150
|
-
@merge_method = merge_options[index]
|
151
|
-
end
|
152
|
-
|
153
|
-
private def template_to_apply
|
154
|
-
return @template_to_apply if @template_to_apply
|
155
|
-
complete_options = pr_template_options << 'None'
|
156
|
-
index = cli.ask_options("Which pull request template should be applied?", complete_options)
|
157
|
-
@template_to_apply = complete_options[index]
|
135
|
+
@template_name_to_apply
|
158
136
|
end
|
159
137
|
|
160
|
-
private def
|
161
|
-
|
162
|
-
nested_templates = Dir.glob(File.join("**/PULL_REQUEST_TEMPLATE", "*.md"), File::FNM_DOTMATCH | File::FNM_CASEFOLD)
|
163
|
-
non_nested_templates = Dir.glob(File.join("**", "pull_request_template.md"), File::FNM_DOTMATCH | File::FNM_CASEFOLD)
|
164
|
-
@pr_template_options = nested_templates.concat(non_nested_templates)
|
165
|
-
end
|
166
|
-
|
167
|
-
private def base_branch_default?
|
168
|
-
answer = cli.ask("Is '#{default_branch}' the correct base branch for your new pull request? (y/n)")
|
169
|
-
!!(answer =~ /^y/i)
|
170
|
-
end
|
171
|
-
|
172
|
-
private def accept_autogenerated_title?
|
173
|
-
title = autogenerated_title
|
174
|
-
|
175
|
-
if title
|
176
|
-
answer = cli.ask("Accept the autogenerated merge request title '#{title}'? (y/n)")
|
177
|
-
!!(answer =~ /^y/i)
|
178
|
-
else
|
179
|
-
false
|
180
|
-
end
|
181
|
-
end
|
182
|
-
|
183
|
-
private def apply_template?(template_file_name)
|
184
|
-
answer = cli.ask("Apply the pull request template from #{template_file_name}? (y/n)")
|
185
|
-
!!(answer =~ /^y/i)
|
138
|
+
private def existing_pr_title
|
139
|
+
@existing_pr_title ||= octokit_client.pull_request(local_repo, pr_id).title
|
186
140
|
end
|
187
141
|
|
188
142
|
private def octokit_client
|
@@ -192,5 +146,9 @@ module GitHelper
|
|
192
146
|
private def cli
|
193
147
|
@cli ||= GitHelper::HighlineCli.new
|
194
148
|
end
|
149
|
+
|
150
|
+
private def local_code
|
151
|
+
@local_code ||= GitHelper::LocalCode.new
|
152
|
+
end
|
195
153
|
end
|
196
154
|
end
|
data/lib/git_helper/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git_helper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.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: 2020-
|
11
|
+
date: 2020-10-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: gitlab
|
@@ -159,6 +159,7 @@ files:
|
|
159
159
|
- lib/git_helper/git_config_reader.rb
|
160
160
|
- lib/git_helper/gitlab_client.rb
|
161
161
|
- lib/git_helper/highline_cli.rb
|
162
|
+
- lib/git_helper/local_code.rb
|
162
163
|
- lib/git_helper/merge_request.rb
|
163
164
|
- lib/git_helper/new_branch.rb
|
164
165
|
- lib/git_helper/octokit_client.rb
|