class GitHelper::CodeRequest

Public Instance Methods

create() click to toggle source
# File lib/git_helper/code_request.rb, line 5
def create
  process_project.create(
    {
      base_branch: base_branch,
      new_title: new_code_request_title
    }
  )
end
merge() click to toggle source
# File lib/git_helper/code_request.rb, line 14
def merge
  process_project.merge
end

Private Instance Methods

ask_for_clarification() click to toggle source

rubocop:disable Metrics/MethodLength

# File lib/git_helper/code_request.rb, line 31
        def ask_for_clarification
  resp = highline.ask(
    'Found git remotes for both GitHub and GitLab. Would you like to proceed ' \
    'with GitLab or GitHub? (github/gitlab)',
    { required: true }
  ).downcase

  if resp.include?('hub')
    github_pull_request
  elsif resp.include?('lab')
    gitlab_merge_request
  else
    puts 'The answer we received was not parseable.'
    exit
  end
end
autogenerated_title() click to toggle source
# File lib/git_helper/code_request.rb, line 87
        def autogenerated_title
  @autogenerated_title ||= local_code.generate_title(local_branch)
end
base_branch() click to toggle source
# File lib/git_helper/code_request.rb, line 74
        def base_branch
  @base_branch ||=
    if highline.ask_yes_no("Is '#{default_branch}' the correct base branch for your new code request? (y/n)")
      default_branch
    else
      highline.ask('Base branch?', { required: true })
    end
end
default_branch() click to toggle source
# File lib/git_helper/code_request.rb, line 70
        def default_branch
  @default_branch ||= local_code.default_branch
end
github_pull_request() click to toggle source

rubocop:enable Metrics/MethodLength

# File lib/git_helper/code_request.rb, line 49
        def github_pull_request
  @github_pull_request ||= GitHelper::GitHubPullRequest.new(options)
end
gitlab_merge_request() click to toggle source
# File lib/git_helper/code_request.rb, line 53
        def gitlab_merge_request
  @gitlab_merge_request ||= GitHelper::GitLabMergeRequest.new(options)
end
highline() click to toggle source
# File lib/git_helper/code_request.rb, line 102
        def highline
  @highline ||= HighlineWrapper.new
end
local_branch() click to toggle source
# File lib/git_helper/code_request.rb, line 83
        def local_branch
  @local_branch ||= local_code.branch
end
local_code() click to toggle source
# File lib/git_helper/code_request.rb, line 106
        def local_code
  @local_code ||= GitHelper::LocalCode.new
end
local_project() click to toggle source
# File lib/git_helper/code_request.rb, line 66
        def local_project
  @local_project ||= local_code.project_name
end
new_code_request_title() click to toggle source
# File lib/git_helper/code_request.rb, line 91
        def new_code_request_title
  @new_code_request_title ||=
    if autogenerated_title && highline.ask_yes_no(
      "Accept the autogenerated code request title '#{autogenerated_title}'? (y/n)"
    )
      autogenerated_title
    else
      highline.ask('Title?', { required: true })
    end
end
options() click to toggle source
# File lib/git_helper/code_request.rb, line 57
        def options
  {
    local_project: local_project,
    local_branch: local_branch,
    local_code: local_code,
    highline: highline
  }
end
process_project() click to toggle source
# File lib/git_helper/code_request.rb, line 18
        def process_project
  if local_code.github_repo? # GitHub remotes are found
    # If GitLab remotes are also found, ask for clarification, else proceed with GitHub
    local_code.gitlab_project? ? ask_for_clarification : github_pull_request
  elsif local_code.gitlab_project? # Only GitLab remotes are found
    gitlab_merge_request
  else # Neither GitHub nor GitLab remotes are found
    puts 'Could not locate GitHub or GitLab remote URLs.'
    exit
  end
end