Skip to content

Commit f9b0013

Browse files
committed
chore: make it more robust
1 parent 5832104 commit f9b0013

File tree

3 files changed

+45
-43
lines changed

3 files changed

+45
-43
lines changed

R/github.R

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,6 @@ check_global_git <- function() {
3737
}
3838
}
3939

40-
clone_pkg <- function(pkg_repo, pkg_dir) {
41-
fs::dir_create(pkg_dir)
42-
usethis::create_from_github(pkg_repo, destdir = pkg_dir, open = FALSE)
43-
}
44-
4540
get_repo_meta <- function(pkg_repo, full = FALSE) {
4641
meta <- gh::gh(paste0("/repos/", pkg_repo)) # nolint: paste_linter
4742

R/pkgreview.R

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ pkgreview_create <- function(pkg_repo, review_parent = ".",
4848
sprintf("%s-%s", meta[["name"]], template)
4949
)
5050

51-
clone_pkg(pkg_repo, pkg_dir = review_parent)
51+
create_from_github(pkg_repo, destdir = review_parent, open = FALSE)
5252

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

120120
usethis::create_project(review_dir, open = FALSE)
121+
use_onboarding_tmpl(template, destdir = review_dir)
122+
pkgreview_index_rmd(pkg_data, template, destdir = review_dir)
121123

122-
usethis::with_project(review_dir, {
123-
# create templates
124-
use_onboarding_tmpl(template)
125-
pkgreview_index_rmd(pkg_data, template)
126-
switch(
127-
template,
128-
review = pkgreview_readme_md(pkg_data),
129-
editor = pkgreview_request(pkg_data)
130-
)
131-
}, quiet = TRUE)
124+
switch(
125+
template,
126+
review = pkgreview_readme_md(pkg_data, destdir = review_dir),
127+
editor = pkgreview_request(pkg_data, destdir = review_dir)
128+
)
132129

133130
cli::cli_alert_success(
134131
"{template} project {.val {basename(review_dir)}} initialised"
@@ -221,14 +218,24 @@ pkgreview_getdata <- function(pkg_repo, pkg_dir = NULL,
221218
#' @export
222219
try_whoami <- function() {
223220
if (isTRUE(as.logical(Sys.getenv("CI")))) {
224-
return(
225-
list(
226-
name = "Maëlle Salmon",
227-
login = "maelle",
228-
html_url = "https://github.com/maelle"
229-
)
221+
list(
222+
login = "maelle",
223+
html_url = "https://github.com/maelle"
230224
)
231225
}
232-
233226
try(gh::gh_whoami(gh::gh_token()), silent = TRUE)
234227
}
228+
229+
create_from_github <- function(pkg_repo, destdir, open) {
230+
if (isTRUE(as.logical(Sys.getenv("CI")))) {
231+
url <- sprintf(
232+
"https://github.com/%s/archive/refs/heads/main.zip",
233+
pkg_repo
234+
)
235+
curl::curl_download(url, destdir)
236+
return(TRUE)
237+
}
238+
239+
240+
usethis::create_from_github(pkg_repo, destdir = destdir, open = open)
241+
}

R/render-templates.R

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,23 +16,27 @@
1616
# @importFrom usethis getFromNamespace check_installed
1717
# @importFrom usethis getFromNamespace render_template
1818
pkgreview_index_rmd <- function(pkg_data,
19-
template = c("review", "editor")) {
19+
template = c("review", "editor"),
20+
destdir) {
2021
template <- match.arg(template)
2122

22-
usethis::use_template(
23-
sprintf("%s-index", template),
24-
"index.Rmd",
25-
data = pkg_data,
26-
ignore = FALSE,
27-
open = FALSE,
28-
package = "pkgreviewr"
29-
)
23+
usethis::with_project(destdir, {
24+
usethis::use_template(
25+
sprintf("%s-index", template),
26+
"index.Rmd",
27+
data = pkg_data,
28+
ignore = FALSE,
29+
open = FALSE,
30+
package = "pkgreviewr"
31+
)
32+
})
3033
invisible(TRUE)
3134
}
3235

3336
#' @export
3437
#' @rdname pkgreview_index_rmd
35-
pkgreview_readme_md <- function(pkg_data) {
38+
pkgreview_readme_md <- function(pkg_data, destdir) {
39+
usethis::local_project(destdir)
3640
usethis::use_template(
3741
"review-README",
3842
"README.md",
@@ -56,35 +60,31 @@ pkgreview_readme_md <- function(pkg_data) {
5660
#' \dontrun{
5761
#' use_onboarding_tmpl(template = "editor")
5862
#' }
59-
use_onboarding_tmpl <- function(template = c("review", "editor")) {
63+
use_onboarding_tmpl <- function(template = c("review", "editor"), destdir) {
6064
template <- match.arg(template)
6165
tmpl_txt <- gh::gh("/repos/:owner/:repo/contents/:path",
6266
owner = "ropensci",
6367
repo = "dev_guide",
6468
path = sprintf("templates/%s.md", template) # nolint: nonportable_path_litner
6569
)
6670

67-
temp_file <- withr::local_tempfile()
68-
curl::curl_download(tmpl_txt[["download_url"]], temp_file)
69-
tmpl_txt <- paste(brio::read_lines(temp_file), collapse = "\n")
70-
71-
new <- usethis::write_over(
72-
usethis::proj_path(fs::path_ext_set(template, ".md")),
73-
tmpl_txt
71+
curl::curl_download(
72+
tmpl_txt[["download_url"]],
73+
fs::path(destdir, fs::path_ext_set(template, ".md"))
7474
)
75-
invisible(new)
7675
}
7776

7877

7978

8079
#' @export
8180
#' @rdname pkgreview_index_rmd
82-
pkgreview_request <- function(pkg_data) {
81+
pkgreview_request <- function(pkg_data, destdir) {
8382
pkg_data <- c(
8483
pkg_data,
8584
editor = try_whoami()[["name"]]
8685
)
8786

87+
usethis::local_project(destdir)
8888
usethis::use_template(
8989
"request",
9090
"request.Rmd",

0 commit comments

Comments
 (0)