generated from jhudsl/OTTR_Template
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathottr-fy.R
67 lines (55 loc) · 1.97 KB
/
ottr-fy.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
#!/usr/bin/env Rscript
# This script downloads all the files and sets up the folders you need to
# OTTR-fy a repository that has markdown or R Markdown files
system("git checkout -b 'robot/ottr-fy'")
if (!('optparse' %in% installed.packages())) {
install.packages("optparse")
}
library(optparse)
library(magrittr)
option_list <- list(
optparse::make_option(
c("--bookdown"),
action = "store_true",
help = "Is this a bookdown repository already? If used, means bookdown repo.",
)
)
# Read the arguments passed
opt_parser <- optparse::OptionParser(option_list = option_list)
opt <- optparse::parse_args(opt_parser)
# Find .git root directory
root_dir <- rprojroot::find_root(rprojroot::has_dir(".git"))
base_url <- "https://raw.githubusercontent.com/jhudsl/OTTR_Template/main/"
needed_files <- c(
".github/workflows/pull_request.yml",
".github/workflows/render-all.yml",
".github/workflows/delete-preview.yml",
"scripts/git_repo_check.R",
"scripts/make_screenshots.R",
"_bookdown.yml",
"_output.yml",
"book.bib",
"config_automation.yml",
"assets/big-image.html",
"assets/footer.html"
)
# If this is bookdown, we don't want to copy over the bookdown.yml or output.yml files
if (opt$bookdown) {
needed_files <- setdiff(needed_files,
c("_bookdown.yml", "_output.yml", "assets/big-image.html", "assets/footer.html", "book.bib"))
}
# Set up a file list with the destination locations as the names
url_to_files <- paste0(base_url, needed_files)
names(url_to_files) <- file.path(root_dir, needed_files)
# Download the file in the respective place
for (index in 1:length(url_to_files)) {
dest_folder <- dirname(names(url_to_files)[index])
if (!dir.exists(dest_folder)){
dir.create(dest_folder, recursive = TRUE)
}
download.file(url = url_to_files[index], destfile = names(url_to_files)[index])
}
system("git add .")
system("git config commit.gpgsign false")
system("git commit -m 'Add ottr-fying files'")
system("git push --set-upstream origin robot/ottr-fy")