diff --git a/DESCRIPTION b/DESCRIPTION index a858551..997ef3f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -37,7 +37,9 @@ Imports: fs, usethis Config/roxygen2/version: 8.0.0 -Suggests: +Suggests: + gert, + gh, testthat (>= 3.0.0) Config/testthat/edition: 3 URL: https://mi-erasmusmc.github.io/studyGenerics/ diff --git a/NAMESPACE b/NAMESPACE index 2c2ce2f..a381a5e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -27,14 +27,6 @@ importFrom(cli,cli_alert_info) importFrom(cli,cli_alert_success) importFrom(cli,cli_alert_warning) importFrom(fs,path_ext_set) -importFrom(gert,git_branch) -importFrom(gert,git_branch_checkout) -importFrom(gert,git_branch_create) -importFrom(gert,git_branch_exists) -importFrom(gert,git_pull) -importFrom(gh,gh) -importFrom(gh,gh_token_exists) -importFrom(gh,gh_tree_remote) importFrom(glue,glue) importFrom(glue,glue_collapse) importFrom(here,here) diff --git a/R/getPkgZips.R b/R/getPkgZips.R index 6903e94..a72d57f 100644 --- a/R/getPkgZips.R +++ b/R/getPkgZips.R @@ -411,3 +411,33 @@ mockLock <- function() { return(lockfile) } +suppPackages <- function() { + list( + Packages = list( + devtools = list( + Package = "devtools", + Version = "2.5.2" + ), # 2.5.2 exists in multiple releases, should pick from the newest (R v4.6) + dplyr = list( + Package = "dplyr", + Version = "0.6" + ), # there is no 0.6 in any of the releases, should get v1.2.1 as alternate from R v4.4 + tidyrr = list( + Package = "tidyr", + Version = "1.3.2" + ), # tidyrr does not exist + RPostgres = list( + Package = "RPostgres", + Version = NULL + ), # no version provided, should get v1.4.10 as alternate from R v4.4 + renv = list( + Package = "renv", + Version = "1.0.7" + ), # renv already exists in lockfile, if override_lock = TRUE, should get v1.0.7 from R v4.2 + xfun = list( + Package = "xfun", + Version = NULL + ) + ) + ) # xfun already exists in lockfile, if override_lock = TRUE, should get v0.57 from R v4.4 +} diff --git a/R/versionControl.R b/R/versionControl.R index 73ea70c..ac11872 100644 --- a/R/versionControl.R +++ b/R/versionControl.R @@ -8,14 +8,24 @@ #' #' @returns A message with the link of the PR #' @importFrom checkmate assertCharacter assertLogical assertTRUE checkClass -#' @importFrom gh gh gh_tree_remote gh_token_exists -#' @importFrom gert git_branch_create git_branch #' @export issueOpen <- function( title, body, newBranch = FALSE ) { + if (!requireNamespace("gh", quietly = TRUE)) { + stop( + "Package \"gh\" must be installed to use this function.", + call. = FALSE + ) + } + if (!requireNamespace("gert", quietly = TRUE)) { + stop( + "Package \"gert\" must be installed to use this function.", + call. = FALSE + ) + } checkmate::assertCharacter( title, len = 1, @@ -84,14 +94,24 @@ issueOpen <- function( #' #' @returns A message with the link of the issue #' @importFrom checkmate assertCharacter assertLogical assertTRUE checkClass -#' @importFrom gh gh gh_tree_remote gh_token_exists -#' @importFrom gert git_branch_create git_branch #' @export pullRequest <- function( title, body, base = "develop" ) { + if (!requireNamespace("gh", quietly = TRUE)) { + stop( + "Package \"gh\" must be installed to use this function.", + call. = FALSE + ) + } + if (!requireNamespace("gert", quietly = TRUE)) { + stop( + "Package \"gert\" must be installed to use this function.", + call. = FALSE + ) + } checkmate::assertCharacter( title, len = 1, @@ -134,9 +154,14 @@ pullRequest <- function( #' and pull latest changes #' #' @returns Git log messages after checking out and pulling 'develop' -#' @importFrom gert git_branch_exists git_branch_checkout git_pull #' @export developCheckout <- function() { + if (!requireNamespace("gert", quietly = TRUE)) { + stop( + "Package \"gert\" must be installed to use this function.", + call. = FALSE + ) + } branch <- "develop" if (gert::git_branch_exists(branch)) { gert::git_branch_checkout( diff --git a/studyGenerics.Rproj b/studyGenerics.Rproj index 270314b..f18f51a 100644 --- a/studyGenerics.Rproj +++ b/studyGenerics.Rproj @@ -1,4 +1,4 @@ -Version: 1.0 +sVersion: 1.0 RestoreWorkspace: Default SaveWorkspace: Default diff --git a/tests/testthat/test-getPkgZips.R b/tests/testthat/test-getPkgZips.R index 0daaf50..22257e8 100644 --- a/tests/testthat/test-getPkgZips.R +++ b/tests/testthat/test-getPkgZips.R @@ -44,7 +44,8 @@ test_that("Message checks - lockfile only", { # Test on lockfile + supp, override_lock = FALSE ---- test_that("Message checks - lockfile + supp, override_lock = FALSE", { - msgs <- capture_messages(pkg_summary <- getPkgZips(lockfile_path = lockfile, supplement = supp)) + lockfile <- mockLock() + msgs <- capture_messages(pkg_summary <- getPkgZips(lockfile_path = lockfile, supplement = suppPackages())) expect_true(any(grepl("PACKAGE NOT FOUND: Unable to find DarwinShinyModules v0.4.0 or a suitable alternate version under R v4.4", msgs))) expect_true(any(grepl("PACKAGE NOT FOUND: Unable to find utils vUNSPECIFIED or a suitable alternate version under R v4.4", msgs))) @@ -71,7 +72,7 @@ test_that("Message checks - lockfile + supp, override_lock = FALSE", { test_that("Message checks - lockfile + supp, override_lock = TRUE", { lockfile <- mockLock() - msgs <- capture_messages(pkg_summary <- getPkgZips(lockfile_path = lockfile, supplement = supp, override_lock = TRUE)) + msgs <- capture_messages(pkg_summary <- getPkgZips(lockfile_path = lockfile, supplement = suppPackages(), override_lock = TRUE)) expect_true(any(grepl("PACKAGE NOT FOUND: Unable to find DarwinShinyModules v0.4.0 or a suitable alternate version under R v4.4", msgs))) expect_true(any(grepl("PACKAGE NOT FOUND: Unable to find utils vUNSPECIFIED or a suitable alternate version under R v4.4", msgs))) @@ -103,34 +104,8 @@ test_that("mockLock()", { lockfile <- mockLock() # Create a supplementary file ---- - supp <- list( - Packages = list( - devtools = list( - Package = "devtools", - Version = "2.5.2" - ), # 2.5.2 exists in multiple releases, should pick from the newest (R v4.6) - dplyr = list( - Package = "dplyr", - Version = "0.6" - ), # there is no 0.6 in any of the releases, should get v1.2.1 as alternate from R v4.4 - tidyrr = list( - Package = "tidyr", - Version = "1.3.2" - ), # tidyrr does not exist - RPostgres = list( - Package = "RPostgres", - Version = NULL - ), # no version provided, should get v1.4.10 as alternate from R v4.4 - renv = list( - Package = "renv", - Version = "1.0.7" - ), # renv already exists in lockfile, if override_lock = TRUE, should get v1.0.7 from R v4.2 - xfun = list( - Package = "xfun", - Version = NULL - ) - ) - ) # xfun already exists in lockfile, if override_lock = TRUE, should get v0.57 from R v4.4 + supp <- suppPackages() + # Sanity check of counts ---- lock <- renv::lockfile_read(lockfile) pkgs <- names(lock[["Packages"]]) @@ -151,7 +126,6 @@ test_that("mockLock()", { expect_equal(n_reqs, 46) # expect_equal(n_reqs_wo_overlap, 41) expect_equal(n_all, 56) # not 58 bc of the supps overlap - }) diff --git a/tests/testthat/test-versionControl.R b/tests/testthat/test-versionControl.R deleted file mode 100644 index d259011..0000000 --- a/tests/testthat/test-versionControl.R +++ /dev/null @@ -1,6 +0,0 @@ -test_that("Opening issue and creating branch", { - issueOpen( - title = "Title Test Issue studyGenerics", - body = "Body Test Issue studyGenerics" - ) -})