Skip to content

Instantly share code, notes, and snippets.

@zkamvar
Created November 21, 2023 23:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zkamvar/ae624796cf29c25be494e6dc8808b350 to your computer and use it in GitHub Desktop.
Save zkamvar/ae624796cf29c25be494e6dc8808b350 to your computer and use it in GitHub Desktop.
Give thanks to contributors of a project
#' Produce a list of all GitHub contributors to a project
#'
#' If you want a way to give thanks to specific people who have contributed to a project
#' since a given release, this will extract the GitHub user names from a given package's
#' NEWS file. This assumes that 1) the package has a `NEWS.md` file and 2) the package
#' uses level 1 headers and semantic versioning for each version in the news file.
#'
#' @param package the name of a package
#' @param since a version number (must match a version recorded in the NEWS)
#' @return a character vector with GitHub user names
#' @examples
#' give_thanks("stringr", "1.2.0")
#' give_thanks("pkgdown", "1.0.0")
give_thanks <- function(package = "sandpaper", since = "1.0.0") {
news <- tinkr::yarn$new(system.file("NEWS.md", package = package))
predicate <- paste0("[@level=1][md:text[contains(text(),'", since, "')]]")
xpath <- paste0(".//md:heading", predicate, "/preceding-sibling::*")
nodes <- xml2::xml_find_all(news$body, xpath, news$ns)
txt <- xml2::xml_text(xml2::xml_find_all(nodes, ".//md:item//md:text[contains(text(),'@')]", news$ns))
unique(unlist(stringr::str_extract_all(txt, "([@][[:alnum:]]+)")))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment