Skip to content
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
5 changes: 5 additions & 0 deletions .github/workflows/R-CMD-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: git config
run: |
git config --global user.email "actions@github.com"
git config --global user.name "gh-pages committer"

- uses: r-lib/actions/setup-pandoc@v2

- uses: r-lib/actions/setup-r@v2
Expand Down
6 changes: 6 additions & 0 deletions .github/workflows/lint-changed-files.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: git config
run: |
git config --global user.email "actions@github.com"
git config --global user.name "gh-pages committer"

- uses: r-lib/actions/setup-r@v2

- uses: r-lib/actions/setup-r-dependencies@v2
Expand All @@ -23,6 +28,7 @@ jobs:
any::gh
any::lintr
any::purrr
cyclocomp
needs: check

- name: Add lintr options
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/test-coverage.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: git config
run: |
git config --global user.email "actions@github.com"
git config --global user.name "gh-pages committer"

- uses: r-lib/actions/setup-r@v2
with:
use-public-rspm: true
Expand Down
5 changes: 0 additions & 5 deletions R/github.R
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ check_global_git <- function() {
}
}

clone_pkg <- function(pkg_repo, pkg_dir) {
fs::dir_create(pkg_dir)
usethis::create_from_github(pkg_repo, destdir = pkg_dir, open = FALSE)
}

get_repo_meta <- function(pkg_repo, full = FALSE) {
meta <- gh::gh(paste0("/repos/", pkg_repo)) # nolint: paste_linter

Expand Down
57 changes: 38 additions & 19 deletions R/pkgreview.R
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pkgreview_create <- function(pkg_repo, review_parent = ".",
sprintf("%s-%s", meta[["name"]], template)
)

clone_pkg(pkg_repo, pkg_dir = review_parent)
create_from_github(pkg_repo, destdir = review_parent, open = FALSE)

# create project
withr::local_options(list(usethis.quiet = TRUE))
Expand Down Expand Up @@ -118,17 +118,14 @@ pkgreview_init <- function(pkg_repo, review_dir = ".",
}

usethis::create_project(review_dir, open = FALSE)
use_onboarding_tmpl(template, destdir = review_dir)
pkgreview_index_rmd(pkg_data, template, destdir = review_dir)

usethis::with_project(review_dir, {
# create templates
use_onboarding_tmpl(template)
pkgreview_index_rmd(pkg_data, template)
switch(
template,
review = pkgreview_readme_md(pkg_data),
editor = pkgreview_request(pkg_data)
)
}, quiet = TRUE)
switch(
template,
review = pkgreview_readme_md(pkg_data, destdir = review_dir),
editor = pkgreview_request(pkg_data, destdir = review_dir)
)

cli::cli_alert_success(
"{template} project {.val {basename(review_dir)}} initialised"
Expand Down Expand Up @@ -220,15 +217,37 @@ pkgreview_getdata <- function(pkg_repo, pkg_dir = NULL,
#' @return a list of whoami token metadata
#' @export
try_whoami <- function() {
if (isTRUE(as.logical(Sys.getenv("CI")))) {
return(
list(
name = "Maëlle Salmon",
login = "maelle",
html_url = "https://github.com/maelle"
)
if (on_ci()) { # nolint: object_usage_linter
list(
login = "maelle",
html_url = "https://github.com/maelle"
)
} else {
try(gh::gh_whoami(gh::gh_token()), silent = TRUE)
}
}

create_from_github <- function(pkg_repo, destdir, open) {
if (on_ci()) { # nolint: object_usage_linter
download_url <- sprintf(
"https://github.com/%s/archive/refs/heads/main.zip",
pkg_repo
)
temp_file <- withr::local_tempfile()
curl::curl_download(download_url, temp_file)

temp_dir <- withr::local_tempdir()
utils::unzip(temp_file, exdir = temp_dir)
zip_name <- sprintf("%s-main", fs::path_file(pkg_repo))

fs::dir_copy(fs::path(temp_dir, zip_name), destdir)
file.rename(
file.path(destdir, zip_name),
file.path(destdir, fs::path_file(pkg_repo))
)
gert::git_init(fs::path(destdir, fs::path_file(pkg_repo)))
return(TRUE)
}

try(gh::gh_whoami(gh::gh_token()), silent = TRUE)
usethis::create_from_github(pkg_repo, destdir = destdir, open = open)
}
44 changes: 23 additions & 21 deletions R/render-templates.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,33 @@
#'
#' @param pkg_data package metadata generated by pkgreview_getdata()
#' @param template character string, one of `review` or `editor`.
#' @param destdir where to save the template
#'
#' @export
# @importFrom usethis getFromNamespace check_installed
# @importFrom usethis getFromNamespace render_template
pkgreview_index_rmd <- function(pkg_data,
template = c("review", "editor")) {
template = c("review", "editor"),
destdir) { # nolint: function_argument_linter
template <- match.arg(template)

usethis::use_template(
sprintf("%s-index", template),
"index.Rmd",
data = pkg_data,
ignore = FALSE,
open = FALSE,
package = "pkgreviewr"
)
usethis::with_project(destdir, {
usethis::use_template(
sprintf("%s-index", template),
"index.Rmd",
data = pkg_data,
ignore = FALSE,
open = FALSE,
package = "pkgreviewr"
)
})
invisible(TRUE)
}

#' @export
#' @rdname pkgreview_index_rmd
pkgreview_readme_md <- function(pkg_data) {
pkgreview_readme_md <- function(pkg_data, destdir) {
usethis::local_project(destdir)
usethis::use_template(
"review-README",
"README.md",
Expand All @@ -48,43 +53,40 @@ pkgreview_readme_md <- function(pkg_data) {
#' Clone an up to date copy of the specified ropensci software
#' review/editor response template.
#' @param template character string, one of `review` or `editor`.
#' @param destdir where to save the template
#'
#' @return writes a `{template}.md` checklist template file in the project root.
#' @return writes a `{template}.md` checklist template file in `destdir`.
#' @export
#'
#' @examples
#' \dontrun{
#' use_onboarding_tmpl(template = "editor")
#' }
use_onboarding_tmpl <- function(template = c("review", "editor")) {
use_onboarding_tmpl <- function(template = c("review", "editor"), destdir) { # nolint: function_argument_linter
template <- match.arg(template)
tmpl_txt <- gh::gh("/repos/:owner/:repo/contents/:path",
owner = "ropensci",
repo = "dev_guide",
path = sprintf("templates/%s.md", template) # nolint: nonportable_path_litner
)

temp_file <- withr::local_tempfile()
curl::curl_download(tmpl_txt[["download_url"]], temp_file)
tmpl_txt <- paste(brio::read_lines(temp_file), collapse = "\n")

new <- usethis::write_over(
usethis::proj_path(fs::path_ext_set(template, ".md")),
tmpl_txt
curl::curl_download(
tmpl_txt[["download_url"]],
fs::path(destdir, fs::path_ext_set(template, ".md"))
)
invisible(new)
}



#' @export
#' @rdname pkgreview_index_rmd
pkgreview_request <- function(pkg_data) {
pkgreview_request <- function(pkg_data, destdir) {
pkg_data <- c(
pkg_data,
editor = try_whoami()[["name"]]
)

usethis::local_project(destdir)
usethis::use_template(
"request",
"request.Rmd",
Expand Down
4 changes: 4 additions & 0 deletions R/utils-ci.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# from testthat
on_ci <- function() {
isTRUE(as.logical(Sys.getenv("CI")))
}
8 changes: 5 additions & 3 deletions man/pkgreview_index_rmd.Rd

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

6 changes: 4 additions & 2 deletions man/use_onboarding_tmpl.Rd

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

38 changes: 0 additions & 38 deletions tests/testthat/_snaps/create-pkgreview.md
Original file line number Diff line number Diff line change
@@ -1,41 +1,3 @@
# review-proj-created-correctly

Code
fs::dir_ls(review_dir, all = TRUE)
Output
/riem-review/.git
/riem-review/.gitignore
/riem-review/.here
/riem-review/R
/riem-review/README.md
/riem-review/index.Rmd
/riem-review/review.md

---

Code
fs::dir_ls(pkg_dir, all = TRUE)
Output
/riem/.Rbuildignore
/riem/.git
/riem/.gitattributes
/riem/.github
/riem/.gitignore
/riem/.lintr
/riem/DESCRIPTION
/riem/NAMESPACE
/riem/NEWS.md
/riem/R
/riem/README.md
/riem/_pkgdown.yml
/riem/codemeta.json
/riem/cran-comments.md
/riem/man
/riem/pkgdown
/riem/riem.Rproj
/riem/tests
/riem/vignettes

# get-pkg_data

Code
Expand Down
38 changes: 38 additions & 0 deletions tests/testthat/_snaps/unix/create-pkgreview.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# review-proj-created-correctly

Code
fs::dir_ls(review_dir, all = TRUE)
Output
/riem-review/.git
/riem-review/.gitignore
/riem-review/.here
/riem-review/R
/riem-review/README.md
/riem-review/index.Rmd
/riem-review/review.md

---

Code
fs::dir_ls(pkg_dir, all = TRUE)
Output
/riem/.Rbuildignore
/riem/.git
/riem/.gitattributes
/riem/.github
/riem/.gitignore
/riem/.lintr
/riem/DESCRIPTION
/riem/NAMESPACE
/riem/NEWS.md
/riem/R
/riem/README.md
/riem/_pkgdown.yml
/riem/codemeta.json
/riem/cran-comments.md
/riem/man
/riem/pkgdown
/riem/riem.Rproj
/riem/tests
/riem/vignettes

10 changes: 6 additions & 4 deletions tests/testthat/test-create-pkgreview.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ test_that("review-proj-created-correctly", {

expect_true(fs::dir_exists(fs::path(review_parent, "riem-review")))
expect_snapshot(
fs::dir_ls(review_dir, all =TRUE),
transform = function(x) sub(".*riem-review/", "/riem-review/", x)
fs::dir_ls(review_dir, all = TRUE),
transform = function(x) sub(".*riem-review/", "/riem-review/", x),
variant = .Platform[["OS.type"]]
)
expect_snapshot(
fs::dir_ls(pkg_dir, all =TRUE),
transform = function(x) sub(".*riem/", "/riem/", x)
fs::dir_ls(pkg_dir, all = TRUE),
transform = function(x) sub(".*riem/", "/riem/", x),
variant = .Platform[["OS.type"]]
)
})

Expand Down
Loading