Class: Octopolo::GitHub::PullRequestCreator

Inherits:
IssueCreator show all
Defined in:
lib/octopolo/github/pull_request_creator.rb

Constant Summary

Constants inherited from IssueCreator

IssueCreator::CannotCreate, IssueCreator::MissingAttribute, IssueCreator::NotYetCreated

Instance Attribute Summary

Attributes inherited from IssueCreator

#data, #number, #options, #repo_name

Attributes included from ConfigWrapper

#config

Instance Method Summary collapse

Methods inherited from IssueCreator

#body, #body_locals, #edit_body, #jira_ids, #jira_url, perform, #pivotal_ids, #title

Constructor Details

#initialize(repo_name, options) ⇒ PullRequestCreator

Public: Create a pull request for the given repo with the given options

repo_name - Full name (“account/repo”) of the repo in question options - Hash of pull request information

title: Title of the pull request
destination_branch: Which branch to merge into
source_branch: Which branch to be merged


16
17
18
# File 'lib/octopolo/github/pull_request_creator.rb', line 16

def initialize repo_name, options
  super(repo_name, options)
end

Instance Method Details

#body_edit_temp_nameObject

Public: Temporary file for body editing

Returns Name of temporary file



71
72
73
# File 'lib/octopolo/github/pull_request_creator.rb', line 71

def body_edit_temp_name
  'octopolo_pull_request'
end

#destination_branchObject

Public: Branch to merge the pull request into

Returns a String with the branch name



50
51
52
# File 'lib/octopolo/github/pull_request_creator.rb', line 50

def destination_branch
  options[:destination_branch] || raise(MissingAttribute)
end

#draftObject

Public: Draft Pull request

Returns a boolean that marks the PR a draft PR



43
44
45
# File 'lib/octopolo/github/pull_request_creator.rb', line 43

def draft
  !options[:skip_draft]
end

#performObject

Public: Create the pull request

Returns an array with the first element being the pull request’s number, the second being a Mash of the response from GitHub’s API



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/octopolo/github/pull_request_creator.rb', line 24

def perform
  result = GitHub.create_pull_request(
    repo_name,
    destination_branch,
    source_branch,
    title,
    body,
    {draft: draft}
  )
  # capture the information
  self.number = result.number
  self.data = result
rescue => e
  raise CannotCreate, e.message
end

#renderer_templateObject

Public: Rendering template for body property

Returns Name of template file



64
65
66
# File 'lib/octopolo/github/pull_request_creator.rb', line 64

def renderer_template
  Renderer::PULL_REQUEST_BODY
end

#source_branchObject

Public: Branch to merge into the destination branch

Returns a String with the branch name



57
58
59
# File 'lib/octopolo/github/pull_request_creator.rb', line 57

def source_branch
  options[:source_branch] || raise(MissingAttribute)
end