git_helper 3.3.1 → 3.3.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -0
  3. data/Gemfile.lock +32 -9
  4. data/Guardfile +3 -1
  5. data/README.md +4 -4
  6. data/Rakefile +2 -0
  7. data/bin/git-helper +18 -13
  8. data/lib/git_helper.rb +6 -2
  9. data/lib/git_helper/change_remote.rb +15 -6
  10. data/lib/git_helper/checkout_default.rb +2 -0
  11. data/lib/git_helper/clean_branches.rb +2 -0
  12. data/lib/git_helper/code_request.rb +33 -19
  13. data/lib/git_helper/empty_commit.rb +2 -0
  14. data/lib/git_helper/forget_local_commits.rb +2 -0
  15. data/lib/git_helper/git_config_reader.rb +3 -5
  16. data/lib/git_helper/gitlab_client.rb +2 -0
  17. data/lib/git_helper/local_code.rb +18 -8
  18. data/lib/git_helper/merge_request.rb +90 -70
  19. data/lib/git_helper/new_branch.rb +3 -1
  20. data/lib/git_helper/octokit_client.rb +2 -0
  21. data/lib/git_helper/pull_request.rb +97 -66
  22. data/lib/git_helper/setup.rb +52 -32
  23. data/lib/git_helper/version.rb +3 -1
  24. data/spec/git_helper/change_remote_spec.rb +24 -24
  25. data/spec/git_helper/checkout_default_spec.rb +2 -0
  26. data/spec/git_helper/clean_branches_spec.rb +2 -0
  27. data/spec/git_helper/code_request_spec.rb +30 -28
  28. data/spec/git_helper/empty_commit_spec.rb +2 -0
  29. data/spec/git_helper/forget_local_commits_spec.rb +2 -0
  30. data/spec/git_helper/git_config_reader_spec.rb +4 -2
  31. data/spec/git_helper/gitlab_client_spec.rb +2 -0
  32. data/spec/git_helper/local_code_spec.rb +2 -0
  33. data/spec/git_helper/merge_request_spec.rb +24 -23
  34. data/spec/git_helper/new_branch_spec.rb +10 -8
  35. data/spec/git_helper/octokit_client_spec.rb +2 -0
  36. data/spec/git_helper/pull_request_spec.rb +20 -18
  37. data/spec/git_helper/setup_spec.rb +34 -26
  38. data/spec/spec_helper.rb +4 -1
  39. metadata +34 -9
  40. data/lib/git_helper/highline_cli.rb +0 -33
  41. data/spec/git_helper/highline_cli_spec.rb +0 -51
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GitHelper
2
4
  class EmptyCommit
3
5
  def execute
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GitHelper
2
4
  class ForgetLocalCommits
3
5
  def execute
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GitHelper
2
4
  class GitConfigReader
3
5
  def gitlab_token
@@ -17,15 +19,11 @@ module GitHelper
17
19
  end
18
20
 
19
21
  def git_config_file_path
20
- Dir.pwd.scan(/\A\/[\w]*\/[\w]*\//).first << git_config_file
22
+ "#{Dir.pwd.scan(%r{\A/\w*/\w*/}).first}.git_helper/config.yml"
21
23
  end
22
24
 
23
25
  private def config_file
24
26
  YAML.load_file(git_config_file_path)
25
27
  end
26
-
27
- private def git_config_file
28
- '.git_helper/config.yml'
29
- end
30
28
  end
31
29
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GitHelper
2
4
  class GitLabClient
3
5
  def client
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GitHelper
2
4
  class LocalCode
3
5
  def checkout_default
@@ -44,20 +46,20 @@ module GitHelper
44
46
  end
45
47
 
46
48
  def https_remote?(remote)
47
- remote.scan(/(https:\/\/)/).any?
49
+ remote.scan(%r{(https://)}).any?
48
50
  end
49
51
 
50
52
  def remote_project(remote)
51
53
  if https_remote?(remote)
52
- remote.scan(/https:\/\/[\S]+\/([\S]*).git/).first.first
54
+ remote.scan(%r{https://\S+/(\S*).git}).first.first
53
55
  elsif ssh_remote?(remote)
54
- remote.scan(/\/([\S]*).git/).first.first
56
+ remote.scan(%r{/(\S*).git}).first.first
55
57
  end
56
58
  end
57
59
 
58
60
  def remote_source(remote)
59
61
  if https_remote?(remote)
60
- remote.scan(/https:\/\/([a-zA-z.]+)\//).first.first
62
+ remote.scan(%r{https://([a-zA-z.]+)/}).first.first
61
63
  elsif ssh_remote?(remote)
62
64
  remote.scan(/git@([a-zA-z.]+):/).first.first
63
65
  end
@@ -73,18 +75,20 @@ module GitHelper
73
75
 
74
76
  def project_name
75
77
  # Get the repo/project name by looking in the remote URLs for the full name
76
- `git remote -v`.scan(/\S[\s]*[\S]+.com[\S]{1}([\S]*).git/).first.first
78
+ `git remote -v`.scan(/\S\s*\S+.com\S{1}(\S*).git/).first.first
77
79
  end
78
80
 
79
81
  def branch
80
82
  # Get the current branch by looking in the list of branches for the *
81
- `git branch`.scan(/\*\s([\S]*)/).first.first
83
+ `git branch`.scan(/\*\s(\S*)/).first.first
82
84
  end
83
85
 
84
86
  def default_branch
85
87
  `git symbolic-ref refs/remotes/origin/HEAD | sed "s@^refs/remotes/origin/@@" | tr -d "\n"`
86
88
  end
87
89
 
90
+ # rubocop:disable Metrics/AbcSize
91
+ # rubocop:disable Metrics/MethodLength
88
92
  def template_options(identifiers)
89
93
  nested_templates = Dir.glob(
90
94
  File.join("#{identifiers[:template_directory]}/#{identifiers[:nested_directory_name]}", '*.md'),
@@ -100,11 +104,15 @@ module GitHelper
100
104
  )
101
105
  nested_templates.concat(non_nested_templates).concat(root_templates).uniq
102
106
  end
107
+ # rubocop:enable Metrics/MethodLength
108
+ # rubocop:enable Metrics/AbcSize
103
109
 
104
110
  def read_template(file_name)
105
111
  File.open(file_name).read
106
112
  end
107
113
 
114
+ # rubocop:disable Metrics/AbcSize
115
+ # rubocop:disable Metrics/MethodLength
108
116
  def generate_title(local_branch)
109
117
  branch_arr = local_branch.split(local_branch.include?('_') ? '_' : '-')
110
118
 
@@ -112,11 +120,11 @@ module GitHelper
112
120
 
113
121
  if branch_arr.length == 1
114
122
  branch_arr.first.capitalize
115
- elsif branch_arr[0].scan(/([\w]+)/).any? && branch_arr[1].scan(/([\d]+)/).any? # branch includes jira_123 at beginning
123
+ elsif branch_arr[0].scan(/(\w+)/).any? && branch_arr[1].scan(/(\d+)/).any? # branch includes jira_123 at beginning
116
124
  issue = "#{branch_arr[0].upcase}-#{branch_arr[1]}"
117
125
  description = branch_arr[2..-1].join(' ')
118
126
  "#{issue} #{description.capitalize}"
119
- elsif branch_arr[0].scan(/([\w]+-[\d]+)/).any? # branch includes string jira-123 at beginning
127
+ elsif branch_arr[0].scan(/(\w+-\d+)/).any? # branch includes string jira-123 at beginning
120
128
  issue = branch_arr[0].upcase
121
129
  description = branch_arr[1..-1].join(' ')
122
130
  "#{issue} #{description.capitalize}"
@@ -124,5 +132,7 @@ module GitHelper
124
132
  branch_arr[0..-1].join(' ').capitalize
125
133
  end
126
134
  end
135
+ # rubocop:enable Metrics/MethodLength
136
+ # rubocop:enable Metrics/AbcSize
127
137
  end
128
138
  end
@@ -1,78 +1,84 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GitHelper
2
4
  class GitLabMergeRequest
3
- attr_accessor :local_project, :local_branch, :local_code, :cli, :base_branch, :new_mr_title
5
+ attr_accessor :local_project, :local_branch, :local_code, :highline, :base_branch, :new_mr_title
4
6
 
5
7
  def initialize(options)
6
8
  @local_project = options[:local_project]
7
9
  @local_branch = options[:local_branch]
8
10
  @local_code = options[:local_code]
9
- @cli = options[:cli]
11
+ @highline = options[:highline]
10
12
  end
11
13
 
14
+ # rubocop:disable Metrics/MethodLength
15
+ # rubocop:disable Metrics/AbcSize
12
16
  def create(options)
13
17
  @base_branch = options[:base_branch]
14
18
  @new_mr_title = options[:new_title]
15
19
 
16
- begin
17
- options = {
18
- source_branch: local_branch,
19
- target_branch: base_branch,
20
- squash: squash_merge_request,
21
- remove_source_branch: remove_source_branch,
22
- description: new_mr_body
23
- }
24
-
25
- puts "Creating merge request: #{new_mr_title}"
26
- mr = gitlab_client.create_merge_request(local_project, new_mr_title, options)
27
-
28
- if mr.diff_refs.base_sha == mr.diff_refs.head_sha
29
- puts "Merge request was created, but no commits have been pushed to GitLab: #{mr.web_url}"
30
- else
31
- puts "Merge request successfully created: #{mr.web_url}"
32
- end
33
- rescue Gitlab::Error::Conflict => e
34
- puts 'Could not create merge request:'
35
- puts ' A merge request already exists for this branch'
36
- rescue Exception => e
37
- puts 'Could not create merge request:'
38
- puts e.message
20
+ options = {
21
+ source_branch: local_branch,
22
+ target_branch: base_branch,
23
+ squash: squash_merge_request,
24
+ remove_source_branch: remove_source_branch,
25
+ description: new_mr_body
26
+ }
27
+
28
+ puts "Creating merge request: #{new_mr_title}"
29
+ mr = gitlab_client.create_merge_request(local_project, new_mr_title, options)
30
+
31
+ if mr.diff_refs.base_sha == mr.diff_refs.head_sha
32
+ puts "Merge request was created, but no commits have been pushed to GitLab: #{mr.web_url}"
33
+ else
34
+ puts "Merge request successfully created: #{mr.web_url}"
39
35
  end
36
+ rescue Gitlab::Error::Conflict
37
+ puts 'Could not create merge request:'
38
+ puts ' A merge request already exists for this branch'
39
+ rescue StandardError => e
40
+ puts 'Could not create merge request:'
41
+ puts e.message
40
42
  end
43
+ # rubocop:enable Metrics/AbcSize
44
+ # rubocop:enable Metrics/MethodLength
41
45
 
46
+ # rubocop:disable Metrics/MethodLength
47
+ # rubocop:disable Metrics/AbcSize
42
48
  def merge
43
- begin
44
- mr_id
45
- options = {
46
- should_remove_source_branch: existing_mr.should_remove_source_branch || existing_mr.force_remove_source_branch,
47
- squash: existing_mr.squash,
48
- squash_commit_message: existing_mr.title
49
- }
50
-
51
- puts "Merging merge request: #{mr_id}"
49
+ mr_id
50
+ options = {
51
+ should_remove_source_branch: existing_mr.should_remove_source_branch || existing_mr.force_remove_source_branch,
52
+ squash: existing_mr.squash,
53
+ squash_commit_message: existing_mr.title
54
+ }
55
+
56
+ puts "Merging merge request: #{mr_id}"
57
+ merge = gitlab_client.accept_merge_request(local_project, mr_id, options)
58
+
59
+ if merge.merge_commit_sha.nil?
60
+ options[:squash] = true
52
61
  merge = gitlab_client.accept_merge_request(local_project, mr_id, options)
62
+ end
53
63
 
54
- if merge.merge_commit_sha.nil?
55
- options[:squash] = true
56
- merge = gitlab_client.accept_merge_request(local_project, mr_id, options)
57
- end
58
-
59
- if merge.merge_commit_sha.nil?
60
- puts 'Could not merge merge request:'
61
- puts " #{merge.merge_error}"
62
- else
63
- puts "Merge request successfully merged: #{merge.merge_commit_sha}"
64
- end
65
- rescue Gitlab::Error::MethodNotAllowed => e
66
- puts 'Could not merge merge request:'
67
- puts ' The merge request is not mergeable'
68
- rescue Gitlab::Error::NotFound => e
64
+ if merge.merge_commit_sha.nil?
69
65
  puts 'Could not merge merge request:'
70
- puts " Could not a locate a merge request to merge with ID #{mr_id}"
71
- rescue Exception => e
72
- puts 'Could not merge merge request:'
73
- puts e.message
66
+ puts " #{merge.merge_error}"
67
+ else
68
+ puts "Merge request successfully merged: #{merge.merge_commit_sha}"
74
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}"
76
+ rescue StandardError => e
77
+ puts 'Could not merge merge request:'
78
+ puts e.message
75
79
  end
80
+ # rubocop:enable Metrics/AbcSize
81
+ # rubocop:enable Metrics/MethodLength
76
82
 
77
83
  private def new_mr_body
78
84
  @new_mr_body ||= template_name_to_apply ? local_code.read_template(template_name_to_apply) : ''
@@ -80,39 +86,53 @@ module GitHelper
80
86
 
81
87
  private def template_name_to_apply
82
88
  return @template_name_to_apply if @template_name_to_apply
89
+
83
90
  @template_name_to_apply = nil
84
91
 
85
- unless mr_template_options.empty?
86
- if mr_template_options.count == 1
87
- apply_single_template = cli.ask_yes_no("Apply the merge request template from #{mr_template_options.first}? (y/n)")
88
- @template_name_to_apply = mr_template_options.first if apply_single_template
89
- else
90
- response = cli.ask_options("Which merge request template should be applied?", mr_template_options << 'None')
91
- @template_name_to_apply = response unless response == 'None'
92
- end
93
- end
92
+ determine_template unless mr_template_options.empty?
94
93
 
95
94
  @template_name_to_apply
96
95
  end
97
96
 
97
+ # rubocop:disable Metrics/MethodLength
98
+ private def determine_template
99
+ if mr_template_options.count == 1
100
+ apply_single_template = highline.ask_yes_no(
101
+ "Apply the merge request template from #{mr_template_options.first}? (y/n)"
102
+ )
103
+ @template_name_to_apply = mr_template_options.first if apply_single_template
104
+ else
105
+ response = highline.ask_options(
106
+ 'Which merge request template should be applied?', mr_template_options << 'None'
107
+ )
108
+ @template_name_to_apply = response unless response == 'None'
109
+ end
110
+ end
111
+ # rubocop:enable Metrics/MethodLength
112
+
98
113
  private def mr_template_options
99
- @mr_template_options ||= local_code.template_options({
100
- template_directory: '.gitlab',
101
- nested_directory_name: 'merge_request_templates',
102
- non_nested_file_name: 'merge_request_template'
103
- })
114
+ @mr_template_options ||= local_code.template_options(
115
+ {
116
+ template_directory: '.gitlab',
117
+ nested_directory_name: 'merge_request_templates',
118
+ non_nested_file_name: 'merge_request_template'
119
+ }
120
+ )
104
121
  end
105
122
 
106
123
  private def mr_id
107
- @mr_id ||= cli.ask('Merge Request ID?')
124
+ @mr_id ||= highline.ask('Merge Request ID?')
108
125
  end
109
126
 
110
127
  private def squash_merge_request
111
- @squash_merge_request ||= cli.ask_yes_no('Squash merge request? (y/n)')
128
+ @squash_merge_request ||= highline.ask_yes_no('Squash merge request? (y/n)')
112
129
  end
113
130
 
114
131
  private def remove_source_branch
115
- @remove_source_branch ||= existing_project.remove_source_branch_after_merge || cli.ask_yes_no('Remove source branch after merging? (y/n)')
132
+ @remove_source_branch ||=
133
+ existing_project.remove_source_branch_after_merge || highline.ask_yes_no(
134
+ 'Remove source branch after merging? (y/n)'
135
+ )
116
136
  end
117
137
 
118
138
  private def existing_project
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GitHelper
2
4
  class NewBranch
3
5
  def execute(new_branch_name = nil)
4
- branch_name = new_branch_name || GitHelper::HighlineCli.new.ask('New branch name?')
6
+ branch_name = new_branch_name || HighlineWrapper.new.ask('New branch name?', { required: true })
5
7
  puts "Attempting to create a new branch: #{branch_name}"
6
8
  GitHelper::LocalCode.new.new_branch(branch_name)
7
9
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GitHelper
2
4
  class OctokitClient
3
5
  def client
@@ -1,75 +1,89 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module GitHelper
2
4
  class GitHubPullRequest
3
- attr_accessor :local_repo, :local_branch, :local_code, :cli, :base_branch, :new_pr_title
5
+ attr_accessor :local_repo, :local_branch, :local_code, :highline, :base_branch, :new_pr_title
4
6
 
5
7
  def initialize(options)
6
8
  @local_repo = options[:local_project]
7
9
  @local_branch = options[:local_branch]
8
10
  @local_code = options[:local_code]
9
- @cli = options[:cli]
11
+ @highline = options[:highline]
10
12
  end
11
13
 
14
+ # rubocop:disable Metrics/MethodLength
15
+ # rubocop:disable Metrics/AbcSize
12
16
  def create(options)
13
17
  @base_branch = options[:base_branch]
14
18
  @new_pr_title = options[:new_title]
15
19
 
16
- begin
17
- new_pr_body
20
+ new_pr_body
18
21
 
19
- puts "Creating pull request: #{new_pr_title}"
20
- pr = octokit_client.create_pull_request(local_repo, base_branch, local_branch, new_pr_title, new_pr_body)
21
- puts "Pull request successfully created: #{pr.html_url}"
22
- rescue Octokit::UnprocessableEntity => e
23
- puts 'Could not create pull request:'
24
- if e.message.include?('pull request already exists')
25
- puts ' A pull request already exists for this branch'
26
- elsif e.message.include?('No commits between')
27
- puts ' No commits have been pushed to GitHub'
28
- else
29
- puts e.message
30
- end
31
- rescue Exception => e
32
- puts 'Could not create pull request:'
22
+ 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
+ )
30
+ puts "Pull request successfully created: #{pr.html_url}"
31
+ rescue Octokit::UnprocessableEntity => e
32
+ puts 'Could not create pull request:'
33
+ if e.message.include?('pull request already exists')
34
+ puts ' A pull request already exists for this branch'
35
+ elsif e.message.include?('No commits between')
36
+ puts ' No commits have been pushed to GitHub'
37
+ else
33
38
  puts e.message
34
39
  end
40
+ rescue StandardError => e
41
+ puts 'Could not create pull request:'
42
+ puts e.message
35
43
  end
44
+ # rubocop:enable Metrics/AbcSize
45
+ # rubocop:enable Metrics/MethodLength
36
46
 
47
+ # rubocop:disable Metrics/MethodLength
48
+ # rubocop:disable Metrics/AbcSize
37
49
  def merge
38
- begin
39
- pr_id
40
- merge_method
41
-
42
- puts "Merging pull request: #{pr_id}"
43
- merge = octokit_client.merge_pull_request(local_repo, pr_id, existing_pr.title, { merge_method: merge_method })
44
- puts "Pull request successfully merged: #{merge.sha}"
45
- rescue Octokit::UnprocessableEntity => e
46
- puts 'Could not merge pull request:'
47
- puts e.message
48
- rescue Octokit::NotFound => e
49
- puts 'Could not merge pull request:'
50
- puts " Could not a locate a pull request to merge with ID #{pr_id}"
51
- rescue Octokit::MethodNotAllowed => e
52
- puts 'Could not merge pull request:'
53
- if e.message.include?('405 - Required status check')
54
- puts ' A required status check has not passed'
55
- elsif e.message.include?('405 - Base branch was modified')
56
- puts ' The base branch has been modified'
57
- elsif e.message.include?('405 - Pull Request is not mergeable')
58
- puts ' The pull request is not mergeable'
59
- elsif e.message.include?('405 - Rebase merges are not allowed on this repository')
60
- puts ' Rebase merges are not allowed on this repository'
61
- elsif e.message.include?('405 - Merge commits are not allowed on this repository')
62
- puts ' Merge commits are not allowed on this repository'
63
- elsif e.message.include?('405 - Squash commits are not allowed on this repository')
64
- puts ' Squash merges are not allowed on this repository'
65
- else
66
- puts e.message
67
- end
68
- rescue Exception => e
69
- puts 'Could not merge pull request:'
50
+ pr_id
51
+ merge_method
52
+
53
+ 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
+ )
60
+ 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
65
+ 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'
78
+ else
70
79
  puts e.message
71
80
  end
81
+ rescue StandardError => e
82
+ puts 'Could not merge pull request:'
83
+ puts e.message
72
84
  end
85
+ # rubocop:enable Metrics/AbcSize
86
+ # rubocop:enable Metrics/MethodLength
73
87
 
74
88
  private def new_pr_body
75
89
  @new_pr_body ||= template_name_to_apply ? local_code.read_template(template_name_to_apply) : ''
@@ -77,39 +91,56 @@ module GitHelper
77
91
 
78
92
  private def template_name_to_apply
79
93
  return @template_name_to_apply if @template_name_to_apply
94
+
80
95
  @template_name_to_apply = nil
81
96
 
82
- unless pr_template_options.empty?
83
- if pr_template_options.count == 1
84
- apply_single_template = cli.ask_yes_no("Apply the pull request template from #{pr_template_options.first}? (y/n)")
85
- @template_name_to_apply = pr_template_options.first if apply_single_template
86
- else
87
- response = cli.ask_options("Which pull request template should be applied?", pr_template_options << 'None')
88
- @template_name_to_apply = response unless response == 'None'
89
- end
90
- end
97
+ determine_template unless pr_template_options.empty?
91
98
 
92
99
  @template_name_to_apply
93
100
  end
94
101
 
102
+ # rubocop:disable Metrics/MethodLength
103
+ private def determine_template
104
+ if pr_template_options.count == 1
105
+ apply_single_template = highline.ask_yes_no(
106
+ "Apply the pull request template from #{pr_template_options.first}? (y/n)"
107
+ )
108
+ @template_name_to_apply = pr_template_options.first if apply_single_template
109
+ else
110
+ response = highline.ask_options(
111
+ 'Which pull request template should be applied?', pr_template_options << 'None'
112
+ )
113
+ @template_name_to_apply = response unless response == 'None'
114
+ end
115
+ end
116
+ # rubocop:enable Metrics/MethodLength
117
+
95
118
  private def pr_template_options
96
- @pr_template_options ||= local_code.template_options({
97
- template_directory: '.github',
98
- nested_directory_name: 'PULL_REQUEST_TEMPLATE',
99
- non_nested_file_name: 'pull_request_template'
100
- })
119
+ @pr_template_options ||= local_code.template_options(
120
+ {
121
+ template_directory: '.github',
122
+ nested_directory_name: 'PULL_REQUEST_TEMPLATE',
123
+ non_nested_file_name: 'pull_request_template'
124
+ }
125
+ )
101
126
  end
102
127
 
103
128
  private def pr_id
104
- @pr_id ||= cli.ask('Pull Request ID?')
129
+ @pr_id ||= highline.ask('Pull Request ID?')
105
130
  end
106
131
 
107
132
  private def merge_method
108
- @merge_method ||= merge_options.length == 1 ? merge_options.first : cli.ask_options('Merge method?', merge_options)
133
+ @merge_method ||=
134
+ if merge_options.length == 1
135
+ merge_options.first
136
+ else
137
+ highline.ask_options('Merge method?', merge_options)
138
+ end
109
139
  end
110
140
 
111
141
  private def merge_options
112
142
  return @merge_options if @merge_options
143
+
113
144
  merge_options = []
114
145
  merge_options << 'merge' if existing_project.allow_merge_commit
115
146
  merge_options << 'squash' if existing_project.allow_squash_merge