rename pre-commit hook to pre-commit checks (no-check)

This commit is contained in:
dr. M.S. (Matthijs) Berends 2024-04-23 10:55:48 +02:00
parent 04df6dfcf5
commit 0d8a91db49
10 changed files with 21 additions and 19 deletions

View File

@ -29,22 +29,24 @@
# how to conduct AMR data analysis: https://msberends.github.io/AMR/ #
# ==================================================================== #
#!/bin/bash
########################################
# This script runs before every commit #
########################################
echo "Running commit-msg hook..."
# check if the commit message contains '(no-check)' or '(no-verify)'
# check the commit message
COMMIT_MSG=$(cat "$1")
if [[ "$COMMIT_MSG" =~ \(no-check\)|\(no-verify\) ]]; then
echo "Commit check bypassed by commit message."
if [[ "$COMMIT_MSG" =~ \(no-check\)|\(no-checks\)|\(no-verify\) ]]; then
echo "Not running pre-commit checks; commit message contains '(no-check)', '(no-checks)', or '(no-verify)."
exit 0
fi
echo "Running pre-commit checks..."
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
if command -v Rscript > /dev/null; then
if [ "$(Rscript -e 'cat(all(c('"'pkgload'"', '"'devtools'"', '"'dplyr'"') %in% rownames(installed.packages())))')" = "TRUE" ]; then
Rscript -e "source('data-raw/_pre_commit_hook.R')"
Rscript -e "source('data-raw/_pre_commit_checks.R')"
currentpkg=$(Rscript -e "cat(pkgload::pkg_name())")
echo "- Adding changed files in ./data-raw and ./man to this commit"
git add data-raw/*

View File

@ -58,9 +58,9 @@ jobs:
- {os: ubuntu-latest, r: 'devel', allowfail: false}
# current 'release' version, check all major OSes:
- {os: macOS-latest, r: '4.3', allowfail: false}
- {os: windows-latest, r: '4.3', allowfail: false}
- {os: ubuntu-latest, r: '4.3', allowfail: false}
- {os: macOS-latest, r: 'release', allowfail: false}
- {os: windows-latest, r: 'release', allowfail: false}
- {os: ubuntu-latest, r: 'release', allowfail: false}
# older versions (see also check-old.yaml for even older versions):
- {os: ubuntu-latest, r: '4.2', allowfail: false}

View File

@ -28,7 +28,7 @@
# ==================================================================== #
# add new version numbers here, and add the rules themselves to "data-raw/eucast_rules.tsv" and clinical_breakpoints
# (sourcing "data-raw/_pre_commit_hook.R" will process the TSV file)
# (sourcing "data-raw/_pre_commit_checks.R" will process the TSV file)
EUCAST_VERSION_BREAKPOINTS <- list(
# "13.0" = list(
# version_txt = "v13.0",

View File

@ -689,7 +689,7 @@ create_eucast_ab_documentation <- function() {
ab <- character()
for (val in x) {
if (paste0("AB_", val) %in% ls(envir = asNamespace("AMR"))) {
# antibiotic group names, as defined in data-raw/_pre_commit_hook.R, such as `CARBAPENEMS`
# antibiotic group names, as defined in data-raw/_pre_commit_checks.R, such as `CARBAPENEMS`
val <- eval(parse(text = paste0("AB_", val)), envir = asNamespace("AMR"))
} else if (val %in% AMR_env$AB_lookup$ab) {
# separate drugs, such as `AMX`

View File

@ -611,7 +611,7 @@ ab_select_exec <- function(function_name,
} else if (isTRUE(function_name == "antimycobacterials")) {
abx <- AMR_env$AB_lookup$ab[which(AMR_env$AB_lookup$group == "Antimycobacterials")]
} else {
# their upper case equivalent are vectors with class 'ab', created in data-raw/_pre_commit_hook.R
# their upper case equivalent are vectors with class 'ab', created in data-raw/_pre_commit_checks.R
# carbapenems() gets its codes from AMR:::AB_CARBAPENEMS
abx <- get(paste0("AB_", toupper(function_name)), envir = asNamespace("AMR"))
# manually added codes from add_custom_antimicrobials() must also be supported

View File

@ -590,7 +590,7 @@ eucast_rules <- function(x,
# this allows: eucast_rules(x, eucast_rules_df = AMR:::EUCAST_RULES_DF %>% filter(is.na(have_these_values)))
eucast_rules_df <- list(...)$eucast_rules_df
} else {
# otherwise internal data file, created in data-raw/_pre_commit_hook.R
# otherwise internal data file, created in data-raw/_pre_commit_checks.R
eucast_rules_df <- EUCAST_RULES_DF
}

View File

@ -335,7 +335,7 @@ get_ab_from_namespace <- function(x, cols_ab) {
x_new <- character()
for (val in x) {
if (paste0("AB_", val) %in% ls(envir = asNamespace("AMR"))) {
# antibiotic group names, as defined in data-raw/_pre_commit_hook.R, such as `AB_CARBAPENEMS`
# antibiotic group names, as defined in data-raw/_pre_commit_checks.R, such as `AB_CARBAPENEMS`
val <- eval(parse(text = paste0("AB_", val)), envir = asNamespace("AMR"))
} else if (val %in% AMR_env$AB_lookup$ab) {
# separate drugs, such as `AMX`

2
R/mo.R
View File

@ -460,7 +460,7 @@ as.mo <- function(x,
}
}
# 'MO_CONS' and 'MO_COPS' are 'mo' vectors created in R/_pre_commit_hook.R
# 'MO_CONS' and 'MO_COPS' are 'mo' vectors created in R/_pre_commit_checks.R
out[out %in% MO_CONS] <- "B_STPHY_CONS"
out[out %in% MO_COPS] <- "B_STPHY_COPS"
if (Becker == "all") {

View File

@ -28,7 +28,7 @@
# ==================================================================== #
# Run this file to update the package using:
# source("data-raw/_pre_commit_hook.R")
# source("data-raw/_pre_commit_checks.R")
library(dplyr, warn.conflicts = FALSE)
try(detach("package:data.table", unload = TRUE), silent = TRUE) # to prevent like() to precede over AMR::like

View File

@ -251,7 +251,7 @@ taxonomy_gbif <- taxonomy_gbif.bak %>%
kingdom %in% c("Archaea", "Bacteria", "Protozoa") |
# include all of these fungal orders
order %in% include_fungal_orders |
# and all of these important genera (see "data-raw/_pre_commit_hook.R")
# and all of these important genera (see "data-raw/_pre_commit_checks.R")
# (they also contain bacteria and protozoa, but these will get prevalence = 2 later on)
genus %in% AMR:::MO_PREVALENT_GENERA
) %>%
@ -1671,7 +1671,7 @@ if (!identical(example_isolates$mo, as.mo(example_isolates$mo, language = NULL))
# load new data sets again
devtools::load_all(".")
source("data-raw/_pre_commit_hook.R")
source("data-raw/_pre_commit_checks.R")
devtools::load_all(".")
if (!identical(intrinsic_resistant$mo, as.mo(intrinsic_resistant$mo, language = NULL))) {