Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: GitStats
Title: Standardized Git Repository Data
Version: 2.5.1.9000
Version: 2.5.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"),
Expand Down
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# GitStats (development version)

## Improvements

- `set_github_host()` and `set_gitlab_host()` now print elapsed time after setting up the host ([#798](https://github.com/r-world-devs/GitStats/issues/798)).

## Bug fixes

- Fixed `get_orgs()` failing for GitLab hosts with more than 10,000 groups. Since GitLab 15.7, the `x-total` header is suppressed from REST API responses when the result set exceeds 10,000 records. The org count is now obtained via GraphQL `groups { count }` query instead ([#793](https://github.com/r-world-devs/GitStats/issues/793)).
Expand Down
12 changes: 12 additions & 0 deletions R/set_host.R
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ set_github_host <- function(gitstats,
repos = NULL,
verbose = is_verbose(gitstats),
.error = TRUE) {
start_time <- Sys.time()
gitstats$set_github_host(
host = host,
token = token,
Expand All @@ -40,6 +41,11 @@ set_github_host <- function(gitstats,
verbose = verbose,
.error = .error
)
end_time <- Sys.time()
time_taken <- end_time - start_time
if (verbose) {
cli::cli_alert_info("Set up in {round(time_taken, 1)} {attr(time_taken, 'units')}.")
}

return(invisible(gitstats))
}
Expand Down Expand Up @@ -69,6 +75,7 @@ set_gitlab_host <- function(gitstats,
repos = NULL,
verbose = is_verbose(gitstats),
.error = TRUE) {
start_time <- Sys.time()
gitstats$set_gitlab_host(
host = host,
token = token,
Expand All @@ -77,6 +84,11 @@ set_gitlab_host <- function(gitstats,
verbose = verbose,
.error = .error
)
end_time <- Sys.time()
time_taken <- end_time - start_time
if (verbose) {
cli::cli_alert_info("Set up in {round(time_taken, 1)} {attr(time_taken, 'units')}.")
}

return(invisible(gitstats))
}
94 changes: 1 addition & 93 deletions tests/testthat/_snaps/set_host.md
Original file line number Diff line number Diff line change
@@ -1,70 +1,3 @@
# Set connection returns appropriate messages

Code
set_github_host(gitstats = test_gitstats, token = Sys.getenv("GITHUB_PAT"),
orgs = c("openpharma", "r-world-devs"))
Message
> Checking owners...
v Set connection to GitHub.

---

Code
set_gitlab_host(test_gitstats, token = Sys.getenv("GITLAB_PAT_PUBLIC"), orgs = c(
"mbtests"))
Message
> Checking owners...
v Set connection to GitLab.

# When empty token for GitHub, GitStats pulls default token

Code
test_gitstats <- set_github_host(create_gitstats(), orgs = c("openpharma",
"r-world-devs"))
Message
i Using PAT from GITHUB_PAT envar.
> Checking owners...
v Set connection to GitHub.

# When empty token for GitLab, GitStats pulls default token

Code
withr::with_envvar(new = c(GITLAB_PAT = Sys.getenv("GITLAB_PAT_PUBLIC")), {
test_gitstats <- set_gitlab_host(create_gitstats(), orgs = "mbtests")
})
Message
i Using PAT from GITLAB_PAT envar.
> Checking owners...
v Set connection to GitLab.

# Set GitHub host with particular repos vector instead of orgs

Code
set_github_host(test_gitstats, token = Sys.getenv("GITHUB_PAT"), repos = c(
"r-world-devs/GitStats", "r-world-devs/shinyCohortBuilder",
"openpharma/GithubMetrics", "openpharma/DataFakeR"))
Message
> Checking repositories...
v Set connection to GitHub.

# Set GitLab host with particular repos vector instead of orgs

Code
set_gitlab_host(test_gitstats, token = Sys.getenv("GITLAB_PAT_PUBLIC"), repos = c(
"mbtests/gitstatstesting", "mbtests/gitstats-testing-2"))
Message
> Checking repositories...
v Set connection to GitLab.

# When no organizations or repositories are set information is printed

Code
set_github_host(test_gitstats, token = Sys.getenv("GITHUB_PAT"), verbose = TRUE)
Message
i No `orgs` nor `repos` specified.
i Searching scope set to [all].
v Set connection to GitHub.

# Error shows, when wrong input is passed when setting connection and host is not passed

x Token exists but does not grant access.
Expand All @@ -73,17 +6,7 @@

# Error pops out, when two clients of the same url api are passed as input

Code
set_github_host(set_github_host(test_gitstats, token = Sys.getenv("GITHUB_PAT"),
orgs = "pharmaverse"), token = Sys.getenv("GITHUB_PAT"), orgs = "openpharma")
Message
> Checking owners...
v Set connection to GitHub.
> Checking owners...
v Set connection to GitHub.
Condition
Error:
x You can not provide two hosts of the same API urls.
x You can not provide two hosts of the same API urls.

# Error pops out when `org` does not exist

Expand Down Expand Up @@ -127,18 +50,3 @@
x Org/user you provided does not exist or its name was passed in a wrong way: r_world_devs
! Please type your org/user name the way you see it in web URL.

# When wrong orgs and repos are passed they are excluded but host is created

Code
test_gitstats <- set_github_host(create_gitstats(), orgs = c("openpharma",
"r_world_devs"), repos = c("r-world-devs/GitStats", "r-world-devs/GitMetrics"),
verbose = TRUE, .error = FALSE)
Message
i Using PAT from GITHUB_PAT envar.
> Checking owners...
! Org/user you provided does not exist: r_world_devs
> Checking repositories...
x HTTP 404 Not Found.
! Repository you provided does not exist: https://api.github.com/repos/r-world-devs/GitMetrics
v Set connection to GitHub.

112 changes: 52 additions & 60 deletions tests/testthat/test-set_host.R
Original file line number Diff line number Diff line change
@@ -1,58 +1,53 @@
test_gitstats <- create_gitstats()

test_that("Set connection returns appropriate messages", {
test_that("Set connection works as expected", {
if (!integration_tests_skipped) {
expect_snapshot(
test_gitstats |>
set_github_host(
gitstats = test_gitstats,
token = Sys.getenv("GITHUB_PAT"),
orgs = c("openpharma", "r-world-devs")
)
expect_equal(
unlist(test_gitstats$.__enclos_env__$private$hosts[[1]]$.__enclos_env__$private$orgs),
c("openpharma", "r-world-devs")
)
expect_snapshot(
test_gitstats |> set_gitlab_host(
test_gitstats |>
set_gitlab_host(
token = Sys.getenv("GITLAB_PAT_PUBLIC"),
orgs = c("mbtests")
)
expect_equal(
unlist(test_gitstats$.__enclos_env__$private$hosts[[2]]$.__enclos_env__$private$orgs),
c("mbtests")
)
}
})

test_that("When empty token for GitHub, GitStats pulls default token", {
skip_on_cran()
test_that("When empty token for GitLab, GitStats pulls default token", {
if (!integration_tests_skipped) {
expect_snapshot(
withr::with_envvar(new = c("GITLAB_PAT" = Sys.getenv("GITLAB_PAT_PUBLIC")), {
test_gitstats <- create_gitstats() |>
set_github_host(
orgs = c("openpharma", "r-world-devs")
set_gitlab_host(
orgs = "mbtests",
verbose = FALSE
)
)
}
})

test_that("When empty token for GitLab, GitStats pulls default token", {
if (!integration_tests_skipped) {
expect_snapshot(
withr::with_envvar(new = c("GITLAB_PAT" = Sys.getenv("GITLAB_PAT_PUBLIC")), {
test_gitstats <- create_gitstats() |>
set_gitlab_host(
orgs = "mbtests"
)
})
)
expect_equal(
test_gitstats$.__enclos_env__$private$hosts[[1]]$.__enclos_env__$private$token,
Sys.getenv("GITLAB_PAT_PUBLIC")
)
})
}
})

test_that("Set GitHub host with particular repos vector instead of orgs", {
if (!integration_tests_skipped) {
test_gitstats <- create_gitstats()
expect_snapshot(
test_gitstats |>
set_github_host(
token = Sys.getenv("GITHUB_PAT"),
repos = c("r-world-devs/GitStats", "r-world-devs/shinyCohortBuilder", "openpharma/GithubMetrics", "openpharma/DataFakeR")
)
)
test_gitstats |>
set_github_host(
token = Sys.getenv("GITHUB_PAT"),
repos = c("r-world-devs/GitStats", "r-world-devs/shinyCohortBuilder", "openpharma/GithubMetrics", "openpharma/DataFakeR"),
verbose = FALSE
)
expect_length(
test_gitstats$.__enclos_env__$private$hosts,
1
Expand All @@ -63,32 +58,19 @@ test_that("Set GitHub host with particular repos vector instead of orgs", {
test_that("Set GitLab host with particular repos vector instead of orgs", {
if (!integration_tests_skipped) {
test_gitstats <- create_gitstats()
expect_snapshot(
test_gitstats |>
set_gitlab_host(
token = Sys.getenv("GITLAB_PAT_PUBLIC"),
repos = c("mbtests/gitstatstesting", "mbtests/gitstats-testing-2")
)
)
test_gitstats |>
set_gitlab_host(
token = Sys.getenv("GITLAB_PAT_PUBLIC"),
repos = c("mbtests/gitstatstesting", "mbtests/gitstats-testing-2"),
verbose = FALSE
)
expect_length(
test_gitstats$.__enclos_env__$private$hosts,
1
)
}
})

test_that("When no organizations or repositories are set information is printed", {
skip_on_cran()
test_gitstats <- create_gitstats()
expect_snapshot(
test_gitstats |>
set_github_host(
token = Sys.getenv("GITHUB_PAT"),
verbose = TRUE
)
)
})

test_that("Error shows, when wrong input is passed when setting connection and host is not passed", {
if (!integration_tests_skipped) {
test_gitstats <- create_gitstats()
Expand All @@ -114,8 +96,7 @@ test_that("Error shows, when wrong input is passed when setting connection and h
test_that("Error pops out, when two clients of the same url api are passed as input", {
if (!integration_tests_skipped) {
test_gitstats <- create_gitstats()
expect_snapshot(
error = TRUE,
expect_snapshot_error(
test_gitstats |>
set_github_host(
token = Sys.getenv("GITHUB_PAT"),
Expand Down Expand Up @@ -165,14 +146,25 @@ test_that("Error pops out when `org` does not exist", {

test_that("When wrong orgs and repos are passed they are excluded but host is created", {
if (!integration_tests_skipped) {
expect_snapshot(
test_gitstats <- create_gitstats() |>
set_github_host(
orgs = c("openpharma", "r_world_devs"),
repos = c("r-world-devs/GitStats", "r-world-devs/GitMetrics"),
verbose = TRUE,
.error = FALSE
)
test_gitstats <- create_gitstats() |>
set_github_host(
orgs = c("openpharma", "r_world_devs"),
repos = c("r-world-devs/GitStats", "r-world-devs/GitMetrics"),
verbose = TRUE,
.error = FALSE
)

expect_length(
test_gitstats$.__enclos_env__$private$hosts,
1
)
expect_equal(
unlist(test_gitstats$.__enclos_env__$private$hosts[[1]]$.__enclos_env__$private$orgs),
"openpharma"
)
expect_equal(
unlist(test_gitstats$.__enclos_env__$private$hosts[[1]]$.__enclos_env__$private$repos),
"GitStats"
)
}
})
Expand Down
Loading