From 695eeeaa785df9c40f6847f04467142e76b6c109 Mon Sep 17 00:00:00 2001 From: Maciej Banas Date: Tue, 29 Oct 2024 10:07:28 +0000 Subject: [PATCH 01/16] Increment version number to 2.1.1.9000 --- DESCRIPTION | 2 +- NEWS.md | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index d9d6fd78..114d8a74 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: GitStats Title: Get Statistics from 'GitHub' and 'GitLab' -Version: 2.1.1 +Version: 2.1.1.9000 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 f953c45c..40e53474 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,5 @@ +# GitStats (development version) + # GitStats 2.1.1 This is a patch release which introduces some improvements in `get_R_package_usage()` on speed and possibility to pull at once data on multiple R packages, new `get_storage()` function and some fixes for checking token scopes and setting hosts. From 68938aaa8011a613300a59cde6f6ba93faca2f50 Mon Sep 17 00:00:00 2001 From: Maciej Banas Date: Tue, 29 Oct 2024 10:45:45 +0000 Subject: [PATCH 02/16] Fix `if` condition. Previous phrase resulted in error when host searched for default token but had verbose switched to FALSE. --- R/GitHost.R | 6 ++++-- tests/testthat/test-set_host.R | 17 +++++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/R/GitHost.R b/R/GitHost.R index 3e325083..c790ae91 100644 --- a/R/GitHost.R +++ b/R/GitHost.R @@ -516,8 +516,10 @@ GitHost <- R6::R6Class( set_default_token = function(verbose) { primary_token_name <- private$token_name token <- Sys.getenv(primary_token_name) - if (private$test_token(token) && verbose) { - cli::cli_alert_info("Using PAT from {primary_token_name} envar.") + if (private$test_token(token)) { + if (verbose) { + cli::cli_alert_info("Using PAT from {primary_token_name} envar.") + } } else { pat_names <- names(Sys.getenv()[grepl(primary_token_name, names(Sys.getenv()))]) possible_tokens <- pat_names[pat_names != primary_token_name] diff --git a/tests/testthat/test-set_host.R b/tests/testthat/test-set_host.R index 8329187a..795c0cd4 100644 --- a/tests/testthat/test-set_host.R +++ b/tests/testthat/test-set_host.R @@ -173,3 +173,20 @@ test_that("Error pops out when `org` does not exist", { error = TRUE ) }) + +test_that("Setting verbose for set_*_host() to FALSE works fine", { + expect_no_error( + create_gitstats() %>% + set_github_host( + orgs = c("openpharma", "r-world-devs"), + verbose = FALSE + ) + ) + expect_no_error( + create_gitstats() %>% + set_gitlab_host( + orgs = "mbtests", + verbose = FALSE + ) + ) +}) From b28f13d2c480f12dd01b458b698f24569d862072 Mon Sep 17 00:00:00 2001 From: Maciej Banas Date: Tue, 29 Oct 2024 11:39:29 +0000 Subject: [PATCH 03/16] Read api scope for GitLab is TRUE when basic endpoint is read, which is done already in test_token function call. Therefore, the private method for GitLab has been deleted. --- R/GitHostGitLab.R | 22 ++-------------------- tests/testthat/test-helpers.R | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/R/GitHostGitLab.R b/R/GitHostGitLab.R index 428b6e0f..875dc083 100644 --- a/R/GitHostGitLab.R +++ b/R/GitHostGitLab.R @@ -184,27 +184,9 @@ GitHostGitLab <- R6::R6Class("GitHostGitLab", ) }, - # check token scopes - # response parameter only for need of super method + # An empty method to fullfill call from super class. check_token_scopes = function(response = NULL, token) { - private$token_scopes <- try({ - httr2::request(private$endpoints$tokens) %>% - httr2::req_headers("Authorization" = paste0("Bearer ", token)) %>% - httr2::req_perform() %>% - httr2::resp_body_json() %>% - purrr::keep(~ .$active) %>% - purrr::map(function(pat) { - data.frame(scopes = unlist(pat$scopes), date = pat$last_used_at) - }) %>% - purrr::list_rbind() %>% - dplyr::filter( - date == max(date) - ) %>% - dplyr::select(scopes) %>% - unlist() - }, - silent = TRUE) - any(private$access_scopes %in% private$token_scopes) + TRUE }, # Add `api_url` column to table. diff --git a/tests/testthat/test-helpers.R b/tests/testthat/test-helpers.R index 86b4a349..09bb8488 100644 --- a/tests/testthat/test-helpers.R +++ b/tests/testthat/test-helpers.R @@ -151,6 +151,30 @@ test_that("`test_token` works properly", { ) }) +test_that("`test_token` works properly", { + skip_on_cran() + expect_true( + gitlab_testhost_priv$test_token(Sys.getenv("GITLAB_PAT_PUBLIC")) + ) + expect_false( + gitlab_testhost_priv$test_token("false_token") + ) +}) + +test_that("`check_token_scopes` works for GitHub", { + skip_on_cran() + github_pat <- Sys.getenv("GITHUB_PAT") + github_response <- httr2::request("https://api.github.com") |> + httr2::req_headers("Authorization" = paste0("Bearer ", github_pat)) |> + httr2::req_perform() + expect_true( + github_testhost_priv$check_token_scopes( + response = github_response, + token = github_pat + ) + ) +}) + test_that("`set_default_token` sets default token for GitLab", { skip_on_cran() expect_snapshot( From f5c82efb917a9cb82db39884f0ebfd34558275d1 Mon Sep 17 00:00:00 2001 From: Maciej Banas Date: Tue, 29 Oct 2024 11:40:03 +0000 Subject: [PATCH 04/16] Small fixes in DESCRIPTION and Readme. --- DESCRIPTION | 2 +- README.Rmd | 4 +++- README.md | 4 +++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 114d8a74..c5f14ef2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -8,7 +8,7 @@ Authors@R: c( person(given = "Matt", family = "Secrest", email = "secrestm@gene.com", role = "aut") ) Description: Obtain statistics in a standardized way from multiple 'Git' services: 'GitHub' and 'GitLab' for the time-being. - Its main purpose is to help teams, whose activities are spread across multiple git platforms, get their repository metadata + Its main purpose is to help teams, whose activities are spread across multiple 'Git' platforms, get their repository metadata in a standardized way from all these platforms. License: MIT + file LICENSE Encoding: UTF-8 diff --git a/README.Rmd b/README.Rmd index 8f6de2aa..776f072b 100644 --- a/README.Rmd +++ b/README.Rmd @@ -33,13 +33,15 @@ With GitStats you can pull git data in a uniform way (table format) from GitHub ## Installation -```r From CRAN: +```r install.packages("GitStats") +``` Or development version: +```r devtools::install_github("r-world-devs/GitStats") ``` diff --git a/README.md b/README.md index decb72a6..0d3003f3 100644 --- a/README.md +++ b/README.md @@ -24,13 +24,15 @@ GitHub and GitLab. For the time-being you can get data on: ## Installation -``` r From CRAN: +``` r install.packages("GitStats") +``` Or development version: +``` r devtools::install_github("r-world-devs/GitStats") ``` From d22bba31e7be8680b8644c73f580c22c7f218f8f Mon Sep 17 00:00:00 2001 From: Maciej Banas Date: Tue, 29 Oct 2024 11:47:24 +0000 Subject: [PATCH 05/16] Update NEWS. --- NEWS.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/NEWS.md b/NEWS.md index 40e53474..659580cb 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +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)). + # GitStats 2.1.1 This is a patch release which introduces some improvements in `get_R_package_usage()` on speed and possibility to pull at once data on multiple R packages, new `get_storage()` function and some fixes for checking token scopes and setting hosts. From 83c971fbcc674c78c01e88aee25e56b0c9d4a4cb Mon Sep 17 00:00:00 2001 From: Maciej Banas Date: Tue, 29 Oct 2024 12:02:46 +0000 Subject: [PATCH 06/16] Update Title and Description. --- DESCRIPTION | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index c5f14ef2..51db616b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,5 +1,5 @@ Package: GitStats -Title: Get Statistics from 'GitHub' and 'GitLab' +Title: Standardized Git Repository Statistics Version: 2.1.1.9000 Authors@R: c( person(given = "Maciej", family = "Banas", email = "banasmaciek@gmail.com", role = c("aut", "cre")), @@ -7,9 +7,9 @@ Authors@R: c( person(given = "Karolina", family = "Marcinkowska", email = "karolina_marcinkowska@onet.pl", role = "aut"), person(given = "Matt", family = "Secrest", email = "secrestm@gene.com", role = "aut") ) -Description: Obtain statistics in a standardized way from multiple 'Git' services: 'GitHub' and 'GitLab' for the time-being. - Its main purpose is to help teams, whose activities are spread across multiple 'Git' platforms, get their repository metadata - in a standardized way from all these platforms. +Description: Obtain standardized statistics from multiple 'Git' services, including 'GitHub' and 'GitLab'. + Designed to be 'Git' service-agnostic, this package assists teams with activities spread across various + 'Git' platforms by providing a unified way to access repository metadata. License: MIT + file LICENSE Encoding: UTF-8 Roxygen: list(markdown = TRUE, r6 = TRUE) From d438e9d60ea094935a7a1411d98eaf8399dcaa9d Mon Sep 17 00:00:00 2001 From: Maciej Banas Date: Thu, 31 Oct 2024 10:42:16 +0000 Subject: [PATCH 07/16] Fix `get_repos_urls()` output when individual repositories are set in `set_*_host()`. --- DESCRIPTION | 2 +- NEWS.md | 1 + R/EngineRestGitHub.R | 11 +++-- R/EngineRestGitLab.R | 11 +++-- R/GitHost.R | 3 +- inst/get_repos_urls_workflow.R | 27 ++++++++++++ tests/testthat/helper-fixtures.R | 14 ++++++ tests/testthat/test-get_urls_repos-GitHub.R | 30 ++++++++++--- tests/testthat/test-get_urls_repos-GitLab.R | 48 +++++++++++++++++---- 9 files changed, 125 insertions(+), 22 deletions(-) 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) }) From 7d00dd4420f33aa34e7afb8896b3669e1cb0afb2 Mon Sep 17 00:00:00 2001 From: Maciej Banas Date: Thu, 31 Oct 2024 15:45:51 +0000 Subject: [PATCH 08/16] Small but horrible bug. --- R/GitStats.R | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/R/GitStats.R b/R/GitStats.R index 8d93cef7..46a6325f 100644 --- a/R/GitStats.R +++ b/R/GitStats.R @@ -700,7 +700,7 @@ GitStats <- R6::R6Class( progress = progress ) } else if (!is.null(with_files)) { - privater$get_repos_from_host_with_files( + private$get_repos_from_host_with_files( host = host, add_contributors = add_contributors, with_files = with_files, From 6b40e5094aef0e2d3b768e07658118771d52991f Mon Sep 17 00:00:00 2001 From: Maciej Banas Date: Mon, 4 Nov 2024 09:33:11 +0000 Subject: [PATCH 09/16] Fix getting GitLab subgroups in repos table. --- DESCRIPTION | 2 +- NEWS.md | 1 + R/EngineRestGitLab.R | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index f12772d3..38060ea8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: GitStats Title: Standardized Git Repository Statistics -Version: 2.1.1.9001 +Version: 2.1.1.9002 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 78c6a630..362acee3 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,7 @@ - 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)). +- Fixed getting GitLab subgroups as organizations in repositories table output when pulling repositories with code ([#531](https://github.com/r-world-devs/GitStats/issues/531)). # GitStats 2.1.1 diff --git a/R/EngineRestGitLab.R b/R/EngineRestGitLab.R index 817ff647..4f73d640 100644 --- a/R/EngineRestGitLab.R +++ b/R/EngineRestGitLab.R @@ -107,7 +107,7 @@ EngineRestGitLab <- R6::R6Class( "languages" = paste0(project$languages, collapse = ", "), "issues_open" = project$issues_open, "issues_closed" = project$issues_closed, - "organization" = project$namespace$path, + "organization" = project$namespace$full_path, "repo_url" = project$web_url ) } From 98685c06fb275b4bc252cd6b9129fd2f0f1e6ddd Mon Sep 17 00:00:00 2001 From: Maciej Banas Date: Thu, 7 Nov 2024 09:55:13 +0000 Subject: [PATCH 10/16] Bump version, update NEWS, small change to DESCRIPTION. --- DESCRIPTION | 8 ++++---- NEWS.md | 4 +++- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 38060ea8..86362475 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,15 +1,15 @@ Package: GitStats -Title: Standardized Git Repository Statistics -Version: 2.1.1.9002 +Title: Standardized Git Repository Data +Version: 2.1.2 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"), person(given = "Karolina", family = "Marcinkowska", email = "karolina_marcinkowska@onet.pl", role = "aut"), person(given = "Matt", family = "Secrest", email = "secrestm@gene.com", role = "aut") ) -Description: Obtain standardized statistics from multiple 'Git' services, including 'GitHub' and 'GitLab'. +Description: Obtain standardized data from multiple 'Git' services, including 'GitHub' and 'GitLab'. Designed to be 'Git' service-agnostic, this package assists teams with activities spread across various - 'Git' platforms by providing a unified way to access repository metadata. + 'Git' platforms by providing a unified way to access repository data. License: MIT + file LICENSE Encoding: UTF-8 Roxygen: list(markdown = TRUE, r6 = TRUE) diff --git a/NEWS.md b/NEWS.md index 362acee3..d4885335 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,4 +1,6 @@ -# GitStats (development version) +# GitStats 2.1.2 + +This is a patch release which introduces some hot fixes. - 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)). From 18182ac1268ba2a9cf31b90df468f723992e9075 Mon Sep 17 00:00:00 2001 From: Maciej Banas Date: Tue, 12 Nov 2024 10:50:55 +0000 Subject: [PATCH 11/16] Add new repo_url column to commits table. --- DESCRIPTION | 2 +- NEWS.md | 1 + R/EngineGraphQLGitHub.R | 6 ++++++ R/EngineRestGitLab.R | 3 ++- R/GQLQueryGitHub.R | 3 +++ R/GitHostGitHub.R | 4 +++- tests/testthat/_snaps/get_commits-GitHub.md | 2 +- tests/testthat/helper-expect-responses.R | 2 +- tests/testthat/helper-expect-tables.R | 4 ++-- tests/testthat/helper-fixtures.R | 7 +++++-- 10 files changed, 25 insertions(+), 9 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 38060ea8..87b15594 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: GitStats Title: Standardized Git Repository Statistics -Version: 2.1.1.9002 +Version: 2.1.1.9003 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 362acee3..b6f7ca36 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # GitStats (development version) +- Added `repo_url` column to output of `get_commits()` function ([#535](https://github.com/r-world-devs/GitStats/issues/535)). - 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)). - Fixed getting GitLab subgroups as organizations in repositories table output when pulling repositories with code ([#531](https://github.com/r-world-devs/GitStats/issues/531)). diff --git a/R/EngineGraphQLGitHub.R b/R/EngineGraphQLGitHub.R index aa20a36f..fce1bc26 100644 --- a/R/EngineGraphQLGitHub.R +++ b/R/EngineGraphQLGitHub.R @@ -143,6 +143,8 @@ EngineGraphQLGitHub <- R6::R6Class( NA } commit$node$committed_date <- gts_to_posixt(commit$node$committed_date) + commit$node$repo_url <- commit$node$repository$url + commit$node$repository <- NULL commit$node }) commits_row$repository <- repo_name @@ -159,6 +161,10 @@ EngineGraphQLGitHub <- R6::R6Class( dplyr::relocate( any_of(c("author_login", "author_name")), .after = author + ) %>% + dplyr::relocate( + repo_url, + .before = api_url ) } return(commits_table) diff --git a/R/EngineRestGitLab.R b/R/EngineRestGitLab.R index 4f73d640..1324df50 100644 --- a/R/EngineRestGitLab.R +++ b/R/EngineRestGitLab.R @@ -142,7 +142,8 @@ EngineRestGitLab <- R6::R6Class( replacement = "", x = gsub(paste0("(.*)", org, "/"), "", commit$web_url) ), - "organization" = org + "organization" = org, + "repo_url" = stringr::str_match(commit$web_url, "(.*)/-/commit/.*")[2] ) }) }) diff --git a/R/GQLQueryGitHub.R b/R/GQLQueryGitHub.R index 555d3269..439065d8 100644 --- a/R/GQLQueryGitHub.R +++ b/R/GQLQueryGitHub.R @@ -147,6 +147,9 @@ GQLQueryGitHub <- R6::R6Class("GQLQueryGitHub", } additions deletions + repository { + url + } } } } diff --git a/R/GitHostGitHub.R b/R/GitHostGitHub.R index f4e570df..4b0089c3 100644 --- a/R/GitHostGitHub.R +++ b/R/GitHostGitHub.R @@ -188,7 +188,9 @@ GitHostGitHub <- R6::R6Class( until = until, progress = progress ) %>% - graphql_engine$prepare_commits_table(org) + graphql_engine$prepare_commits_table( + org = org + ) return(commits_table_org) }, .progress = if (private$scan_all && progress) { "[GitHost:GitHub] Pulling commits..." diff --git a/tests/testthat/_snaps/get_commits-GitHub.md b/tests/testthat/_snaps/get_commits-GitHub.md index 637aace0..8a2b9065 100644 --- a/tests/testthat/_snaps/get_commits-GitHub.md +++ b/tests/testthat/_snaps/get_commits-GitHub.md @@ -3,5 +3,5 @@ Code gh_commits_by_repo_query Output - [1] "{\n repository(name: \"GitStats\", owner: \"r-world-devs\") {\n defaultBranchRef {\n target {\n ... on Commit {\n history(since: \"2023-01-01T00:00:00Z\"\n until: \"2023-02-28T00:00:00Z\"\n \n ) {\n pageInfo {\n hasNextPage\n endCursor\n }\n edges {\n node {\n ... on Commit {\n id\n committed_date: committedDate\n author {\n name\n user {\n name\n login\n }\n }\n additions\n deletions\n }\n }\n }\n }\n }\n }\n }\n }\n }" + [1] "{\n repository(name: \"GitStats\", owner: \"r-world-devs\") {\n defaultBranchRef {\n target {\n ... on Commit {\n history(since: \"2023-01-01T00:00:00Z\"\n until: \"2023-02-28T00:00:00Z\"\n \n ) {\n pageInfo {\n hasNextPage\n endCursor\n }\n edges {\n node {\n ... on Commit {\n id\n committed_date: committedDate\n author {\n name\n user {\n name\n login\n }\n }\n additions\n deletions\n repository {\n url\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }" diff --git a/tests/testthat/helper-expect-responses.R b/tests/testthat/helper-expect-responses.R index a0590472..32dba117 100644 --- a/tests/testthat/helper-expect-responses.R +++ b/tests/testthat/helper-expect-responses.R @@ -112,7 +112,7 @@ expect_gh_commit_gql_response <- function(object) { ) expect_list_contains( object$node, - c("id", "committed_date", "author", "additions", "deletions") + c("id", "committed_date", "author", "additions", "deletions", "repository") ) } diff --git a/tests/testthat/helper-expect-tables.R b/tests/testthat/helper-expect-tables.R index 74b555b9..12043a2e 100644 --- a/tests/testthat/helper-expect-tables.R +++ b/tests/testthat/helper-expect-tables.R @@ -40,12 +40,12 @@ expect_commits_table <- function(get_commits_object, with_stats = TRUE, exp_auth commit_cols <- if (exp_author) { c( "id", "committed_date", "author", "author_login", "author_name", "additions", "deletions", - "repository", "organization", "api_url" + "repository", "organization", "repo_url", "api_url" ) } else { c( "id", "committed_date", "author", "additions", "deletions", - "repository", "organization", "api_url" + "repository", "organization", "repo_url", "api_url" ) } expect_s3_class(get_commits_object, "data.frame") diff --git a/tests/testthat/helper-fixtures.R b/tests/testthat/helper-fixtures.R index bf7a473a..5fc10365 100644 --- a/tests/testthat/helper-fixtures.R +++ b/tests/testthat/helper-fixtures.R @@ -257,7 +257,10 @@ github_commit_edge <- list( ) ), "additions" = 5L, - "deletions" = 8L + "deletions" = 8L, + "repository" = list( + "url" = "test_url" + ) ) ) @@ -294,7 +297,7 @@ gitlab_commit <- list( "committed_date" = "2023-04-05T12:07:50.000+00:00", "trailers" = list(), "extedned_trailers" = list(), - "web_url" = "https://test_url.com", + "web_url" = "https://test_url.com/-/commit/sxsxsxsx", "stats" = list( "additions" = 1L, "deletions" = 0L, From a88c316cf42a4455703e46cc8268d820a8819881 Mon Sep 17 00:00:00 2001 From: Maciej Banas Date: Tue, 12 Nov 2024 11:09:48 +0000 Subject: [PATCH 12/16] Prettify GraphQL query for commits, remove unncecessary authors query. --- R/EngineGraphQLGitHub.R | 20 ++++++------- R/GQLQueryGitHub.R | 33 +++++++-------------- tests/testthat/_snaps/get_commits-GitHub.md | 4 +-- tests/testthat/test-get_commits-GitHub.R | 12 ++------ 4 files changed, 25 insertions(+), 44 deletions(-) diff --git a/R/EngineGraphQLGitHub.R b/R/EngineGraphQLGitHub.R index fce1bc26..f75f827a 100644 --- a/R/EngineGraphQLGitHub.R +++ b/R/EngineGraphQLGitHub.R @@ -392,18 +392,18 @@ EngineGraphQLGitHub <- R6::R6Class( repo, since, until, - commits_cursor = "", - author_id = "") { - commits_by_org_query <- self$gql_query$commits_by_repo( - org = org, - repo = repo, - since = date_to_gts(since), - until = date_to_gts(until), - commits_cursor = commits_cursor, - author_id = author_id + commits_cursor = "") { + commits_by_org_query <- self$gql_query$commits_from_repo( + commits_cursor = commits_cursor ) response <- self$gql_response( - gql_query = commits_by_org_query + gql_query = commits_by_org_query, + vars = list( + "org" = org, + "repo" = repo, + "since" = date_to_gts(since), + "until" = date_to_gts(until) + ) ) return(response) }, diff --git a/R/GQLQueryGitHub.R b/R/GQLQueryGitHub.R index 439065d8..2c465b67 100644 --- a/R/GQLQueryGitHub.R +++ b/R/GQLQueryGitHub.R @@ -101,34 +101,21 @@ GQLQueryGitHub <- R6::R6Class("GQLQueryGitHub", }, #' @description Prepare query to get commits on GitHub. - #' @param org A GitHub organization. - #' @param repo Name of a repository. - #' @param since Git Time Stamp of starting date of commits. - #' @param until Git Time Stamp of end date of commits. #' @param commits_cursor An endCursor. - #' @param author_id An Id of an author. #' @return A query. - commits_by_repo = function(org, - repo, - since, - until, - commits_cursor = "", - author_id = "") { - if (nchar(author_id) == 0) { - author_filter <- author_id - } else { - author_filter <- paste0('author: { id: "', author_id, '"}') - } - - paste0('{ - repository(name: "', repo, '", owner: "', org, '") { + commits_from_repo = function(commits_cursor = "") { + paste0(' + query GetCommitsFromRepo($repo: String! + $org: String! + $since: GitTimestamp + $until: GitTimestamp){ + repository(name: $repo, owner: $org) { defaultBranchRef { target { ... on Commit { - history(since: "', since, '" - until: "', until, '" - ', private$add_cursor(commits_cursor), " - ", author_filter, ") { + history(since: $since + until: $until + ', private$add_cursor(commits_cursor), ") { pageInfo { hasNextPage endCursor diff --git a/tests/testthat/_snaps/get_commits-GitHub.md b/tests/testthat/_snaps/get_commits-GitHub.md index 8a2b9065..2f631896 100644 --- a/tests/testthat/_snaps/get_commits-GitHub.md +++ b/tests/testthat/_snaps/get_commits-GitHub.md @@ -1,7 +1,7 @@ # commits_by_repo GitHub query is built properly Code - gh_commits_by_repo_query + gh_commits_from_repo_query Output - [1] "{\n repository(name: \"GitStats\", owner: \"r-world-devs\") {\n defaultBranchRef {\n target {\n ... on Commit {\n history(since: \"2023-01-01T00:00:00Z\"\n until: \"2023-02-28T00:00:00Z\"\n \n ) {\n pageInfo {\n hasNextPage\n endCursor\n }\n edges {\n node {\n ... on Commit {\n id\n committed_date: committedDate\n author {\n name\n user {\n name\n login\n }\n }\n additions\n deletions\n repository {\n url\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }" + [1] "\n query GetCommitsFromRepo($repo: String!\n $org: String!\n $since: GitTimestamp\n $until: GitTimestamp){\n repository(name: $repo, owner: $org) {\n defaultBranchRef {\n target {\n ... on Commit {\n history(since: $since\n until: $until\n ) {\n pageInfo {\n hasNextPage\n endCursor\n }\n edges {\n node {\n ... on Commit {\n id\n committed_date: committedDate\n author {\n name\n user {\n name\n login\n }\n }\n additions\n deletions\n repository {\n url\n }\n }\n }\n }\n }\n }\n }\n }\n }\n }" diff --git a/tests/testthat/test-get_commits-GitHub.R b/tests/testthat/test-get_commits-GitHub.R index c8b4e6e3..65433a53 100644 --- a/tests/testthat/test-get_commits-GitHub.R +++ b/tests/testthat/test-get_commits-GitHub.R @@ -1,15 +1,9 @@ test_that("commits_by_repo GitHub query is built properly", { - gh_commits_by_repo_query <- - test_gqlquery_gh$commits_by_repo( - org = "r-world-devs", - repo = "GitStats", - since = "2023-01-01T00:00:00Z", - until = "2023-02-28T00:00:00Z" - ) + gh_commits_from_repo_query <- + test_gqlquery_gh$commits_from_repo() expect_snapshot( - gh_commits_by_repo_query + gh_commits_from_repo_query ) - test_mocker$cache(gh_commits_by_repo_query) }) test_that("`get_commits_page_from_repo()` pulls commits page from repository", { From b1f30a0c1c2ac41a1af3fddacd891a320005fa7a Mon Sep 17 00:00:00 2001 From: Maciej Banas Date: Tue, 12 Nov 2024 12:07:02 +0000 Subject: [PATCH 13/16] Try adjust test to GH Actions where 'Couldn't resolve host name [wrong.url]: Could not resolve host: wrong.url' is run instead of simple 'Could not resolve host: wrong.url' which shows locally. --- tests/testthat/_snaps/set_host.md | 9 --------- tests/testthat/test-set_host.R | 4 ++-- 2 files changed, 2 insertions(+), 11 deletions(-) diff --git a/tests/testthat/_snaps/set_host.md b/tests/testthat/_snaps/set_host.md index e3e8c181..48d069fd 100644 --- a/tests/testthat/_snaps/set_host.md +++ b/tests/testthat/_snaps/set_host.md @@ -80,15 +80,6 @@ i Check if you use correct token. ! Scope that is needed: [read_api]. ---- - - Code - create_gitstats() %>% set_github_host(host = "wrong.url", orgs = c("openpharma", - "r_world_devs")) - Condition - Error: - ! Could not resolve host: wrong.url - # Error pops out, when two clients of the same url api are passed as input Code diff --git a/tests/testthat/test-set_host.R b/tests/testthat/test-set_host.R index 795c0cd4..85069b3a 100644 --- a/tests/testthat/test-set_host.R +++ b/tests/testthat/test-set_host.R @@ -113,14 +113,14 @@ test_that("Error shows, when wrong input is passed when setting connection and h token = Sys.getenv("GITLAB_PAT_PUBLIC") ) ) - expect_snapshot({ + expect_error({ create_gitstats() %>% set_github_host( host = "wrong.url", orgs = c("openpharma", "r_world_devs") ) }, - error = TRUE + "Could not resolve host." ) }) From 2d3a637fe8b801ebdf4af2ae66088909183d6342 Mon Sep 17 00:00:00 2001 From: Maciej Banas Date: Tue, 12 Nov 2024 12:35:11 +0000 Subject: [PATCH 14/16] Update NEWS. --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index cb1a7515..4c468524 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,6 +1,6 @@ # GitStats 2.1.2 -This is a patch release which introduces some hot fixes. +This is a patch release which introduces some hot fixes and new data in `get_commits()` output. - Added `repo_url` column to output of `get_commits()` function ([#535](https://github.com/r-world-devs/GitStats/issues/535)). - 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)). From e4564af9b5e97dc2dae6c487cd12f733c0165071 Mon Sep 17 00:00:00 2001 From: Maciej Banas Date: Tue, 12 Nov 2024 13:18:35 +0000 Subject: [PATCH 15/16] Skip test on CRAN. --- DESCRIPTION | 2 +- tests/testthat/test-set_host.R | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 86362475..17cf416f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: GitStats Title: Standardized Git Repository Data -Version: 2.1.2 +Version: 2.1.1.9004 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/tests/testthat/test-set_host.R b/tests/testthat/test-set_host.R index 85069b3a..cdeaf470 100644 --- a/tests/testthat/test-set_host.R +++ b/tests/testthat/test-set_host.R @@ -175,6 +175,7 @@ test_that("Error pops out when `org` does not exist", { }) test_that("Setting verbose for set_*_host() to FALSE works fine", { + skip_on_cran() expect_no_error( create_gitstats() %>% set_github_host( From 73727017e91a366b8c7b5c60d177de51cff2e774 Mon Sep 17 00:00:00 2001 From: Maciej Banas Date: Tue, 12 Nov 2024 14:48:29 +0000 Subject: [PATCH 16/16] Bump version. --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 17cf416f..86362475 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: GitStats Title: Standardized Git Repository Data -Version: 2.1.1.9004 +Version: 2.1.2 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"),