diff --git a/R/GitHost.R b/R/GitHost.R index c7aa46b2..d373f1c4 100644 --- a/R/GitHost.R +++ b/R/GitHost.R @@ -721,7 +721,8 @@ GitHost <- R6::R6Class( information = "Pulling all organizations" ) } - private$orgs <- private$engines$graphql$get_orgs() + graphql_engine <- private$engines$graphql + private$orgs <- graphql_engine$get_orgs() } repos_urls_from_orgs <- private$get_repos_urls_from_orgs( type = type, @@ -823,14 +824,14 @@ GitHost <- R6::R6Class( verbose = verbose, progress = progress ) - }) %>% + }) |> purrr::list_flatten() } if (output != "raw") { repos_table <- repos_response %>% rest_engine$tailor_repos_response( output = output - ) %>% + ) |> rest_engine$prepare_repos_table( output = output, verbose = verbose diff --git a/tests/testthat/_snaps/01-get_repos-GitHub.md b/tests/testthat/_snaps/01-get_repos-GitHub.md index bafe0009..42efdf6e 100644 --- a/tests/testthat/_snaps/01-get_repos-GitHub.md +++ b/tests/testthat/_snaps/01-get_repos-GitHub.md @@ -5,6 +5,53 @@ Output [1] "\n query GetReposByOrg($login: String!) {\n repositoryOwner(login: $login) {\n ... on Organization {\n \n repositories(first: 100) {\n totalCount\n pageInfo {\n endCursor\n hasNextPage\n }\n nodes {\n repo_id: id\n repo_name: name\n default_branch: defaultBranchRef {\n name\n }\n stars: stargazerCount\n forks: forkCount\n created_at: createdAt\n last_activity_at: pushedAt\n languages (first: 5) { nodes {name} }\n issues_open: issues (first: 100 states: [OPEN]) {\n totalCount\n }\n issues_closed: issues (first: 100 states: [CLOSED]) {\n totalCount\n }\n organization: owner {\n login\n }\n repo_url: url\n }\n }\n \n }\n }\n }" +# `get_repos_with_code_from_orgs()` pulls raw response + + Code + repos_with_code_from_orgs_raw <- github_testhost_priv$ + get_repos_with_code_from_orgs(code = "shiny", in_files = c("DESCRIPTION", + "NAMESPACE"), output = "raw", verbose = TRUE) + Message + i [Host:GitHub][Engine:REST][Scope:test_org] Pulling repositories... + +# `get_repos_with_code_from_host()` pulls and parses output into table + + Code + repos_with_code_from_host_table <- github_testhost_priv$ + get_repos_with_code_from_host(code = "DESCRIPTION", in_path = TRUE, output = "table_full", + verbose = TRUE) + Message + i [Host:GitHub][Engine:REST] Pulling repositories... + +# `get_repos_with_code_from_repos()` works + + Code + repos_with_code_from_repos_full <- github_testhost_priv$ + get_repos_with_code_from_repos(code = "tests", output = "table_full", + verbose = TRUE) + Message + i [Host:GitHub][Engine:REST][Scope:] Pulling repositories... + i Preparing repositories table... + +# `get_repos_with_code_from_orgs()` pulls minimum version of table + + Code + repos_with_code_from_repos_min <- github_testhost_priv$ + get_repos_with_code_from_repos(code = "tests", in_files = "DESCRIPTION", + output = "table_min", verbose = TRUE) + Message + i [Host:GitHub][Engine:REST][Scope:] Pulling repositories... + i Preparing repositories table... + +# `get_repos_with_code_from_host()` pulls raw response + + Code + repos_with_code_from_host_raw <- github_testhost_priv$ + get_repos_with_code_from_host(code = "shiny", in_files = c("DESCRIPTION", + "NAMESPACE"), output = "raw", verbose = TRUE) + Message + i [Host:GitHub][Engine:REST] Pulling repositories... + # `get_all_repos()` is set to scan whole git host Code diff --git a/tests/testthat/_snaps/get_urls_repos-GitHub.md b/tests/testthat/_snaps/get_urls_repos-GitHub.md new file mode 100644 index 00000000..aeb16a31 --- /dev/null +++ b/tests/testthat/_snaps/get_urls_repos-GitHub.md @@ -0,0 +1,8 @@ +# get_repos_urls_from_orgs prepares web repo_urls vector + + Code + gh_repos_urls_from_orgs <- github_testhost_priv$get_repos_urls_from_orgs(type = "web", + verbose = TRUE, progress = FALSE) + Message + i [Host:GitHub][Engine:REST][Scope:test_org] Pulling repositories (URLs)... + diff --git a/tests/testthat/test-01-get_repos-GitHub.R b/tests/testthat/test-01-get_repos-GitHub.R index e86c31bf..3036fb20 100644 --- a/tests/testthat/test-01-get_repos-GitHub.R +++ b/tests/testthat/test-01-get_repos-GitHub.R @@ -371,27 +371,112 @@ test_that("`get_repos_with_code_from_orgs()` pulls raw response", { "rest_engine$get_repos_by_code", test_mocker$use("gh_repos_by_code_raw") ) - repos_with_code_from_orgs_raw <- github_testhost_priv$get_repos_with_code_from_orgs( - code = "shiny", - in_files = c("DESCRIPTION", "NAMESPACE"), - output = "raw", - verbose = FALSE + expect_snapshot( + repos_with_code_from_orgs_raw <- github_testhost_priv$get_repos_with_code_from_orgs( + code = "shiny", + in_files = c("DESCRIPTION", "NAMESPACE"), + output = "raw", + verbose = TRUE + ) ) expect_type(repos_with_code_from_orgs_raw, "list") expect_gt(length(repos_with_code_from_orgs_raw), 0) }) +test_that("`get_repos_with_code_from_host()` pulls and parses output into table", { + mockery::stub( + github_testhost_priv$get_repos_with_code_from_host, + "rest_engine$get_repos_by_code", + test_mocker$use("gh_repos_by_code_raw") + ) + mockery::stub( + github_testhost_priv$get_repos_with_code_from_host, + "rest_engine$prepare_repos_table", + test_mocker$use("gh_repos_by_code_table") + ) + mockery::stub( + github_testhost_priv$get_repos_with_code_from_host, + "rest_engine$get_repos_issues", + test_mocker$use("gh_repos_by_code_table") + ) + expect_snapshot( + repos_with_code_from_host_table <- github_testhost_priv$get_repos_with_code_from_host( + code = "DESCRIPTION", + in_path = TRUE, + output = "table_full", + verbose = TRUE + ) + ) + expect_repos_table(repos_with_code_from_host_table) +}) + +test_that("`get_repos_with_code_from_repos()` works", { + github_testhost_priv <- create_github_testhost( + repos = c("TestRepo1", "TestRepo2"), + mode = "private" + ) + mockery::stub( + github_testhost_priv$get_repos_with_code_from_repos, + "rest_engine$get_repos_by_code", + test_mocker$use("gh_repos_by_code") + ) + mockery::stub( + github_testhost_priv$get_repos_with_code_from_repos, + "rest_engine$get_repos_issues", + test_mocker$use("gh_repos_by_code_table") + ) + github_testhost_priv$searching_scope <- c("repo") + expect_snapshot( + repos_with_code_from_repos_full <- github_testhost_priv$get_repos_with_code_from_repos( + code = "tests", + output = "table_full", + verbose = TRUE + ) + ) + expect_repos_table(repos_with_code_from_repos_full) +}) + +test_that("`get_repos_with_code_from_repos()` pulls minimum version of table", { + github_testhost_priv <- create_github_testhost( + repos = c("TestRepo1", "TestRepo2"), + mode = "private" + ) + mockery::stub( + github_testhost_priv$get_repos_with_code_from_repos, + "rest_engine$get_repos_by_code", + test_mocker$use("gh_repos_by_code") + ) + mockery::stub( + github_testhost_priv$get_repos_with_code_from_repos, + "rest_engine$get_repos_issues", + test_mocker$use("gh_repos_by_code_table") + ) + github_testhost_priv$searching_scope <- c("org", "repo") + expect_snapshot( + repos_with_code_from_repos_min <- github_testhost_priv$get_repos_with_code_from_repos( + code = "tests", + in_files = "DESCRIPTION", + output = "table_min", + verbose = TRUE + ) + ) + expect_repos_table(repos_with_code_from_repos_min, + repo_cols = repo_min_colnames) +}) + test_that("`get_repos_with_code_from_host()` pulls raw response", { mockery::stub( github_testhost_priv$get_repos_with_code_from_host, "rest_engine$get_repos_by_code", test_mocker$use("gh_repos_by_code_raw") ) - repos_with_code_from_host_raw <- github_testhost_priv$get_repos_with_code_from_host( - code = "shiny", - in_files = c("DESCRIPTION", "NAMESPACE"), - output = "raw", - verbose = FALSE + expect_snapshot( + repos_with_code_from_host_raw <- github_testhost_priv$get_repos_with_code_from_host( + code = "shiny", + in_files = c("DESCRIPTION", "NAMESPACE"), + output = "raw", + verbose = TRUE + ) ) expect_type(repos_with_code_from_host_raw, "list") expect_gt(length(repos_with_code_from_host_raw), 0) diff --git a/tests/testthat/test-get_urls_repos-GitHub.R b/tests/testthat/test-get_urls_repos-GitHub.R index 613fe956..0a9c008e 100644 --- a/tests/testthat/test-get_urls_repos-GitHub.R +++ b/tests/testthat/test-get_urls_repos-GitHub.R @@ -59,10 +59,12 @@ test_that("get_repos_urls_from_orgs prepares web repo_urls vector", { ) github_testhost_priv$searching_scope <- "org" github_testhost_priv$orgs <- "test_org" - gh_repos_urls_from_orgs <- github_testhost_priv$get_repos_urls_from_orgs( - type = "web", - verbose = FALSE, - progress = FALSE + expect_snapshot( + gh_repos_urls_from_orgs <- github_testhost_priv$get_repos_urls_from_orgs( + type = "web", + verbose = TRUE, + progress = FALSE + ) ) expect_gt(length(gh_repos_urls_from_orgs), 0) expect_true(any(grepl("test-org", gh_repos_urls_from_orgs))) @@ -118,6 +120,35 @@ test_that("get_all_repos_urls prepares web repo_urls vector", { test_mocker$cache(gh_repos_urls) }) +test_that("get_all_repos_urls is set to scan whole host", { + github_testhost_all_priv <- create_github_testhost_all( + orgs = "test_org", + mode = "private" + ) + mockery::stub( + github_testhost_all_priv$get_all_repos_urls, + "graphql_engine$get_orgs", + "test_org" + ) + mockery::stub( + github_testhost_all_priv$get_all_repos_urls, + "private$get_repos_urls_from_orgs", + test_mocker$use("gh_repos_urls_from_orgs") + ) + mockery::stub( + github_testhost_all_priv$get_all_repos_urls, + "private$get_repos_urls_from_repos", + test_mocker$use("gh_repos_urls") + ) + gh_repos_urls <- github_testhost_all_priv$get_all_repos_urls( + type = "web", + verbose = FALSE + ) + expect_gt(length(gh_repos_urls), 0) + expect_true(any(grepl("test-org", gh_repos_urls))) + expect_true(all(grepl("https://testhost.com/", gh_repos_urls))) +}) + test_that("get_repo_url_from_response retrieves repositories URLS", { gh_repo_api_urls <- github_testhost_priv$get_repo_url_from_response( search_response = test_mocker$use("gh_search_repos_response"),