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

respect auth_token=NULL when used in install_github() #819

Merged
merged 5 commits into from
Jan 9, 2025
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
4 changes: 2 additions & 2 deletions R/install-github.R
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ remote_package_name.github_remote <- function(remote, ..., use_local = TRUE,
# Otherwise lookup the package name from the remote DESCRIPTION file
desc <- github_DESCRIPTION(username = remote$username, repo = remote$repo,
subdir = remote$subdir, host = remote$host, ref = remote$ref,
pat = remote$auth_token %||% github_pat(), use_curl = use_curl)
pat = remote$auth_token, use_curl = use_curl)

if (is.null(desc)) {
return(NA_character_)
Expand All @@ -260,7 +260,7 @@ remote_package_name.github_remote <- function(remote, ..., use_local = TRUE,
remote_sha.github_remote <- function(remote, ..., use_curl = !is_standalone() && pkg_installed("curl")) {
tryCatch(
github_commit(username = remote$username, repo = remote$repo,
host = remote$host, ref = remote$ref, pat = remote$auth_token %||% github_pat(), use_curl = use_curl),
host = remote$host, ref = remote$ref, pat = remote$auth_token, use_curl = use_curl),

# 422 errors most often occur when a branch or PR has been deleted, so we
# ignore the error in this case
Expand Down
4 changes: 2 additions & 2 deletions inst/install-github.R

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions install-github.R

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 50 additions & 0 deletions tests/testthat/test-install-github.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,11 @@ test_that("github_resolve_ref.github_release", {
skip_on_cran()
skip_if_offline()
skip_if_over_rate_limit()
# skip in GHA PRs, no token
if (Sys.getenv("GITHUB_ACTIONS") == "true" &&
startsWith(Sys.getenv("GITHUB_REF"), "refs/pull")) {
skip("GHA pull request, no token")
}

expect_error(
github_resolve_ref.github_release(
Expand Down Expand Up @@ -38,6 +43,11 @@ test_that("github_resolve_ref.github_release", {
skip_on_cran()
skip_if_offline()
skip_if_over_rate_limit()
# skip in GHA PRs, no token
if (Sys.getenv("GITHUB_ACTIONS") == "true" &&
startsWith(Sys.getenv("GITHUB_REF"), "refs/pull")) {
skip("GHA pull request, no token")
}

expect_error(
github_resolve_ref(
Expand All @@ -54,6 +64,11 @@ test_that("github_release", {
skip_on_cran()
skip_if_offline()
skip_if_over_rate_limit()
# skip in GHA PRs, no token
if (Sys.getenv("GITHUB_ACTIONS") == "true" &&
startsWith(Sys.getenv("GITHUB_REF"), "refs/pull")) {
skip("GHA pull request, no token")
}

Sys.unsetenv("R_TESTS")

Expand All @@ -79,6 +94,11 @@ test_that("install_github", {
skip_on_cran()
skip_if_offline()
skip_if_over_rate_limit()
# skip in GHA PRs, no token
if (Sys.getenv("GITHUB_ACTIONS") == "true" &&
startsWith(Sys.getenv("GITHUB_REF"), "refs/pull")) {
skip("GHA pull request, no token")
}

Sys.unsetenv("R_TESTS")

Expand Down Expand Up @@ -110,6 +130,11 @@ test_that("error if not username, warning if given as argument", {
skip_on_cran()
skip_if_offline()
skip_if_over_rate_limit()
# skip in GHA PRs, no token
if (Sys.getenv("GITHUB_ACTIONS") == "true" &&
startsWith(Sys.getenv("GITHUB_REF"), "refs/pull")) {
skip("GHA pull request, no token")
}

Sys.unsetenv("R_TESTS")

Expand Down Expand Up @@ -153,6 +178,11 @@ test_that("remote_sha.github_remote", {
skip_on_cran()
skip_if_offline()
skip_if_over_rate_limit()
# skip in GHA PRs, no token
if (Sys.getenv("GITHUB_ACTIONS") == "true" &&
startsWith(Sys.getenv("GITHUB_REF"), "refs/pull")) {
skip("GHA pull request, no token")
}

expect_equal(
remote_sha.github_remote(
Expand All @@ -176,6 +206,11 @@ test_that("github_remote with deleted branch", {
# skip this test unless we are using curl
skip_if(is_standalone() || !pkg_installed("curl"))

# skip in GHA PRs, no token
if (Sys.getenv("GITHUB_ACTIONS") == "true" &&
startsWith(Sys.getenv("GITHUB_REF"), "refs/pull")) {
skip("GHA pull request, no token")
}

expect_equal(
remote_sha.github_remote(
Expand All @@ -198,6 +233,11 @@ test_that("github_pull", {
skip_on_cran()
skip_if_offline()
skip_if_over_rate_limit()
# skip in GHA PRs, no token
if (Sys.getenv("GITHUB_ACTIONS") == "true" &&
startsWith(Sys.getenv("GITHUB_REF"), "refs/pull")) {
skip("GHA pull request, no token")
}

Sys.unsetenv("R_TESTS")

Expand All @@ -222,6 +262,11 @@ test_that("remote_sha.github_remote errors if remote doesn't exist", {
skip_on_cran()
skip_if_offline()
skip_if_over_rate_limit()
# skip in GHA PRs, no token
if (Sys.getenv("GITHUB_ACTIONS") == "true" &&
startsWith(Sys.getenv("GITHUB_REF"), "refs/pull")) {
skip("GHA pull request, no token")
}

expect_error(remote_sha(github_remote("arst/arst")))
})
Expand All @@ -230,6 +275,11 @@ test_that("remote_sha.github_remote returns expected value if remote does exist"
skip_on_cran()
skip_if_offline()
skip_if_over_rate_limit()
# skip in GHA PRs, no token
if (Sys.getenv("GITHUB_ACTIONS") == "true" &&
startsWith(Sys.getenv("GITHUB_REF"), "refs/pull")) {
skip("GHA pull request, no token")
}

expect_equal(remote_sha(github_remote("r-lib/[email protected]")), "ad9aac7b9a522354e1ff363a86f389e32cec181b")
})
Loading