From 695eeeaa785df9c40f6847f04467142e76b6c109 Mon Sep 17 00:00:00 2001 From: Maciej Banas Date: Tue, 29 Oct 2024 10:07:28 +0000 Subject: [PATCH 1/6] 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 2/6] 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 3/6] 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 4/6] 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 5/6] 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 6/6] 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)