diff --git a/DESCRIPTION b/DESCRIPTION index 51db616b..f12772d3 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: GitStats Title: Standardized Git Repository Statistics -Version: 2.1.1.9000 +Version: 2.1.1.9001 Authors@R: c( person(given = "Maciej", family = "Banas", email = "banasmaciek@gmail.com", role = c("aut", "cre")), person(given = "Kamil", family = "Koziej", email = "koziej.k@gmail.com", role = "aut"), diff --git a/NEWS.md b/NEWS.md index 659580cb..78c6a630 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,7 @@ # GitStats (development version) - Fixed setting default tokens when `verbose` mode is set to `FALSE` ([#525](https://github.com/r-world-devs/GitStats/issues/525)) and fixed checking token scopes for GitLab ([#526](https://github.com/r-world-devs/GitStats/issues/526)). +- Fixed `get_repos_urls()` output when individual repositories are set in `set_*_host()`([#529](https://github.com/r-world-devs/GitStats/issues/529)). Earlier the function pulled all repositories for an organization, even though, repositories were defined for the host, not whole organizations. This is similar to the solved earlier ([#439](https://github.com/r-world-devs/GitStats/issues/439)). # GitStats 2.1.1 diff --git a/R/EngineRestGitHub.R b/R/EngineRestGitHub.R index 5b8a69b1..86ec5e91 100644 --- a/R/EngineRestGitHub.R +++ b/R/EngineRestGitHub.R @@ -106,10 +106,15 @@ EngineRestGitHub <- R6::R6Class( }, #' Pull all repositories URLS from organization - get_repos_urls = function(type, org) { - repos_urls <- self$response( + get_repos_urls = function(type, org, repos) { + repos_response <- self$response( endpoint = paste0(private$endpoints[["organizations"]], org, "/repos") - ) %>% + ) + if (!is.null(repos)) { + repos_response <- repos_response %>% + purrr::keep(~ .$name %in% repos) + } + repos_urls <- repos_response %>% purrr::map_vec(function(repository) { if (type == "api") { repository$url diff --git a/R/EngineRestGitLab.R b/R/EngineRestGitLab.R index a11048ce..817ff647 100644 --- a/R/EngineRestGitLab.R +++ b/R/EngineRestGitLab.R @@ -166,10 +166,15 @@ EngineRestGitLab <- R6::R6Class( }, # Pull all repositories URLs from organization - get_repos_urls = function(type, org) { - repos_urls <- self$response( + get_repos_urls = function(type, org, repos) { + repos_response <- self$response( endpoint = paste0(private$endpoints[["organizations"]], utils::URLencode(org, reserved = TRUE), "/projects") - ) %>% + ) + if (!is.null(repos)) { + repos_response <- repos_response %>% + purrr::keep(~ .$path %in% repos) + } + repos_urls <- repos_response %>% purrr::map_vec(function(project) { if (type == "api") { project$`_links`$self diff --git a/R/GitHost.R b/R/GitHost.R index c790ae91..0fb6981c 100644 --- a/R/GitHost.R +++ b/R/GitHost.R @@ -700,7 +700,8 @@ GitHost <- R6::R6Class( } repos_urls <- rest_engine$get_repos_urls( type = type, - org = org + org = org, + repos = private$set_repos(org) ) return(repos_urls) }, .progress = progress) %>% diff --git a/inst/get_repos_urls_workflow.R b/inst/get_repos_urls_workflow.R index ad357185..b78979a0 100644 --- a/inst/get_repos_urls_workflow.R +++ b/inst/get_repos_urls_workflow.R @@ -6,3 +6,30 @@ test_gitstats <- create_gitstats() |> ) get_repos_urls(test_gitstats, with_code = "shiny") + +# should return 2 repos URLs +create_gitstats() %>% + set_github_host( + repos = c("r-world-devs/GitStats", "r-world-devs/shinyCohortBuilder") + ) %>% + get_repos_urls() + +# should return 2 repos URLs +create_gitstats() %>% + set_github_host( + repos = c("r-world-devs/GitStats", "r-world-devs/shinyCohortBuilder") + ) %>% + get_repos_urls(type = "api") + +create_gitstats() %>% + set_gitlab_host( + orgs = "mbtests" + ) %>% + get_repos_urls() + +# should return 1 repo URL +create_gitstats() %>% + set_gitlab_host( + repos = "mbtests/gitstatstesting" + ) %>% + get_repos_urls(type = "api") diff --git a/tests/testthat/helper-fixtures.R b/tests/testthat/helper-fixtures.R index 6d574213..bf7a473a 100644 --- a/tests/testthat/helper-fixtures.R +++ b/tests/testthat/helper-fixtures.R @@ -65,6 +65,13 @@ test_fixtures$github_repositories_rest_response <- list( test_fixtures$github_repository_rest_response, list( "id" = 2222222222222, + "name" = "testRepo2", + "html_url" = "https://testhost.com/test-org/TestRepo", + "url" = "https://testhost.com/api/v4/repos/test-org/TestRepo" + ), + list( + "id" = 2222222222222, + "name" = "testRepo3", "html_url" = "https://testhost.com/test-org/TestRepo", "url" = "https://testhost.com/api/v4/repos/test-org/TestRepo" ) @@ -73,10 +80,17 @@ test_fixtures$github_repositories_rest_response <- list( test_fixtures$gitlab_repositories_rest_response <- list( list( + "path" = "testRepo1", "_links" = list("self" = "https://gitlab.com/api/v4/projects/43400864"), "web_url" = "https://gitlab.com/mbtests/gitstats-testing-2" ), list( + "path" = "testRepo2", + "_links" = list("self" = "https://gitlab.com/api/v4/projects/43398933"), + "web_url" = "https://gitlab.com/mbtests/gitstatstesting" + ), + list( + "path" = "testRepo3", "_links" = list("self" = "https://gitlab.com/api/v4/projects/43398933"), "web_url" = "https://gitlab.com/mbtests/gitstatstesting" ) diff --git a/tests/testthat/test-get_urls_repos-GitHub.R b/tests/testthat/test-get_urls_repos-GitHub.R index 9cada53a..fd0c2e75 100644 --- a/tests/testthat/test-get_urls_repos-GitHub.R +++ b/tests/testthat/test-get_urls_repos-GitHub.R @@ -1,4 +1,4 @@ -test_that("get_repos_urls() works", { +test_that("get_repos_urls() works for whole orgs", { mockery::stub( test_rest_github$get_repos_urls, "self$response", @@ -6,11 +6,30 @@ test_that("get_repos_urls() works", { ) gh_repos_urls <- test_rest_github$get_repos_urls( type = "web", - org = "test-org" + org = "test-org", + repos = NULL ) - expect_gt( - length(gh_repos_urls), - 0 + expect_length( + gh_repos_urls, + 3 + ) + test_mocker$cache(gh_repos_urls) +}) + +test_that("get_repos_urls() works for individual repos", { + mockery::stub( + test_rest_github$get_repos_urls, + "self$response", + test_fixtures$github_repositories_rest_response + ) + gh_repos_urls <- test_rest_github$get_repos_urls( + type = "web", + org = "test-org", + repos = c("testRepo", "testRepo2") + ) + expect_length( + gh_repos_urls, + 2 ) test_mocker$cache(gh_repos_urls) }) @@ -24,6 +43,7 @@ test_that("get_all_repos_urls prepares api repo_urls vector", { test_fixtures$github_repositories_rest_response ) gh_api_repos_urls <- test_rest_github$get_repos_urls( + repos = NULL, type = "api" ) expect_gt(length(gh_api_repos_urls), 0) diff --git a/tests/testthat/test-get_urls_repos-GitLab.R b/tests/testthat/test-get_urls_repos-GitLab.R index 5e743c0b..75f28141 100644 --- a/tests/testthat/test-get_urls_repos-GitLab.R +++ b/tests/testthat/test-get_urls_repos-GitLab.R @@ -1,4 +1,4 @@ -test_that("get_repos_urls() works", { +test_that("get_repos_urls() works for org", { mockery::stub( test_rest_gitlab$get_repos_urls, "self$response", @@ -6,20 +6,50 @@ test_that("get_repos_urls() works", { ) gl_api_repos_urls <- test_rest_gitlab$get_repos_urls( type = "api", - org = "mbtests" + org = "mbtests", + repos = NULL ) - expect_gt( - length(gl_api_repos_urls), - 0 + expect_length( + gl_api_repos_urls, + 3 ) test_mocker$cache(gl_api_repos_urls) gl_web_repos_urls <- test_rest_gitlab$get_repos_urls( type = "web", - org = "mbtests" + org = "mbtests", + repos = NULL ) - expect_gt( - length(gl_web_repos_urls), - 0 + expect_length( + gl_web_repos_urls, + 3 + ) + test_mocker$cache(gl_web_repos_urls) +}) + +test_that("get_repos_urls() works for individual repos", { + mockery::stub( + test_rest_gitlab$get_repos_urls, + "self$response", + test_fixtures$gitlab_repositories_rest_response + ) + gl_api_repos_urls <- test_rest_gitlab$get_repos_urls( + type = "api", + org = "mbtests", + repos = c("testRepo1", "testRepo2") + ) + expect_length( + gl_api_repos_urls, + 2 + ) + test_mocker$cache(gl_api_repos_urls) + gl_web_repos_urls <- test_rest_gitlab$get_repos_urls( + type = "web", + org = "mbtests", + repos = c("testRepo1", "testRepo2") + ) + expect_length( + gl_web_repos_urls, + 2 ) test_mocker$cache(gl_web_repos_urls) })