Skip to content

Commit

Permalink
Closes #196 Check post tags using CICD (#208)
Browse files Browse the repository at this point in the history
* #196 add function to check post tags

* #196 add check post tags workflow

* #196 update to workflow

* #196 testing changes

* #196 updates

* #196 updates

* #196 test

* #196 test

* #196 test

* #196 test

* #196 update

* #196 update

* #196 updates following review

* #196 update

* #196 updates

* #196 updates

* #196 styler

* #196 styler

* #196 wording

* #196 styler again lol

* #196 remove superassignment and linebreak in PR guidance

* #196 correct submission tags
  • Loading branch information
manciniedoardo authored Aug 7, 2024
1 parent 20e487a commit d2d7dc2
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/pull_request_template.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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
17 changes: 17 additions & 0 deletions .github/workflows/check_post_tags.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Check post tags

on:
pull_request:
branches:
- 'main'

jobs:
Check-post-tags:
runs-on: ubuntu-latest
container:
image: "rocker/tidyverse:4.2.1"
steps:
- uses: actions/checkout@v4
- 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")
30 changes: 30 additions & 0 deletions R/check_post_tags.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# 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, allowed_post_tags = allowed_tags) {
post_tags <- rmarkdown::yaml_front_matter(file.path("posts", post))$categories
cross_check <- post_tags %in% allowed_post_tags
problematic_tags <- post_tags[!cross_check]

if (!all(cross_check)) {
cli::format_message("The tag(s) {.val {problematic_tags}} in the post {.val {post}} are not from the allowed list of 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
2 changes: 1 addition & 1 deletion posts/2023-08-14_rhino_submission_2/rhino_submission_2.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ description: "A short blog post about a Rhino pilot submission." # <---- please
date: "2023-10-10"
# please do not use any non-default categories.
# You can find the default categories in the repository README.md
categories: [Submission, Community]
categories: [Submissions, Community]
# feel free to change the image
image: "Rhino_LS.png"
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ description: "In this post, we dig into the ongoing efforts undertaken to evalua
date: "2024-02-01"
# please do not use any non-default categories.
# You can find the default categories in the repository README.md
categories: [Submission]
categories: [Submissions]
# feel free to change the image
image: "FDA_WebR_Rhino.webp"
---
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ description: "In this post, we explore the importance of validation in the pharm
date: "2024-03-01"
# please do not use any non-default categories.
# You can find the default categories in the repository README.md
categories: [Submission, Community]
categories: [Submissions, Community]
# feel free to change the image
image: "Rhino.webp"
---
Expand Down

0 comments on commit d2d7dc2

Please sign in to comment.