class PurrPr

Constants

DEFAULT_CONFIG_FILE_PATH
VERSION

Attributes

config[R]
config_file_path[R]

Public Class Methods

new(config_file_path = DEFAULT_CONFIG_FILE_PATH) click to toggle source
# File lib/purr_pr.rb, line 14
def initialize(config_file_path = DEFAULT_CONFIG_FILE_PATH)
  @config_file_path = config_file_path
  @config = Config.new
end

Public Instance Methods

create() click to toggle source
# File lib/purr_pr.rb, line 19
def create
  config.instance_eval(config_code)

  # use file for body to avoid quotes issues
  body_file = Tempfile.new
  body_file.write(config.values.body)
  body_file.rewind

  command = 'gh pr create'
  command += " --title '#{config.values.title}'" if config.values.title
  command += " --body-file '#{body_file.path}'"
  command += " --assignee #{config.values.assignee}" if config.values.assignee
  command += " --base #{config.values.base}" if config.values.base
  command += ' --draft' if config.values.draft
  command += ' --no-maintainer-edit' unless config.values.maintainer_edit

  config.values.labels.each do |label|
    command += " --label #{label}"
  end

  config.values.reviewers.each do |reviewer|
    command += " --reviewer #{reviewer}"
  end

  # The later arguments will override the earlier ones,
  # e.g. after `gh pr create --title a --title b` the title will equal 'b',
  # so explicit options will override the config
  command += ARGV.join(' ').prepend(' ')

  system(command)
ensure
  body_file.close
end

Private Instance Methods

config_code() click to toggle source
# File lib/purr_pr.rb, line 55
def config_code
  File.read(config_file_path)
end