Skip to content

Commit

Permalink
#196 updates following review
Browse files Browse the repository at this point in the history
  • Loading branch information
manciniedoardo committed Aug 7, 2024
1 parent f7dc9ce commit 3e1d5fe
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 11 deletions.
3 changes: 2 additions & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ Please check off each taskbox as an acknowledgment that you completed the task o

- [ ] Place Closes #<insert_issue_number> into the beginning of your Pull Request Title (Use Edit button in top-right if you need to update), and make sure the corresponding issue is linked in the Development section on the right hand side
- [ ] Run the script from `CICD.R` line by line to first check the spelling in your post and then to make sure your code is compatible with our code-style. Address any incongruences by following the instructions in the file!
- [ ] Choose (possibly several) `tag(s)` or categories from the current list: `c("Metadata", "SDTM", "ADaM", "TLG", "Shiny", "Community", "Conferences", "Submissions", "Technical")` for your blog post. If you cannot find anything that fits your blog post, add your own tag! We occasionally tidy up all `tags` for consistency.
- [ ] Choose (possibly several) `tag(s)` or categories from the current list: ` c("Metadata", "SDTM", "ADaM", "TLG", "Shiny", "Community", "Conferences", "Submissions", "Technical")` for your blog post. If you cannot find anything that fits your blog post, propose a new tag to the maintainers! Note: if you use
a tag not from this list, the "Check Post Tags" CICD pipeline will error. We occasionally tidy up all `tags` for consistency.
- [ ] Add a short description for your blog post in the `description` field at the top of the markdown document.
- [ ] Blog post is *short*, *personalized*, *reproducible* and *readable*
- [ ] Add a disclaimer at the top of your post, if appropriate (example: **Disclaimer**
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/check_post_tags.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ jobs:
image: "rocker/tidyverse:4.2.1"
steps:
- uses: actions/checkout@v4
shell: Rscript {0}
- name: Run check_post_tags
run: source("R/check_post_tags.R")
shell: Rscript {0}
4 changes: 4 additions & 0 deletions R/allowed_tags.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#' This is a vector of all the allowed blog post tags. It is stored in a separate file so that it can be referenced
#' by `create_blogpost.R` and `check_post_tags.R`.

allowed_tags <<- c("Metadata", "SDTM", "ADaM", "TLG", "Shiny", "Community", "Conferences", "Submissions", "Technical")
26 changes: 21 additions & 5 deletions R/check_post_tags.R
Original file line number Diff line number Diff line change
@@ -1,18 +1,34 @@
# Get list of blog posts ----
posts <- list.files("posts", recursive = TRUE, pattern = "*.qmd")

# Get vector of allowed tags ----
source("R/allowed_tags.R")

# Function to extract tags from a post and check them against the allowed list ----
check_post_tags <- function(post) {
allowable_tags <- c("Metadata", "SDTM", "ADaM", "TLG", "Shiny", "Community", "Conferences", "Submissions", "Technical")

post_tags <- rmarkdown::yaml_front_matter(file.path("posts", post))$categories

cross_check <- post_tags %in% allowable_tags

problematic_tags <- post_tags[!cross_check]

if (!all(cross_check)) {
stop(paste("The tags selected in:", post, "are not all from the allowed list of tags."))
cli::format_message('The tag(s) {.val {problematic_tags}} in the post {.val {post}} are not from the allowable list of tags.')
}
}

# Apply check_post_tags to all blog posts ----
invisible(lapply(posts, check_post_tags))
# Apply check_post_tags to all blog posts and find problem posts ----
check_results <- lapply(posts, check_post_tags)
error_messages <- unlist(Filter(Negate(is.null), check_results))

# Construct error message if one or more posts have problematic tags ----
if(length(error_messages) > 0){

error_messages <- c(error_messages, "Please select from the following tags: {.val {allowed_tags}}, or contact one of the maintainers.")
names(error_messages) = rep("x", length(error_messages) - 1)

concatenated_error_messages = cli::cli_bullets(error_messages)

cli::cli_abort(concatenated_error_messages)

}
9 changes: 4 additions & 5 deletions R/create_blogpost.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# You can easily create a new blog post skeleton using the create_post() function.
# First, we load the helping function:
# First, we load the helping function and the allowed post tags:

source("R/help_create_blogpost.R")

source("R/allowed_tags.R")

## The available images are at the moment:
list.files("media") %>% tools::file_path_sans_ext()
## Please choose (possibly multiple) from this tags list:
c("Metadata", "SDTM", "ADaM", "TLG", "Shiny", "Community", "Conferences", "Submissions", "Technical")
print(allowed_tags)

# Fill in the info, e.g.:
create_post(
Expand All @@ -16,10 +16,9 @@ create_post(
description = "", # you can fill the description in later as well
author = c("My Name"), # one or more authors are permitted
cover_image = "pharmaverse", # chose one of the above (see line 8)
tags = c("submission", "ADaMs", "conferences", "admiral", "xportr", "metatools", "metacore") # chose (multiple) from line 10
tags = c("Metadata", "SDTM", "ADaM", "TLG", "Shiny", "Community", "Conferences", "Submissions", "Technical") # chose (multiple) from line 10
)


# Remove that post:
# unlink("posts/2023-06-15_lbla", recursive = TRUE)

Expand Down
2 changes: 2 additions & 0 deletions R/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ Some of these files help in creating/developing blog-posts, others are used by o

- `create_blogpost.R`: use this script to create a new blogpost based on our blogpost template.
- `CICD.R`: use this script to spellcheck and stylecheck your blogpost.
- `allowed_tags.R`: contains vector of allowed blog post tags

## development files
- `help_create_blogpost.R`: script containing the function(s) used by `create_blogpost.R`
- `switch.R`: Used by CICD spellcheck workflow.
- `check_post_tags.R`: Used by Check-Post-Tags CICD workflow

0 comments on commit 3e1d5fe

Please sign in to comment.