Skip to content

Commit

Permalink
GitLab basics W.I.P.
Browse files Browse the repository at this point in the history
  • Loading branch information
ErdaradunGaztea committed Oct 14, 2023
1 parent 45b6b31 commit ee5ecc7
Show file tree
Hide file tree
Showing 16 changed files with 127 additions and 1 deletion.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export(wood_github_latest)
export(wood_github_packages)
export(wood_github_tags)
export(wood_github_versions)
export(wood_gitlab_latest)
export(wood_local_dependencies)
export(wood_local_packages)
export(wood_local_versions)
Expand Down
52 changes: 52 additions & 0 deletions R/gitlab-latest.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#' Get current package version on GitLab
#'
#' @description This function queries GitLab for the code of the current package
#' version. This may reference a non-tagged commit; for the analysis of tagged
#' commits only, see [wood_gitlab_versions()].
#'
#' @template package
#' @template git-user
#'
#' @return A character vector of version codes.
#'
#' @examples
#' \donttest{
#' # Latest version code is returned
#' wood_gitlab_latest("rock", "r-packages")
#'
#' # To get the latest *tagged* version code instead, use:
#' codes <- wood_gitlab_versions("rock", "r-packages")
#' versionsort::ver_latest(codes)
#' }
#'
#' @family gitlab
#' @family versions
#' @export
wood_gitlab_latest <- function(package, user) {
assert_param_package(package)
assert_param_git_user(user)

desc <- gitlab_description_cache(package, user, "latest")
read_dcf_one_value(desc, "Version")
}

gitlab_description_cache <- function(package, user, tag) {
if (tag == "latest") {
ret <- with_cache({
content <- guess_default_branch(user, package, "DESCRIPTION")
list(exists = TRUE, content = content)
}, "DESCRIPTION", "github", user, package)
ret[["content"]]
} else {
# with_cache({
# url <- raw_github_url(user, package, tag, "DESCRIPTION")
# content <- download_safely(url, on_status = list(
# `403` = stopf_gh_rate_limit,
# `404` = function() stopf(c(
# "Can't find DESCRIPTION file in `%1$s/%2$s` repository on Github.\n",
# "(i) Is `%3$s` a valid tag?"
# ), user, package, tag)
# ))
# }, "DESCRIPTION", "github", user, package, tag)
}
}
5 changes: 5 additions & 0 deletions R/gitlab-utils.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
guess_default_branch_gl <- function(user, package, ...) {
guess_default_branch(
"gitlab", user, package, ..., branches = c("master", "main", "dev", "prod")
)
}
6 changes: 6 additions & 0 deletions R/utils-url.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@ github_url <- function(..., params = list()) {
append_url_params(paste("https://api.github.com", ..., sep = "/"), params)
}

gitlab_url <- function(..., params = list()) {
append_url_params(paste("https://gitlab.com", ..., sep = "/"), params)
}

# "https://gitlab.com/api/v4"

#' Get Bioconductor URL
#'
#' @description Creates an URL to the selected Bioconductor API.
Expand Down
1 change: 1 addition & 0 deletions man/wood_bioc_version.Rd

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

1 change: 1 addition & 0 deletions man/wood_core_version.Rd

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

1 change: 1 addition & 0 deletions man/wood_cran_latest.Rd

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

1 change: 1 addition & 0 deletions man/wood_cran_versions.Rd

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

3 changes: 2 additions & 1 deletion man/wood_github_latest.Rd

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

1 change: 1 addition & 0 deletions man/wood_github_versions.Rd

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

49 changes: 49 additions & 0 deletions man/wood_gitlab_latest.Rd

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

1 change: 1 addition & 0 deletions man/wood_local_versions.Rd

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

1 change: 1 addition & 0 deletions man/wood_runiverse_version.Rd

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

1 change: 1 addition & 0 deletions man/wood_url_version.Rd

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

1 change: 1 addition & 0 deletions man/wood_versions.Rd

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

3 changes: 3 additions & 0 deletions tests/testthat/test-gitlab-latest.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test_that("multiplication works", {
expect_equal(2 * 2, 4)
})

0 comments on commit ee5ecc7

Please sign in to comment.