Last active
September 4, 2019 17:56
-
-
Save jeremy8883/9b454d7ba3087ba7937ce62e824c61dd to your computer and use it in GitHub Desktop.
Submit PR
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# This script runs all of the boilerplate commands that I repeatedly need to run | |
# when submitting a pull request for typical javascript projects. | |
# To summarize what this script does: | |
# - Opens github page to submit a PR in the web browser | |
# - Runs linting, tries to fix any errors, then automatically pushes the fixes | |
# up. You may need to make some fixes manually. | |
# - Runs jest tests. Of course, the CI server would also run these, but I prefer | |
# to run them locally as well. That way I can get told my tests are failing | |
# much sooner. | |
# | |
# To get this script working, make sure you update the `githubUrl` and | |
# `sourceDirectory` values below to match your project, and then copy this | |
# script to your project directory. | |
githubUrl="https://github.com/ACCOUNT_NAME/PROJECT_NAME" | |
sourceDirectory="src" | |
# Functions that allow us to show some colour in the console | |
RED='\033[0;31m' | |
BLUE='\033[0;94m' | |
NO_COLOUR='\033[0m' | |
echo_error () { | |
echo -e "${RED}$1${NO_COLOUR}" | |
} | |
echo_info () { | |
echo -e "${BLUE}$1${NO_COLOUR}" | |
} | |
status="$(git status --short)" | |
if [ "${status}" != "" ]; then | |
echo_error "Please commit your changes or stash them before you run this command." | |
exit 1; | |
fi | |
branchName="$(git rev-parse --abbrev-ref HEAD)" | |
if [ "${branchName}" = "master" ]; then | |
echo_error "Current branch is ${branchName}. This script is for creating PRs from feature branches." | |
exit 1; | |
fi | |
git push --set-upstream origin $branchName | |
if [ "$?" != "0" ]; then | |
echo_error "There was a problem pushing up your code." | |
exit 1; | |
fi | |
echo_info "Browser opened so you can submit your PR. While you're filling out the tile/description, we'll fix the lint errors for you." | |
open $githubUrl/compare/$branchName?expand=1 | |
while true; do | |
echo_info "Checking/fixing lint errors..." | |
lintResult="$(node node_modules/eslint/bin/eslint.js -c .eslintrc \— ext .js $sourceDirectory --fix)" | |
if [ "${lintResult}" = "" ]; then | |
break; | |
fi | |
# Running again to show the errors...I don't know bash very well | |
node node_modules/eslint/bin/eslint.js -c .eslintrc \— ext .js $sourceDirectory --fix | |
echo_error "There were lint errors that could not be fixed. Please fix these up manually." | |
read -p "Press 'enter' once you are done" | |
done | |
status="$(git status --short)" | |
if [ "${status}" != "" ]; then | |
echo_info "Committing and pushing up lint fixes" | |
git commit -am "Fix lint issues" | |
git push | |
if [ "$?" != "0" ]; then | |
echo_error "There was a problem pushing up the lint fixes." | |
exit 1; | |
fi | |
fi | |
echo_info "Running tests" | |
yarn run jest |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment