Skip to content
Open
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
8b18758
adding check for api access and git fallback
dgkf Apr 30, 2021
5985ecd
always try gitlab_remote when !git_fallback
dgkf Apr 30, 2021
8bed1e4
adding error handling for http requests during remote_package_name.gi…
dgkf Jun 15, 2021
8be0803
update NEWS; bump dev version
dgkf Jun 16, 2021
0160e2c
update NEWS
dgkf Jun 16, 2021
a914a74
breaking out dev note
dgkf Jun 22, 2021
17c49bc
Merge branch 'master' into 625-git-remote-http
jimhester Jun 23, 2021
e79a8b5
updating inst/ content; minor whitespace fix
dgkf Jun 24, 2021
3fdd93f
Merge branch 'master' of github.com:r-lib/remotes into dev/gitlab-git…
dgkf Jun 24, 2021
37d359b
Merge branch '625-git-remote-http' of github.com:dgkf/remotes into de…
dgkf Jun 24, 2021
b0d69b8
simplifying git fallback
dgkf Jun 24, 2021
1b8e961
adding more helpful fallback messages
dgkf Jun 24, 2021
795b46a
adding more helpful fallback messages
dgkf Jun 24, 2021
00fc529
adding wrap helper function
dgkf Jun 24, 2021
ab20096
breaking out git fallback into separate remote constructor
dgkf Jun 25, 2021
915c08c
fixing undef var
dgkf Jun 25, 2021
d9ca73a
handling sha/ref reconcilliation
dgkf Jun 25, 2021
8b9911f
adding parsing for username:password in git url
dgkf Jun 25, 2021
409ea84
censoring password in git command message
dgkf Jun 25, 2021
f6af232
actually censoring messages in git output
dgkf Jun 25, 2021
4f49ce0
enabling censored clone output
dgkf Jun 25, 2021
e90a52c
adding tests
dgkf Jun 25, 2021
b477334
improving documentation of new behavios
dgkf Jun 25, 2021
4021939
adding tests; docs
dgkf Jun 26, 2021
8b68875
Merge branch 'master' into dev/gitlab-git-api-fallback-2
dgkf Jul 9, 2021
d7d8709
updating NEWS
dgkf Jul 9, 2021
37e177b
updating DESCRIPTION; tests
dgkf Jul 10, 2021
a6d1ae0
rerunning make
dgkf Jul 10, 2021
68980b2
using atomic return instead of function for mocks
dgkf Jul 10, 2021
1917f02
fixing stubbing at depth into fn; yo dawg i heard you like mocks
dgkf Jul 10, 2021
18e0b37
Merge branch 'master' into dev/gitlab-git-api-fallback
jimhester Sep 24, 2021
aa6f2a2
Merge branch 'master' into dev/gitlab-git-api-fallback
jimhester Sep 27, 2021
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
Prev Previous commit
Next Next commit
adding more helpful fallback messages
  • Loading branch information
dgkf committed Jun 24, 2021
commit 795b46ab4210dc2be4523f9bc81acf29ac9538d9
87 changes: 52 additions & 35 deletions R/install-gitlab.R
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ gitlab_remote <- function(repo, subdir = NULL,
auth_token = gitlab_pat(), sha = NULL,
host = "gitlab.com", ...,
git_fallback = getOption("remotes.gitlab_git_fallback", TRUE),
credentials = NULL,
quiet = FALSE) {

meta <- parse_git_repo(repo)
Expand All @@ -73,53 +74,69 @@ gitlab_remote <- function(repo, subdir = NULL,
url <- paste0(build_url(host, repo), ".git")
url_has_token <- grepl("^(.*://)?[^@/]+@", url)
has_access_token <- !is.null(auth_token) && nchar(auth_token) > 0L
has_credentials <- !is.null(list(...)$credentials)
has_credentials <- !is.null(credentials)
use_git2r <- !is_standalone() && pkg_installed("git2r")

if (!quiet) {
message(wrap(exdent = 2L, paste0("auth_token does not have scopes ",
"'read-repository' and 'api' for host '", host, "' required to ",
"install using gitlab_remote.")))
}

# for basic http auth,
# - in GitLab CI using job account, username must be "gitlab-ci-token"
# - for Project Access Tokens, username must be "<project-name>"
# - for Personal Acccess Tokens, username is ignored
# choose to use "gitlab-ci-token" for most general default behavior
# https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html
if (has_access_token && !url_has_token && !has_credentials) {
# for basic http auth,
# - in GitLab CI using job account, username must be "gitlab-ci-token"
# - for Project Access Tokens, username must be "<project-name>"
# - for Personal Acccess Tokens, username is ignored
# choose to use "gitlab-ci-token" for most general default behavior
# https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html
url_protocol <- gsub("((.*)://)?.*", "\\1", url)
url_path <- gsub("((.*)://)?", "", url)

if (!quiet) {
message("auth_token does not have scopes 'read-repository' and 'api' ",
"for host '", host, "' required to install using gitlab_remote.\n",
"Attempting git_remote using ",
sprintf("url=%sgitlab-ci-token:<auth_token>@%s", url_protocol, url_path))
if (use_git2r) {
credentials <- getExportedValue("git2r", "cred_user_pass")(
username = "gitlab-ci-token",
password = auth_token
)

if (!quiet) {
message(wrap(exdent = 2L, paste0("Attempting git_remote using ",
"credentials: username='gitlab-ci-token', password=<auth_token>")))
}

} else {
url_protocol <- gsub("((.*)://)?.*", "\\1", url)
url_path <- gsub("((.*)://)?", "", url)

if (!quiet) {
message(wrap(exdent = 2L, paste0("Attempting git_remote using ",
sprintf("url=%sgitlab-ci-token:<auth_token>@%s", url_protocol, url_path))))
}

url <- paste0(url_protocol, "gitlab-ci-token:", auth_token, "@", url_path)
}

url <- paste0(url_protocol, "gitlab-ci-token:", auth_token, "@", url_path)
} else if (has_credentials && !quiet) {
message("auth_token does not have scopes 'read-repository' and 'api' ",
"for host '", host, "' required to install using gitlab_remote.\n",
"Attempting git_remote using provided credentials for authentication.")
message(wrap(exdent = 2L, paste0("Attempting git_remote using provided ",
"credentials for authentication.")))
} else if (!quiet) {
message("auth_token does not have scopes 'read-repository' and 'api' ",
"for host '", host, "' required to install using gitlab_remote.\n",
"Attempting using git_remote.")
message(wrap(exdent = 2L, "Attempting using git_remote."))
}

git_remote(
return(git_remote(
url = url,
subdir = subdir,
ref = sha %||% meta$ref,
credentials = credentials,
...
)
} else {
remote("gitlab",
host = host,
repo = paste(c(meta$repo, meta$subdir), collapse = "/"),
subdir = subdir,
username = meta$username,
ref = meta$ref,
sha = sha,
auth_token = auth_token
)
))
}

remote("gitlab",
host = host,
repo = paste(c(meta$repo, meta$subdir), collapse = "/"),
subdir = subdir,
username = meta$username,
ref = meta$ref,
sha = sha,
auth_token = auth_token
)
}

#' @export
Expand Down