Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add possibility to pass host with http. #513

Merged
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: Get Statistics from GitHub and GitLab
Version: 2.1.0.9006
Version: 2.1.0.9007
Authors@R: c(
person(given = "Maciej", family = "Banas", email = "[email protected]", role = c("aut", "cre")),
person(given = "Kamil", family = "Koziej", email = "[email protected]", role = "aut"),
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- Fixed getting large search responses for GitHub ([#491](https://github.com/r-world-devs/GitStats/issues/491)).
- Fixed checking token scopes ([#501](https://github.com/r-world-devs/GitStats/issues/501)). If token scopes are insufficient error is returned and `GitHost` is not passed to `GitStats`. This also applies to situation when `GitStats` looks for default tokens (not defined by user). Earlier, if tests for token failed, an empty token was passed and `GitStats` was created, which was misleading for the user.
- User can now optionally pass public GitHub host name (`github.com` or `https://github.com`) to `set_github_host()` ([#475](https://github.com/r-world-devs/GitStats/issues/475)).
- It is possible to pass hosts in more flexible way than before (e.g. `{host_url}`, `http://{host_url}` or `https://{host_url}`) to `host` parameter in `set_*_host() function ([#399](https://github.com/r-world-devs/GitStats/issues/399)).

# GitStats 2.1.0

Expand Down
5 changes: 4 additions & 1 deletion R/GitHost.R
Original file line number Diff line number Diff line change
Expand Up @@ -297,11 +297,14 @@ GitHost <- R6::R6Class(

# Set API url
set_custom_api_url = function(host) {
private$api_url <- if (!grepl("https://", host)) {
private$api_url <- if (!grepl("https|http", host)) {
glue::glue(
"https://{host}/api/v{private$api_version}"
)
} else {
if (grepl("http(?!s)", host, perl = TRUE)) {
host <- gsub("http", "https", host)
}
glue::glue(
"{host}/api/v{private$api_version}"
)
Expand Down
1 change: 1 addition & 0 deletions R/GitHostGitHub.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ GitHostGitHub <- R6::R6Class(
set_api_url = function(host) {
if (is.null(host) ||
host == "https://github.com" ||
host == "http://github.com" ||
host == "github.com") {
private$api_url <- "https://api.github.com"
} else {
Expand Down
20 changes: 19 additions & 1 deletion tests/testthat/test-GitHost-helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ test_that("set_owner_types sets attributes to owners list", {
expect_equal(owner[[1]], "test_org", ignore_attr = TRUE)
})

test_that("set_api_url works for public hosts", {
test_that("set_api_url works", {
expect_equal({
github_testhost_priv$set_api_url(
host = "github.com"
Expand All @@ -33,6 +33,11 @@ test_that("set_api_url works for public hosts", {
host = "https://github.com"
)
}, "https://api.github.com")
expect_equal({
github_testhost_priv$set_api_url(
host = "http://github.com"
)
}, "https://api.github.com")
expect_equal({
github_testhost_priv$set_api_url(
host = "https://github.company.com"
Expand All @@ -49,3 +54,16 @@ test_that("set_api_url works for public hosts", {
)
}, "https://gitlab.com/api/v4")
})

test_that("set_custom_api_url works", {
expect_equal({
gitlab_testhost_priv$set_custom_api_url(
host = "http://gitlab.com"
)
}, "https://gitlab.com/api/v4")
expect_equal({
github_testhost_priv$set_custom_api_url(
host = "http://github.company.com"
)
}, "https://github.company.com/api/v3")
})
Loading