diff --git a/packages.qmd b/packages.qmd index 3dcff54..7135504 100644 --- a/packages.qmd +++ b/packages.qmd @@ -25,8 +25,9 @@ The OpenRBQM framework is designed to provide a robust and flexible solution for # Function to get package names from a GitHub repository get_packages <- function(org) { - url <- paste0("https://api.github.com/orgs/", org, "/repos") - response <- GET(url) + url <- paste0("https://api.github.com/orgs/", org, "/repos?type=public") + response <- GET(url, + httr::authenticate("lauramaxwell", Sys.getenv("GITHUB_PAT"))) content <- content(response, as = "text") json <- fromJSON(content) return(json) @@ -37,20 +38,98 @@ orgs <- c("openrbqm", "gilead-biostats") # Get packages from each repository packages <- orgs %>% map(get_packages) %>% bind_rows +packages$description[is.na(packages$description)] <- "No Description Provided" -packages %>% glue_data('- [{full_name}]({html_url}) {description}', close='\n') +packages %>% glue_data('- [{full_name}]({html_url}): *{description}*', close='\n') ``` -# Articles +# Package Documentation -## OpenRBQM +```{r define article functions, echo=FALSE, results = "asis"} +get_articles <- function(org, repo) { + url <- paste0("https://api.github.com/repos/",org,"/",repo,"/contents/vignettes") + response <- GET(url, + httr::authenticate("lauramaxwell", Sys.getenv("GITHUB_PAT"))) + if (response$status_code == 200) { + content <- content(response, as = "text") + json <- fromJSON(content) %>% + dplyr::filter(grepl("Rmd", name)) %>% + dplyr::mutate(name_html = gsub("Rmd", "html", name)) + return(json) + } + else{ + return("No articles to display for this repository\n\n") + } +} + +get_meta <- function(article, field) { + field_line <- article[grep(paste0(field,": "), article)[1]] + if(length(field_line) > 0) { + clean_field <- gsub(paste0(field,": "), "", field_line) + clean_field <- gsub('\"', "", clean_field) + } else { + clean_field <- NA + } + return(clean_field) +} + +get_pkgdown_url <- function(org, repo) { + url <- paste0("https://api.github.com/repos/",org,"/",repo) + response <- GET(url, + httr::authenticate("lauramaxwell", Sys.getenv("GITHUB_PAT"))) + content <- content(response, as = "text") + json <- fromJSON(content) + return(json$homepage) +} +``` + + + +```{r get_articles, echo=FALSE, results = "asis"} +packages_clean <- packages %>% + filter(grepl("/", full_name)) %>% # remove malformed full_name entries + mutate( + org = map_chr(full_name, ~ strsplit(.x, "/")[[1]][1]), + repo = map_chr(full_name, ~ strsplit(.x, "/")[[1]][2]) + ) %>% + select(full_name, org, repo) + +# Iterate using pwalk +pwalk(packages_clean, function(full_name, org, repo, ...) { + # Print header with appropriate spacing + homepage_link <- get_pkgdown_url(org, repo) + cat(glue("\n\n## {full_name} \n\n [{repo} Website]({homepage_link})\n\n")) + cat("\n\n") + + articles_meta <- get_articles(org, repo) -- Intro to OpenRBQM -- Data Model Overview + if (is.data.frame(articles_meta)) { + articles <- map(articles_meta$download_url, readLines) + names(articles) <- articles_meta$name -## gsm.core + # Add metadata + articles_meta$title <- map2_chr(articles_meta$name, articles, ~ get_meta(.y, "title")) + articles_meta$description <- map2_chr(articles_meta$name, articles, ~ get_meta(.y, "description")) + articles_meta$homepage_link <- homepage_link -- + # Derive name_html if needed + if (!"name_html" %in% colnames(articles_meta)) { + articles_meta$name_html <- articles_meta$name + } + + # Output + glue_data( + articles_meta, + '- [{title}]({homepage_link}articles/{name_html}) {description}' + ) %>% cat(sep = "\n\n") + } else { + cat(articles_meta, sep = "\n") + } +}) + +``` # Examples + +Under Construction \ No newline at end of file