class Thegarage::Gitx::Cli::ReviewCommand

Constants

APPROVAL_COMMENT_PREFIX
BUMP_COMMENT_PREFIX
REJECTION_COMMENT_PREFIX

Public Instance Methods

review(branch = nil) click to toggle source

@see developer.github.com/v3/pulls/

# File lib/thegarage/gitx/cli/review_command.rb, line 43
def review(branch = nil)
  fail 'Github authorization token not found' unless authorization_token

  branch ||= current_branch.name
  pull_request = find_or_create_pull_request(branch)
  bump_pull_request(pull_request) if options[:bump]
  approve_pull_request(pull_request) if options[:approve]
  reject_pull_request(pull_request) if options[:reject]
  assign_pull_request(pull_request) if options[:assignee]

  run_cmd "open #{pull_request.html_url}" if options[:open]
end

Private Instance Methods

approve_pull_request(pull_request) click to toggle source
# File lib/thegarage/gitx/cli/review_command.rb, line 81
def approve_pull_request(pull_request)
  comment = comment_from_template(pull_request, APPROVAL_COMMENT_PREFIX, APPROVAL_COMMENT_FOOTER)
  update_review_status(pull_request, 'success', 'Peer review approved')
end
assign_pull_request(pull_request) click to toggle source
# File lib/thegarage/gitx/cli/review_command.rb, line 58
def assign_pull_request(pull_request)
  assignee = options[:assignee]
  say "Assigning pull request to "
  say assignee, :green

  title = pull_request.title
  body = pull_request.body
  options = {
    assignee: assignee
  }
  github_client.update_issue(github_slug, pull_request.number, title, body, options)
end
bump_pull_request(pull_request) click to toggle source
# File lib/thegarage/gitx/cli/review_command.rb, line 71
def bump_pull_request(pull_request)
  comment = comment_from_template(pull_request, BUMP_COMMENT_PREFIX, BUMP_COMMENT_FOOTER)
  update_review_status(pull_request, 'pending', 'Peer review in progress')
end
comment_from_template(pull_request, prefix, footer) click to toggle source
# File lib/thegarage/gitx/cli/review_command.rb, line 86
def comment_from_template(pull_request, prefix, footer)
  text = ask_editor("\n\n#{footer}", repo.config['core.editor'])
  comment = [prefix, text].join("\n\n")
  comment = comment.gsub(footer, '').chomp.strip
  github_client.add_comment(github_slug, pull_request.number, comment)
end
reject_pull_request(pull_request) click to toggle source
# File lib/thegarage/gitx/cli/review_command.rb, line 76
def reject_pull_request(pull_request)
  comment = comment_from_template(pull_request, REJECTION_COMMENT_PREFIX, REJECTION_COMMENT_FOOTER)
  update_review_status(pull_request, 'failure', 'Peer review rejected')
end