From 2cf59e42f50345bab5fc15ca8b8c4b54519e1c1e Mon Sep 17 00:00:00 2001 From: MurielleDelmotte Date: Mon, 5 Aug 2024 15:06:58 +0000 Subject: [PATCH 1/2] feat: complete extract_pkg_info with RemoteRef (branch) - to add the name branch in remote return by set_remote_desc() - refacto : add complete_remote_branch - complete test (gitlab, github, git using branch) Issue #113 --- NAMESPACE | 1 + R/set_remotes.R | 54 ++++++++++++++++++++++++++++--- man/complete_remote_branch.Rd | 23 +++++++++++++ tests/testthat/test-set-remotes.R | 40 +++++++++++++++++++++++ 4 files changed, 113 insertions(+), 5 deletions(-) create mode 100644 man/complete_remote_branch.Rd diff --git a/NAMESPACE b/NAMESPACE index 9dd7c62..c6cf68e 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -15,6 +15,7 @@ export(att_from_rscripts) export(att_to_desc_from_is) export(att_to_desc_from_pkg) export(att_to_description) +export(complete_remote_branch) export(create_dependencies_file) export(create_renv_for_dev) export(create_renv_for_prod) diff --git a/R/set_remotes.R b/R/set_remotes.R index 82fb771..dfa2234 100644 --- a/R/set_remotes.R +++ b/R/set_remotes.R @@ -179,16 +179,35 @@ extract_pkg_info <- function(pkgdesc) { # paste0("universe::", gsub(".r-universe.dev", "", desc[["Repository"]]), "/", desc[["Package"]]) setNames(NA, paste0("r-universe: need to set options to repos=\"", desc[["Repository"]], "\"")) } else if (!is.null(desc$RemoteType) && desc$RemoteType == "github") { - paste(desc$RemoteUsername, desc$RemoteRepo, sep = "/") + + attachment::complete_remote_branch( + remote = paste(desc$RemoteUsername, desc$RemoteRepo, sep = "/"), + remoteref = desc$RemoteRef + ) + } else if (!is.null(desc$RemoteType) && desc$RemoteType %in% c("gitlab", "bitbucket")) { - paste0(desc$RemoteType, "::", - paste(desc$RemoteUsername, desc$RemoteRepo, sep = "/")) + + attachment::complete_remote_branch(remote = paste0( + desc$RemoteType, + "::", + paste(desc$RemoteUsername, desc$RemoteRepo, sep = "/") + ), + remoteref = desc$RemoteRef) + } else if (!is.null(desc$RemoteType) && desc$RemoteType == "local" && !is.null(desc$RemoteUrl) && is.null(desc$RemoteHost)) { - paste0(desc$RemoteType, "::", desc$RemoteUrl) + + attachment::complete_remote_branch( + remote = paste0(desc$RemoteType, "::", desc$RemoteUrl), + remoteref = desc$RemoteRef + ) + } else if (!is.null(desc$RemoteType) && !(desc$RemoteType %in% c("github","gitlab","bitbucket","local")) && grepl("git",x = desc$RemoteType) ){ - paste0("git::",desc$RemoteUrl) + + attachment::complete_remote_branch(remote = paste0("git::", desc$RemoteUrl), + remoteref = desc$RemoteRef) + } else if (is.null(desc$RemoteType) && isTRUE(grepl("bioconductor",x = desc$URL))) { biocversion <- desc$git_branch %>% gsub(pattern = "RELEASE_", replacement = "") %>% @@ -204,6 +223,31 @@ extract_pkg_info <- function(pkgdesc) { setNames(pkg_not_cran) } guess_repo + } +#' Construct a Remote Branch Reference String +#' +#' This function constructs a reference string for a remote branch in a version control system like Git. +#' It returns a formatted string combining the remote name and a specified branch or reference. +#' +#' @param remote A character string representing the name of the remote repository (e.g., `"origin"`). +#' @param remoteref A character string representing the branch or reference within the remote repository. +#' Default is `"HEAD"`. +#' +#' @return A character string. If `remoteref` is `"HEAD"`, it returns just the `remote` string. If +#' `remoteref` is not `"HEAD"`, it returns a string in the format `"remote@remoteref"`. +#' @keywords internal +#' @export +complete_remote_branch <- function(remote, remoteref = "HEAD"){ + + if (isTRUE(remoteref != "HEAD")) { + return( + paste(remote, remoteref, sep = "@") + ) + } else { + return(remote) + } + +} diff --git a/man/complete_remote_branch.Rd b/man/complete_remote_branch.Rd new file mode 100644 index 0000000..84c8248 --- /dev/null +++ b/man/complete_remote_branch.Rd @@ -0,0 +1,23 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/set_remotes.R +\name{complete_remote_branch} +\alias{complete_remote_branch} +\title{Construct a Remote Branch Reference String} +\usage{ +complete_remote_branch(remote, remoteref = "HEAD") +} +\arguments{ +\item{remote}{A character string representing the name of the remote repository (e.g., \code{"origin"}).} + +\item{remoteref}{A character string representing the branch or reference within the remote repository. +Default is \code{"HEAD"}.} +} +\value{ +A character string. If \code{remoteref} is \code{"HEAD"}, it returns just the \code{remote} string. If +\code{remoteref} is not \code{"HEAD"}, it returns a string in the format \code{"remote@remoteref"}. +} +\description{ +This function constructs a reference string for a remote branch in a version control system like Git. +It returns a formatted string combining the remote name and a specified branch or reference. +} +\keyword{internal} diff --git a/tests/testthat/test-set-remotes.R b/tests/testthat/test-set-remotes.R index 6007a6c..9353dd8 100644 --- a/tests/testthat/test-set-remotes.R +++ b/tests/testthat/test-set-remotes.R @@ -62,6 +62,7 @@ test_that("extract_pkg_info extracts code", { c("r-universe: need to set options to repos=\"https://thinkr-open.r-universe.dev\"" = NA)) #"universe::thinkr-open/fusen" + # R-universe from repos changed fake_desc_universe2 <- list( list( @@ -89,6 +90,18 @@ test_that("extract_pkg_info extracts code", { ) %>% setNames("fusen") expect_equal(extract_pkg_info(fake_desc_github)[["fusen"]], "ThinkR-open/fusen") + # Github with branch + fake_desc_github_with_branch <- list( + list( + RemoteType = "github", + RemoteHost = "api.github.com", + RemoteRepo = "fusen", + RemoteUsername = "ThinkR-open", + RemoteRef = "branchdev" + ) + ) %>% setNames("fusen") + expect_equal(extract_pkg_info(fake_desc_github_with_branch)[["fusen"]], "ThinkR-open/fusen@branchdev") + # GitLab fake_desc_gitlab <- list( list( @@ -100,6 +113,20 @@ test_that("extract_pkg_info extracts code", { ) %>% setNames("fakepkg") expect_equal(extract_pkg_info(fake_desc_gitlab)[["fakepkg"]], "gitlab::statnmap/fakepkg") + + # GitLab with branch + fake_desc_gitlab_with_branch <- list( + list( + RemoteType = "gitlab", + RemoteHost = "gitlab.com", + RemoteRepo = "fakepkg", + RemoteRef = "fakebranch", + RemoteUsername = "statnmap" + ) + ) %>% setNames("fakepkg") + expect_equal(extract_pkg_info(fake_desc_gitlab_with_branch)[["fakepkg"]], "gitlab::statnmap/fakepkg@fakebranch") + + # Git fake_desc_git <- list( list( @@ -119,6 +146,19 @@ test_that("extract_pkg_info extracts code", { ) %>% setNames("fakepkggit2r") expect_equal(extract_pkg_info(fake_desc_git2r)[["fakepkggit2r"]], "git::https://MyForge.com/fakepkggit2r") + # Git with branch + fake_desc_git2r_with_branch <- list( + list( + RemoteType = "git2r", + RemoteUrl = "https://MyForge.com/fakepkggit2r", + RemoteRepo = NULL, + RemoteRef = "fakepkgbranch", + RemoteUsername = NULL + ) + ) %>% setNames("fakepkggit2r") + expect_equal(extract_pkg_info(fake_desc_git2r_with_branch)[["fakepkggit2r"]], "git::https://MyForge.com/fakepkggit2r@fakepkgbranch") + + # Bioconductor fake_desc_bioc <- list( list( From d7289db9cfcb9ccf601ed37787ad779c81774811 Mon Sep 17 00:00:00 2001 From: MurielleDelmotte Date: Mon, 5 Aug 2024 15:08:43 +0000 Subject: [PATCH 2/2] chore : bump version v0.4.2.9002 Issue #113 --- DESCRIPTION | 2 +- NEWS.md | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index d5dfdc7..efb7977 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: attachment Title: Deal with Dependencies -Version: 0.4.2.9001 +Version: 0.4.2.9002 Authors@R: c( person("Sébastien", "Rochette", , "sebastien@thinkr.fr", role = c("cre", "aut"), comment = c(ORCID = "0000-0002-1565-9313")), diff --git a/NEWS.md b/NEWS.md index 466a4c6..601ed88 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,6 +5,7 @@ - Add `att_from_examples()` to get all packages called in examples from R files - Add `att_from_data()` to look for functions called in data loading code - `att_amend_desc` amend package DESCRIPTION file (Suggests) with the list of dependencies extracted from examples in R files. +- `set_remotes_to_desc()` takes into account the branch ## Patch