Skip to content

Instantly share code, notes, and snippets.

@stufield
Last active July 4, 2020 20:40
Show Gist options
  • Save stufield/5962778d47de752ac3afbf38bca25d41 to your computer and use it in GitHub Desktop.
Save stufield/5962778d47de752ac3afbf38bca25d41 to your computer and use it in GitHub Desktop.
The `somaverse` pre-commit hook
#!/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 <&-
#!/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