Last active
July 4, 2020 20:40
-
-
Save stufield/5962778d47de752ac3afbf38bca25d41 to your computer and use it in GitHub Desktop.
The `somaverse` pre-commit hook
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
#!/bin/sh | |
echo | |
echo "Thank you for contributing to the ..." | |
echo " ___ ___ _____ __ ___ _____ _______ ___ " | |
echo " (_-</ o \\/ \\ /o \\\\ |/ / -_) __(_-</ -_)" | |
echo "/___/\\___/__Y_Y__\\/_/\\_\\\\__/\\__/_/ /___/\\__/ " | |
# Read user input, assign stdin to keyboard | |
exec < /dev/tty | |
while read -p "* Are ALL of the unit tests passing? (Y/n) " yn; do | |
case $yn in | |
[Yy] ) break;; | |
[Nn] ) echo "* Please fix unit tests and retry."; exit 1;; | |
* ) echo "* Please answer y (yes) or n (no):" && continue; | |
esac | |
done | |
Rscript --vanilla -e "devtools::spell_check()" | |
while read -p "* Are there any spelling mistakes in the documentation? (Y/n) " yn; do | |
case $yn in | |
[Nn] ) break;; | |
[Yy] ) echo "* Please correct them, add them to the WORDLIST file, roxygenize, and retry."; exit 1;; | |
* ) echo "* Please answer y (yes) or n (no):" && continue; | |
esac | |
done | |
while read -p "* Don't forget to add the JIRA issue in the Git commit message ... OK? (Y/n) " yn; do | |
case $yn in | |
[Yy] ) break;; | |
[Nn] ) echo "* Please check JIRA for code, e.g. SOMAR-175, and add to commit message"; exit 1;; | |
* ) echo "* Please answer y (yes) or n (no):" && continue; | |
esac | |
done | |
echo | |
echo "You rock!" | |
echo "Thank you for your contribution to this member of the somaverse!" | |
echo | |
exec <&- |
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 Rscript | |
# ------ | |
# check spelling | |
# ----- | |
words <- devtools::spell_check() | |
if (length(words$word) > 0) { | |
warning( | |
paste0("Spelling errors (", length(words$word), ") detected"), | |
call. = FALSE) | |
} | |
# ------ | |
# check .lintr file | |
# ----- | |
if (git2r::in_repository()) { | |
git_status <- git2r::status(staged = FALSE) | |
if (any(unlist(git_status) == ".lintr")) { | |
stop("Unstaged changes to .lintr file. Stage the .lintr ", | |
"file or discard the changes to it. ", call. = FALSE) | |
} | |
} | |
files <- list.files("R", full.names = TRUE) | |
# ------ | |
# check lints | |
# ----- | |
lints <- lapply(files, function(path) { | |
lints <- somaverse::lintFile(path) | |
if (length(lints) > 0) { | |
stop("File ", basename(path), " is not lint free\n", | |
"Run somaverse::lintFile('", basename(path), | |
"') to check the lintr output.", call. = FALSE) | |
} | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment