Skip to content

Commit

Permalink
Use pulled files if check_R_package_usage is run for second and nex…
Browse files Browse the repository at this point in the history
…t time.
  • Loading branch information
maciekbanas committed Dec 19, 2023
1 parent b3d2556 commit 86c2d3f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
12 changes: 8 additions & 4 deletions R/GitStats.R
Original file line number Diff line number Diff line change
Expand Up @@ -410,10 +410,14 @@ GitStats <- R6::R6Class("GitStats",
# @param package_name Name of a package.
check_R_package_as_dependency = function(package_name) {
cli::cli_alert_info("Checking where [{package_name}] is used as a dependency...")
self$pull_files(
file_path = c("DESCRIPTION", "NAMESPACE")
)
desc_table <- self$get_files()
if (all(c("DESCRIPTION", "NAMESPACE") %in% private$files$file_path)){
desc_table <- self$get_files()
} else {
self$pull_files(
file_path = c("DESCRIPTION", "NAMESPACE")
)
desc_table <- self$get_files()
}
repos_with_package <- desc_table[grepl(package_name, desc_table$file_content), ]
if (nrow(repos_with_package) > 0) {
repos_with_package <- repos_with_package[!duplicated(repos_with_package$api_url),]
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test-06-GitStats.R
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ test_that("check_R_package_as_dependency", {
test_mocker$cache(R_package_as_dependency)
})

test_that("check_R_package does not pull files if NAMESPACE and DESCRIPTION are already loaded", {
suppressMessages(
R_package_as_dependency <- test_gitstats_priv$check_R_package_as_dependency("dplyr")
)
expect_package_usage_table(R_package_as_dependency)
})

# public methods

test_that("GitStats get users info", {
Expand Down

0 comments on commit 86c2d3f

Please sign in to comment.