Skip to content

Commit

Permalink
add 'get_subdir_from_url' fn for #64
Browse files Browse the repository at this point in the history
  • Loading branch information
mpadge committed Nov 11, 2024
1 parent 8545fae commit 60bc201
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 4 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: roreviewapi
Title: Plumber API to report package structure and function
Version: 0.1.0.060
Version: 0.1.0.061
Authors@R:
person("Mark", "Padgham", , "[email protected]", role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-2172-5265"))
Expand Down
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export(collate_editor_check)
export(dl_gh_repo)
export(editor_check)
export(get_branch_from_url)
export(get_subdir_from_url)
export(is_user_authorized)
export(pkgrep_install_deps)
export(post_to_issue)
Expand Down
24 changes: 23 additions & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ authorized_users <- c (
)

#' Get branch from a GitHub URL if non-default branch specified there
#' @param repourl Potentially with "/tree/branch_name" appended
#' @param repourl Potentially with "/tree/branch_name/sub-directory" appended
#' @return Branch as single string.
#' @family github
#' @export
Expand All @@ -80,10 +80,32 @@ get_branch_from_url <- function (repourl) {
if (length (domains) > 4L & any (domains == "tree")) {
i <- which (domains == "tree")
branch <- domains [which (domains == "tree") + 1L]
if (branch %in% c ("main", "master") && length (domains) > (i + 1)) {
# URL has branch only as prefix to sub-directory
branch <- NULL

Check warning on line 85 in R/utils.R

View check run for this annotation

Codecov / codecov/patch

R/utils.R#L85

Added line #L85 was not covered by tests
}
}
return (branch)
}

#' Return sub-directory from URL if present. This function is also intended to
#' test whether packages are in sub-directories (issue #64)
#'
#' @inheritParams get_branch_from_url
#' @export
get_subdir_from_url <- function (reporul) {

subdir <- NULL
domains <- strsplit (repourl, "\\/+") [[1]]
if (length (domains) > 4L & any (domains == "tree")) {
i <- which (domains == "tree")
if (length (domains) > (i + 1)) {
subdir <- domains [i + 2L]

Check warning on line 103 in R/utils.R

View check run for this annotation

Codecov / codecov/patch

R/utils.R#L98-L103

Added lines #L98 - L103 were not covered by tests
}
}
return (subdir)

Check warning on line 106 in R/utils.R

View check run for this annotation

Codecov / codecov/patch

R/utils.R#L106

Added line #L106 was not covered by tests
}

#' Bob Rudis's URL checker function
#'
#' This is used here to check the URLs in the `check_issue_template` function.
Expand Down
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"codeRepository": "https://github.com/ropensci-review-tools/roreviewapi",
"issueTracker": "https://github.com/ropensci-review-tools/roreviewapi/issues",
"license": "https://spdx.org/licenses/GPL-3.0",
"version": "0.1.0.060",
"version": "0.1.0.061",
"programmingLanguage": {
"@type": "ComputerLanguage",
"name": "R",
Expand Down
2 changes: 1 addition & 1 deletion man/get_branch_from_url.Rd

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

13 changes: 13 additions & 0 deletions man/get_subdir_from_url.Rd

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

0 comments on commit 60bc201

Please sign in to comment.