Skip to content

Instantly share code, notes, and snippets.

@ruralocity
Last active November 13, 2017 18:23
Show Gist options
  • Save ruralocity/a01fe5daa345e250a7e5e06a8dfe9e2c to your computer and use it in GitHub Desktop.
Save ruralocity/a01fe5daa345e250a7e5e06a8dfe9e2c to your computer and use it in GitHub Desktop.
Hack to automate style guide reviews during pull requests
# Prerequisites:
#
# * Add pronto, pronto-rubocop, and any other pronto runners to Gemfile's
# development group (TODO: how to run using standalone gems?)
# Add dotenv to project's Gemfile, if necessary (dotenv-rails includes
# it by default)
# * Create a GitHub API token: https://github.com/settings/tokens.
# Give it the following scopes: repo, repo:status
# See this tutorial for more info:
# https://christoph.luppri.ch/articles/2017/03/05/how-to-automatically-review-your-prs-for-style-violations-with-pronto-and-rubocop/
class PR < Thor
include Thor::Actions
# Usage:
# Note pull request ID in the GitHub UI or URL
# cd path/to/app
# git checkout <branch-to-review>
# thor pr:review
desc "review", "automated code review for style guide issues"
def review
if (token = ENV["PRONTO_GITHUB_ACCESS_TOKEN"])
puts "PRONTO_GITHUB_ACCESS_TOKEN found in ENV"
else
token = ask "GitHub access token:"
end
id = ask "Pull request ID:"
base = ask "Base for comparison:", default: "origin/master"
run "PRONTO_GITHUB_ACCESS_TOKEN=#{token} PULL_REQUEST_ID=#{id} pronto run -f github_status github_pr -c #{base}"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment