class RightBranch::Updater

Attributes

credentials[R]
repository[R]

Public Class Methods

new(options) click to toggle source
# File lib/right_branch/updater.rb, line 7
def initialize(options)
  @repository = options[:repository]
  @credentials = options[:credentials]
end

Public Instance Methods

run!(old_pr_number, new_branch) click to toggle source
# File lib/right_branch/updater.rb, line 12
def run!(old_pr_number, new_branch)
  new_pr = resubmit_pr(old_pr_number, new_branch)

  update_pr(old_pr_number, state: 'closed')

  comment_on_issue old_pr_number ,
    "Reopened against `#{new_branch}` (##{new_pr.number})"
end

Private Instance Methods

comment_on_issue(number, comment) click to toggle source
# File lib/right_branch/updater.rb, line 31
def comment_on_issue(number, comment)
  github.add_comment(repository, number, comment)
end
get_pr(pr_number) click to toggle source
# File lib/right_branch/updater.rb, line 27
def get_pr(pr_number)
  github.pull_request(repository, pr_number)
end
github() click to toggle source
# File lib/right_branch/updater.rb, line 23
def github
  @github ||= Octokit::Client.new(credentials)
end
resubmit_pr(old_pr_number, new_branch) click to toggle source
# File lib/right_branch/updater.rb, line 39
def resubmit_pr(old_pr_number, new_branch)
  old_pr = get_pr(old_pr_number)

  github.create_pull_request \
    repository,
    new_branch,
    old_pr[:head][:label],
    old_pr[:title],
    old_pr[:body]
end
update_pr(number, args) click to toggle source
# File lib/right_branch/updater.rb, line 35
def update_pr(number, args)
  github.update_pull_request(repository, number, args)
end