class Ninny::Commands::PullRequestMerge

Attributes

branch_type[R]
options[RW]
pull_request[RW]
pull_request_id[RW]
username[R]

Public Class Methods

new(pull_request_id, options) click to toggle source
# File lib/ninny/commands/pull_request_merge.rb, line 11
def initialize(pull_request_id, options)
  @branch_type = options[:branch_type] || Ninny::Git::STAGING_PREFIX
  self.pull_request_id = pull_request_id
  self.options = options
end

Public Instance Methods

branch_to_merge_into() click to toggle source

Public: Find the branch

Returns a String

# File lib/ninny/commands/pull_request_merge.rb, line 86
def branch_to_merge_into
  @branch_to_merge_into ||= Ninny.git.latest_branch_for(branch_type)
end
check_out_branch() click to toggle source

Public: Check out the branch

# File lib/ninny/commands/pull_request_merge.rb, line 44
def check_out_branch
  prompt.say "Checking out #{branch_to_merge_into}."
  Ninny.git.check_out(branch_to_merge_into, false)
  Ninny.git.track_current_branch
rescue Ninny::Git::NoBranchOfType
  prompt.say "No #{branch_type} branch available. Creating one now."
  CreateDatedBranch.new(branch: branch_type).execute
end
comment_about_merge() click to toggle source

Public: Comment that the pull request was merged into the branch

# File lib/ninny/commands/pull_request_merge.rb, line 60
def comment_about_merge
  pull_request.write_comment(comment_body)
end
comment_body() click to toggle source

Public: The content of the comment to post when merged

Returns a String

# File lib/ninny/commands/pull_request_merge.rb, line 67
def comment_body
  user = username || determine_local_user
  body = "Merged into #{branch_to_merge_into}".dup
  body << " by #{user}" if user
  body << '.'
end
determine_local_user() click to toggle source
# File lib/ninny/commands/pull_request_merge.rb, line 90
def determine_local_user
  local_user_name = `git config user.name`.strip
  local_user_name.empty? ? nil : local_user_name
end
execute(*) click to toggle source
# File lib/ninny/commands/pull_request_merge.rb, line 17
def execute(*)
  unless pull_request_id
    current = Ninny.repo.current_pull_request
    self.pull_request_id = current.number if current
  end

  self.pull_request_id ||= select_pull_request

  return nil if pull_request_id.nil?

  check_out_branch
  merge_pull_request
  comment_about_merge
end
merge_pull_request() click to toggle source

Public: Merge the pull request's branch into the checked-out branch

# File lib/ninny/commands/pull_request_merge.rb, line 54
def merge_pull_request
  prompt.say "Merging #{pull_request.branch} to #{branch_to_merge_into}."
  Ninny.git.merge(pull_request.branch)
end

Private Instance Methods

select_pull_request() click to toggle source
# File lib/ninny/commands/pull_request_merge.rb, line 32
def select_pull_request
  choices = Ninny.repo.open_pull_requests.map { |pr| { name: pr.title, value: pr.number } }

  if choices.empty?
    prompt.say "There don't seem to be any open merge requests."
  else
    prompt.select("Which #{Ninny.repo.pull_request_label}?", choices)
  end
end