From 16e095e5a6f94545b25265d948af1b465cb82da8 Mon Sep 17 00:00:00 2001 From: KatherineCox Date: Tue, 4 Feb 2025 09:40:58 -0500 Subject: [PATCH] Delete unneeded scripts --- scripts/AnVIL_Feedback_Script.sh | 19 ------- scripts/anvil_repo_check.R | 83 --------------------------- scripts/anvil_repo_table.R | 41 -------------- scripts/git_repo_check.R | 97 -------------------------------- scripts/make_screenshots.R | 74 ------------------------ scripts/ottr-fy.R | 67 ---------------------- scripts/quiz-check.R | 39 ------------- scripts/spell-check.R | 67 ---------------------- scripts/url-check.R | 75 ------------------------ 9 files changed, 562 deletions(-) delete mode 100644 scripts/AnVIL_Feedback_Script.sh delete mode 100644 scripts/anvil_repo_check.R delete mode 100644 scripts/anvil_repo_table.R delete mode 100644 scripts/git_repo_check.R delete mode 100644 scripts/make_screenshots.R delete mode 100644 scripts/ottr-fy.R delete mode 100644 scripts/quiz-check.R delete mode 100644 scripts/spell-check.R delete mode 100644 scripts/url-check.R diff --git a/scripts/AnVIL_Feedback_Script.sh b/scripts/AnVIL_Feedback_Script.sh deleted file mode 100644 index 5269b76..0000000 --- a/scripts/AnVIL_Feedback_Script.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -# Extract the title from the YAML front matter of index.Rmd -title=$(awk '/^title:/{gsub(/^title: /,""); print}' "index.Rmd" | grep -v '^$') - -# Remove the outside quotation marks -title=$(sed -e 's/^"//' -e 's/"$//' <<< "$title") - -# Replace spaces with '+' -title=${title// /+} - -# Base url for the AnVIL Google Form -url_base="https://docs.google.com/forms/d/e/1FAIpQLScrDVb_utm55pmb_SHx-RgELTEbCCWdLea0T3IzS0Oj00GE4w/viewform?usp=pp_url&entry.1565230805=" - -# Replace the url inside _output.yml -perl -i -pe 's|https://docs.google.com/forms/d/e/1FAIpQLScrDVb_utm55pmb_SHx-RgELTEbCCWdLea0T3IzS0Oj00GE4w/viewform\?usp=pp_url&entry\.1565230805=.*"> Click|'${url_base}${title}'"> Click|g' _output.yml - -# Print for Github actions -echo "The feedback link is: ${url_base}${title}" \ No newline at end of file diff --git a/scripts/anvil_repo_check.R b/scripts/anvil_repo_check.R deleted file mode 100644 index 36b3dcb..0000000 --- a/scripts/anvil_repo_check.R +++ /dev/null @@ -1,83 +0,0 @@ -#!/usr/bin/env Rscript - -library(optparse) -library(httr) -library(jsonlite) -library(dplyr) -library(readr) - -option_list <- list( - optparse::make_option( - c("--git_pat"), - type = "character", - default = NULL, - help = "GitHub personal access token", - ) -) - -# Read the GH_PAT argument -opt_parser <- optparse::OptionParser(option_list = option_list) -opt <- optparse::parse_args(opt_parser) -git_pat <- opt$git_pat - -message(paste("Querying Github API...")) - -# Request search results specific to AnVIL within the jhudsl organization -# and provide the appropriate GH token -req <- httr::GET( - "https://api.github.com/search/repositories?q=user:jhudsl&per_page=500", - httr::add_headers(Authorization = paste("token", git_pat)) -) - -if (!(httr::http_error(req))) { - message(paste("API request successful!")) - - # Read in and save data - repo_dat <- - jsonlite::fromJSON(httr::content(req, as = "text"), flatten = TRUE) - - message(paste("...", repo_dat$total_count, "organization repositories detected.")) - - # Modify the request results to get what we need - repo_df <- - dplyr::tibble(repo_dat$items) %>% - dplyr::select(name, homepage, html_url, description) %>% - # Search for AnVIL in topics - dplyr::bind_cols(tibble(anvil = unlist( - lapply(repo_dat$items$topics, function(x) { - "anvil" %in% x - }) - ))) %>% - # Collapse topics so they can be printed - dplyr::bind_cols(tibble(topics = unlist( - lapply(repo_dat$items$topics, paste, collapse = ", ") - ))) %>% - # Filter for anvil tag - dplyr::filter(anvil) %>% - dplyr::relocate(description, .before = topics) - - message(paste("...", nrow(repo_df), "repositories with AnVIL topic tagged.")) - - # Ensure no missing homepage / description - repo_df <- - repo_df %>% filter(!(is.na(homepage)), homepage != "", !(is.na(description))) - - message(paste("...", nrow(repo_df), "repositories with homepage & description.")) - - # Create an artifact file containing the AnVIL repos, else write an empty file - if (!dir.exists("resources")) { - dir.create("resources") - } - if (nrow(repo_df) > 0) { - readr::write_tsv(repo_df, file.path('resources', 'AnVIL_repos.tsv')) - } else { - readr::write_tsv(tibble(), file.path('resources', 'AnVIL_repos.tsv')) - } - -} else { - message(paste("API request failed!")) - if (!dir.exists("resources")) { - dir.create("resources") - } - readr::write_tsv(tibble(), file.path('resources', 'AnVIL_repos.tsv')) -} diff --git a/scripts/anvil_repo_table.R b/scripts/anvil_repo_table.R deleted file mode 100644 index 7d9f472..0000000 --- a/scripts/anvil_repo_table.R +++ /dev/null @@ -1,41 +0,0 @@ -library(dplyr) -library(stringr) - -make_anvil_repo_table <- function(exclude = NULL) { - # Read in AnVIL repos found by GHA - df <- tryCatch( - # Check for the file created by GHA - expr = { - df <- - readr::read_tsv("resources/AnVIL_repos.tsv") - }, - # Will error out if file doesn't exist - provides a blank tibble instead - error = function(e) { - df <- tibble(name = "none", html_url = "none") - } - ) - - # Filter out any user specified repos (could be some that are in progress, - # templates, etc) - df <- - df %>% - filter(!(name %in% exclude)) - - # Do some cleaning of strings - df$name <- - df$name %>% - stringr::str_replace_all("_Book_", ": ") %>% - stringr::str_replace_all("_", " ") - - # Concatenate columns to create links - df <- - df %>% - mutate(`Book Name` = paste0("[", name, "](", homepage, ") ([github](", html_url, "))")) %>% - arrange(`Book Name`) %>% - rename(Description = description, Topics = topics) %>% - select(`Book Name`, Description, Topics) - - message(paste(colnames(df))) - - return(df) -} diff --git a/scripts/git_repo_check.R b/scripts/git_repo_check.R deleted file mode 100644 index fd4b8f5..0000000 --- a/scripts/git_repo_check.R +++ /dev/null @@ -1,97 +0,0 @@ -#!/usr/bin/env Rscript - -# Written by Candace Savonen Sept 2021 - -if (!("optparse" %in% installed.packages())){ - install.packages("optparse") -} - -library(optparse) - -option_list <- list( - optparse::make_option( - c("--repo"), - type = "character", - default = NULL, - help = "GitHub repository name, e.g. jhudsl/OTTR_Template", - ), - optparse::make_option( - c("--git_pat"), - type = "character", - default = NULL, - help = "GitHub personal access token", - ) -) - -# Read the arguments passed -opt_parser <- optparse::OptionParser(option_list = option_list) -opt <- optparse::parse_args(opt_parser) - -repo <- opt$repo -git_pat <- opt$git_pat - -if (!is.character(repo)) { - repo <- as.character(repo) -} - -check_git_repo <- function(repo, git_pat = NULL, silent = TRUE, return_repo = FALSE) { - # Given a repository name, check with git ls-remote whether the repository - # exists and return a TRUE/FALSE - - # Inputs: - # repo: the name of the repository, e.g. jhudsl/OTTR_Template - # git_pat: A personal access token from GitHub. Only necessary if the repository being - # checked is a private repository. - # silent: TRUE/FALSE of whether the warning from the git ls-remote command - # should be echoed back if it does fail. - # return_repo: TRUE/FALSE of whether or not the output from git ls-remote - # should be saved to a file (if the repo exists) - - # Returns: - # A TRUE/FALSE whether or not the repository exists. - # Optionally the output from git ls-remote if return_repo = TRUE. - - message(paste("Checking for remote git repository:", repo)) - - # If silent = TRUE don't print out the warning message from the 'try' - report <- ifelse(silent, suppressWarnings, message) - - if (!is.null(git_pat)) { - # If git_pat is supplied, use it - test_repo <- report( - try(system(paste0("git ls-remote https://", git_pat, "@github.com/", repo), - intern = TRUE, ignore.stderr = TRUE - )) - ) - } else { - - # Try to git ls-remote the repo given - test_repo <- report( - try(system(paste0("git ls-remote https://github.com/", repo), - intern = TRUE, ignore.stderr = TRUE - )) - ) - } - # If 128 is returned as a status attribute it means it failed - exists <- ifelse(is.null(attr(test_repo, "status")), TRUE, FALSE) - - if (return_repo && exists) { - # Make file name - output_file <- paste0("git_ls_remote_", gsub("/", "_", repo)) - - # Tell the user the file was saved - message(paste("Saving output from git ls-remote to file:", output_file)) - - # Write to file - writeLines(exists, file.path(output_file)) - } - - return(exists) -} - -# Change repo name to its Leanpub equivalent: -repo <- gsub("_Template", "", repo) -repo <- paste0(repo, "_Quizzes") - -# Print out the result -write(check_git_repo(repo, git_pat = git_pat), stdout()) diff --git a/scripts/make_screenshots.R b/scripts/make_screenshots.R deleted file mode 100644 index c57a182..0000000 --- a/scripts/make_screenshots.R +++ /dev/null @@ -1,74 +0,0 @@ -#!/usr/bin/env Rscript -# Written by Candace Savonen Jan 2022 - -if (!('devtools' %in% installed.packages())) { - # install.packages("remotes", repos = "http://cran.us.r-project.org") -} - -if (!('optparse' %in% installed.packages())) { - # install.packages("optparse", repos = "http://cran.us.r-project.org") -} - -webshot::install_phantomjs() - -library(optparse) -library(magrittr) - -option_list <- list( - optparse::make_option( - c("--repo"), - type = "character", - default = NULL, - help = "GitHub repository name, e.g. jhudsl/OTTR_Template", - ), - optparse::make_option( - c("--git_pat"), - type = "character", - default = NULL, - help = "GitHub personal access token", - ), - optparse::make_option( - c("--output_dir"), - type = "character", - default = "resources/chapt_screen_images", - help = "Output directory where the chapter's screen images should be stored", - ), - optparse::make_option( - c("--base_url"), - type = "character", - default = NULL, - help = "Output directory where the chapter's screen images should be stored", - ) -) - -# Read the arguments passed -opt_parser <- optparse::OptionParser(option_list = option_list) -opt <- optparse::parse_args(opt_parser) - -output_folder <- file.path(opt$output_dir) -if (!dir.exists(output_folder)) { - dir.create(output_folder, recursive = TRUE) -} - -if (is.null(opt$base_url)) { - base_url <- cow::get_pages_url(repo_name = opt$repo, git_pat = opt$git_pat) - base_url <- gsub("/$", "", base_url) -} - -chapt_df <- ottrpal::get_chapters(base_url = file.path(base_url, "no_toc/")) - -file_names <- lapply(chapt_df$url, function(url) { - file_name <- gsub(".html", ".png", file.path(output_folder, basename(url))) - # Get rid of special characters - webshot::webshot(url, file_name) - file_name <- gsub(":|?|!|\\'", "", file_name) - message(paste("Screenshot saved:", file_name)) - return(file_name) -}) - -# Save file of chapter urls and file_names -chapt_df %>% - dplyr::mutate(img_path = unlist(file_names)) %>% - readr::write_tsv(file.path(output_folder, "chapter_urls.tsv")) - -message(paste("Image Chapter key written to: ", file.path(output_folder, "chapter_urls.tsv"))) diff --git a/scripts/ottr-fy.R b/scripts/ottr-fy.R deleted file mode 100644 index aa079ce..0000000 --- a/scripts/ottr-fy.R +++ /dev/null @@ -1,67 +0,0 @@ -#!/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") diff --git a/scripts/quiz-check.R b/scripts/quiz-check.R deleted file mode 100644 index 9c10ee9..0000000 --- a/scripts/quiz-check.R +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env Rscript - -# Adapted for this jhudsl repository by Candace Savonen Mar 2022 - -# Run spell check and save results - -library(magrittr) - -# Find .git root directory -root_dir <- rprojroot::find_root(rprojroot::has_dir(".git")) - -output_file <- file.path(root_dir, 'check_reports', 'question_error_report.tsv') - -if (!dir.exists('check_reports')) { - dir.create('check_reports') -} - -ottrpal::check_quizzes(quiz_dir = file.path(root_dir, 'quizzes'), write_report = TRUE, verbose = TRUE) - -if (file.exists("question_error_report.tsv")) { - quiz_errors <- readr::read_tsv("question_error_report.tsv") - - file.copy('question_error_report.tsv', file.path(root_dir, 'check_reports')) - file.remove('question_error_report.tsv') - - # Print out how many quiz check errors - write(nrow(quiz_errors), stdout()) - -} else { - quiz_errors <- data.frame(errors = NA) - - # Print out how many quiz check errors - write("1", stdout()) -} - -# Save question errors to file -readr::write_tsv(quiz_errors, output_file) - -message(paste0("Saved to: ", output_file)) diff --git a/scripts/spell-check.R b/scripts/spell-check.R deleted file mode 100644 index 58f1b17..0000000 --- a/scripts/spell-check.R +++ /dev/null @@ -1,67 +0,0 @@ -#!/usr/bin/env Rscript - -# This code was originally written by Josh Shapiro and Candace Savonen -# for the Childhood Cancer Data Lab an initiative of Alexs Lemonade Stand Foundation. -# https://github.com/AlexsLemonade/refinebio-examples/blob/33cdeff66d57f9fe8ee4fcb5156aea4ac2dce07f/.github/workflows/style-and-sp-check.yml#L1 - -# Adapted for this jhudsl repository by Candace Savonen Apr 2021 - -# Run spell check and save results - -library(magrittr) - -if (!("spelling" %in% installed.packages())){ - install.packages("spelling") -} -# Find .git root directory -root_dir <- rprojroot::find_root(rprojroot::has_dir(".git")) - -# Set up output file directory -output_file <- file.path(root_dir, 'check_reports', 'spell_check_results.tsv') - -if (!dir.exists('check_reports')) { - dir.create('check_reports') -} - -dictionary_file <- file.path(root_dir, 'resources', 'dictionary.txt') - -if (!file.exists(dictionary_file)) { - message(paste("No dictionary text file found at:", dictionary_file, "downloading one from the main OTTR Template repo")) - download.file("https://raw.githubusercontent.com/jhudsl/OTTR_Template/main/resources/dictionary.txt", - destfile = dictionary_file) -} - -# Read in dictionary -dictionary <- readLines(dictionary_file) - -# Only declare `.Rmd` files but not the ones in the style-sets directory -files <- list.files(pattern = 'Rmd$', recursive = TRUE, full.names = TRUE) - -# Get quiz file names -quiz_files <- list.files(file.path(root_dir, "quizzes"), pattern = '\\.md$', full.names = TRUE) - -# Put into one list -files <- c(files, quiz_files) - -files <- grep("About.Rmd", files, ignore.case = TRUE, invert = TRUE, value = TRUE) -files <- grep("style-sets", files, ignore.case = TRUE, invert = TRUE, value = TRUE) - -# Run spell check -sp_errors <- spelling::spell_check_files(files, ignore = dictionary) - -if (nrow(sp_errors) > 0) { - sp_errors <- sp_errors %>% - data.frame() %>% - tidyr::unnest(cols = found) %>% - tidyr::separate(found, into = c("file", "lines"), sep = ":") -} else { - sp_errors <- data.frame(errors = NA) -} - -# Print out how many spell check errors -write(nrow(sp_errors), stdout()) - -# Save spell errors to file temporarily -readr::write_tsv(sp_errors, output_file) - -message(paste0("Saved to: ", output_file)) diff --git a/scripts/url-check.R b/scripts/url-check.R deleted file mode 100644 index 4928ea0..0000000 --- a/scripts/url-check.R +++ /dev/null @@ -1,75 +0,0 @@ -#!/usr/bin/env Rscript - -# Adapted for this jhudsl repository by Candace Savonen Mar 2022 - -# Summarize url checks - -library(magrittr) - -# Find .git root directory -root_dir <- rprojroot::find_root(rprojroot::has_dir(".git")) - -ignore_urls_file <- file.path(root_dir, "resources", "ignore-urls.txt") - -if (!file.exists(ignore_urls_file)) { - message(paste("No ignore URLs text file found at:", ignore_urls_file, "downloading one from the main OTTR Template repo")) - download.file("https://raw.githubusercontent.com/jhudsl/OTTR_Template/main/resources/ignore-urls.txt", - destfile = ignore_urls_file) -} -ignore_urls <- readLines(ignore_urls_file) - -output_file <- file.path(root_dir, 'check_reports', 'url_checks.tsv') - -if (!dir.exists('check_reports')) { - dir.create('check_reports') -} - -# Only declare `.Rmd` files but not the ones in the style-sets directory -files <- list.files(path = root_dir, pattern = 'md$', full.names = TRUE) - -test_url <- function(url) { - message(paste0("Testing: ", url)) - url_status <- try(httr::GET(url), silent = TRUE) - status <- ifelse(suppressMessages(grepl("Could not resolve host", url_status)), "failed", "success") - return(status) -} - -get_urls <- function(file) { - # Read in a file and return the urls from it - content <- readLines(file) - content <- grep("http[s]?://", content, value = TRUE) - url_pattern <- "http[s]?://.+?[\"|\\)| |,|}]" - urls <- stringr::str_extract(content, url_pattern) - urls <- urls[!is.na(urls)] - if (length(urls) > 0 ){ - urls <- gsub("\\)$|\"|)$", "", urls) - urls_status <- sapply(urls, test_url) - url_df <- data.frame(urls, urls_status, file) - return(url_df) - } -} - -# Run this for all Rmds -all_urls <- lapply(files, get_urls) - -# Write the file -all_urls_df <- dplyr::bind_rows(all_urls) %>% - dplyr::filter(!is.na(urls)) - -if (nrow(all_urls_df) > 0) { - failed_urls_df <- all_urls_df %>% - dplyr::filter(urls_status == "failed") -} else { - failed_urls_df <- data.frame(errors = NA) -} - -failed_urls_df <- failed_urls_df %>% - dplyr::filter(!(urls %in% ignore_urls)) - -# Save spell errors to file temporarily -readr::write_tsv(failed_urls_df, output_file) - -message(paste0("Saved to: ", output_file)) - -# Print out how many spell check errors -write(nrow(failed_urls_df), stdout())