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

Extract pkg info branch #119

Merged
merged 2 commits into from
Aug 5, 2024
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: attachment
Title: Deal with Dependencies
Version: 0.4.2.9001
Version: 0.4.2.9002
Authors@R: c(
person("Sébastien", "Rochette", , "[email protected]", role = c("cre", "aut"),
comment = c(ORCID = "0000-0002-1565-9313")),
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
54 changes: 49 additions & 5 deletions R/set_remotes.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "") %>%
Expand All @@ -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)
}

}
23 changes: 23 additions & 0 deletions man/complete_remote_branch.Rd

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

40 changes: 40 additions & 0 deletions tests/testthat/test-set-remotes.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand Down
Loading