Skip to content

Commit

Permalink
check URL on pull request only
Browse files Browse the repository at this point in the history
  • Loading branch information
shikokuchuo committed Feb 28, 2024
1 parent 47008f6 commit c3e641a
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 8 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Generated by roxygen2: do not edit by hand

export(assert_package)
export(assert_package_url)
export(build_universe)
export(review_pull_request)
export(review_pull_requests)
Expand Down
21 changes: 15 additions & 6 deletions R/assert_package.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#' @title Validate a package entry.
#' @title Validate a Package Entry
#' @export
#' @keywords internal
#' @description Validate a package entry.
#' @return An character string if there is a problem with the package entry,
#' @return A character string if there is a problem with the package entry,
#' otherwise `NULL` if there are no issues.
assert_package <- function(path) {
if (!is_character_scalar(path)) {
Expand Down Expand Up @@ -40,25 +40,34 @@ assert_package_contents <- function(name, url) {
paste("Found malformed URL", shQuote(url), "of package", shQuote(name))
)
}
}

#' @title Validate a Package URL
#' @export
#' @keywords internal
#' @description Validate that the package URL is in the description file if on
#' CRAN.
#' @return A character string if there is a problem with the URL for the given
#' package name, otherwise `NULL` if there are no issues.
assert_package_url <- function(name, url) {

Check warning on line 52 in R/assert_package.R

View workflow job for this annotation

GitHub Actions / lint

file=R/assert_package.R,line=52,col=1,[cyclocomp_linter] Functions should have cyclomatic complexity of less than 15, this has 16.

Check warning on line 53 in R/assert_package.R

View workflow job for this annotation

GitHub Actions / lint

file=R/assert_package.R,line=53,col=1,[trailing_whitespace_linter] Trailing whitespace is superfluous.
res <- ps(name, size = 1L)
pkg <- res[["package"]]
if (length(pkg) && name == pkg) {

purl <- parse_url(sub("/$", "", url, perl = TRUE))
urls <- strsplit(res[["url"]], ",\n|, |\n", perl = TRUE)[[1L]]
for (u in urls) {
pu <- parse_url(sub("/$", "", u, perl = TRUE))
purl[["host"]] == pu[["host"]] && purl[["path"]] == pu[["path"]] &&
return(invisible())
}

burl <- parse_url(res[["bugreports"]])
purl[["host"]] == burl[["host"]] &&
purl[["path"]] == sub("/issues/*$", "", burl[["path"]], perl = TRUE) &&
return(invisible())

return(
paste("URL of CRAN package", shQuote(name), "is not", shQuote(url))
paste("CRAN package", shQuote(name), "does not have URL", shQuote(url))
)
}

Check warning on line 72 in R/assert_package.R

View workflow job for this annotation

GitHub Actions / lint

file=R/assert_package.R,line=72,col=1,[trailing_whitespace_linter] Trailing whitespace is superfluous.
}
16 changes: 16 additions & 0 deletions R/review_pull_request.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,22 @@ review_pull_request <- function(
)
return(invisible())
}
result <- assert_package_url(name = name, url = url)
if (!is.null(result)) {
pull_request_defer(
owner = owner,
repo = repo,
number = number,
message = paste0(
"Pull request ",
number,
" automated diagnostics failed: ",
result,
". Manual review required."
)
)
return(invisible())
}
}
pull_request_merge(
owner = owner,
Expand Down
4 changes: 2 additions & 2 deletions man/assert_package.Rd

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

17 changes: 17 additions & 0 deletions man/assert_package_url.Rd

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

56 changes: 56 additions & 0 deletions tests/test-assert_package.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,59 @@ dir.create(dirname(path))
writeLines("https://github.com/owner/package", path)
stopifnot(is.null(r.releases.utils::assert_package(path = path)))
unlink(dirname(path), recursive = TRUE)

stopifnot(
grepl(
"does not have URL",
r.releases.utils::assert_package_url(
name = "gh",
url = "https://github.com/r-lib/gha"
),
fixed = TRUE
)
)

stopifnot(
is.null(
r.releases.utils::assert_package_url(
name = "gh",
url = "https://github.com/r-lib/gh"
)
)
)

stopifnot(
is.null(
r.releases.utils::assert_package_url(
name = "curl",
url = "https://github.com/jeroen/curl/"
)
)
)

stopifnot(
is.null(
r.releases.utils::assert_package_url(
name = "curl",
url = "https://github.com/jeroen/curl/"
)
)
)

stopifnot(
is.null(
r.releases.utils::assert_package_url(
name = "jsonlite",
url = "https://github.com/jeroen/jsonlite"
)
)
)

stopifnot(
is.null(
r.releases.utils::assert_package_url(
name = "packageNOTonCRAN",
url = "https://github.com/jeroen/jsonlite"
)
)
)

0 comments on commit c3e641a

Please sign in to comment.