From 60bc201bba46909f5d24f50836fec2a692fa5985 Mon Sep 17 00:00:00 2001 From: mpadge Date: Mon, 11 Nov 2024 12:26:11 +0100 Subject: [PATCH] add 'get_subdir_from_url' fn for #64 --- DESCRIPTION | 2 +- NAMESPACE | 1 + R/utils.R | 24 +++++++++++++++++++++++- codemeta.json | 2 +- man/get_branch_from_url.Rd | 2 +- man/get_subdir_from_url.Rd | 13 +++++++++++++ 6 files changed, 40 insertions(+), 4 deletions(-) create mode 100644 man/get_subdir_from_url.Rd diff --git a/DESCRIPTION b/DESCRIPTION index ab9c16f..0dca172 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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", , "mark.padgham@email.com", role = c("aut", "cre"), comment = c(ORCID = "0000-0003-2172-5265")) diff --git a/NAMESPACE b/NAMESPACE index 84ca5a3..5ba06d0 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -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) diff --git a/R/utils.R b/R/utils.R index 592fc74..c622167 100644 --- a/R/utils.R +++ b/R/utils.R @@ -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 @@ -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 + } } 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] + } + } + return (subdir) +} + #' Bob Rudis's URL checker function #' #' This is used here to check the URLs in the `check_issue_template` function. diff --git a/codemeta.json b/codemeta.json index 4d15b88..1cde987 100644 --- a/codemeta.json +++ b/codemeta.json @@ -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", diff --git a/man/get_branch_from_url.Rd b/man/get_branch_from_url.Rd index 2b7256a..416b6a2 100644 --- a/man/get_branch_from_url.Rd +++ b/man/get_branch_from_url.Rd @@ -7,7 +7,7 @@ get_branch_from_url(repourl) } \arguments{ -\item{repourl}{Potentially with "/tree/branch_name" appended} +\item{repourl}{Potentially with "/tree/branch_name/sub-directory" appended} } \value{ Branch as single string. diff --git a/man/get_subdir_from_url.Rd b/man/get_subdir_from_url.Rd new file mode 100644 index 0000000..80eb05d --- /dev/null +++ b/man/get_subdir_from_url.Rd @@ -0,0 +1,13 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils.R +\name{get_subdir_from_url} +\alias{get_subdir_from_url} +\title{Return sub-directory from URL if present. This function is also intended to +test whether packages are in sub-directories (issue #64)} +\usage{ +get_subdir_from_url(reporul) +} +\description{ +Return sub-directory from URL if present. This function is also intended to +test whether packages are in sub-directories (issue #64) +}