-
Notifications
You must be signed in to change notification settings - Fork 8
Dynamically pull repo information for HPC lessons #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
20267a6
Dynamically pull repo information for HPC lessons
526c20b
Update to use latest json data
c760145
Fix action
fef50ed
Fix CI
45747e2
Update build-and-deploy.yml
1216dd3
Add hpc-carpentry as tag to filter
15ddec2
Merge branch 'main' into generate_lesson_json and update lesson page
a70358a
Fix broken link
75f2b93
Add a whitelist to Help Wanted
7bb1e52
Remove unnecessary duplication
59c6fd7
Address review comments
f0dc50d
Update README with new instructions
f9dc447
Document feed script dependencies
tkphd 344dc96
Typo
6211c97
Merge branch 'generate_lesson_json' of github.com:hpc-carpentry/hpc-c…
d8b9972
Update README.md
3069c2c
Update R feed dependencies, install instructions
tkphd 377f9a1
Merge branch 'generate_lesson_json' of github:hpc-carpentry/hpc-carpe…
tkphd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,5 @@ gem 'faraday', '0.17.3' | |
|
||
group :jekyll_plugins do | ||
gem 'github-pages' | ||
gem 'jekyll-get-json', "~> 0.0.2" | ||
# gem 'jekyll-get-json', "~> 0.0.2" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since we are not pulling data from AMY this is not needed (yet) |
||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
The files in this directory are based off of https://github.com/carpentries/feeds.carpentries.org (also MIT licence). If they require an update you should check there first. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
source("R/utils.R") | ||
ocaisa marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
new_tbl_github_issues <- function(url = character(0), | ||
title = character(0), | ||
type = character(0), | ||
labels = character(0), | ||
label_colors = character(0), | ||
font_colors = character(0), | ||
created_at = character(0), | ||
updated_at = character(0), | ||
empty = FALSE | ||
) { | ||
|
||
stopifnot(rlang::is_scalar_logical(empty)) | ||
|
||
if (empty) { | ||
stopifnot(rlang::is_character(url, n = 0L)) | ||
stopifnot(rlang::is_character(title, n = 0L)) | ||
stopifnot(rlang::is_character(type, n = 0L)) | ||
stopifnot(rlang::is_character(labels, n = 0L)) | ||
stopifnot(rlang::is_character(label_colors, n = 0L)) | ||
stopifnot(rlang::is_character(font_colors, n = 0L)) | ||
stopifnot(rlang::is_character(created_at, n = 0L)) | ||
stopifnot(rlang::is_character(updated_at, n = 0L)) | ||
} else { | ||
stopifnot(rlang::is_scalar_character(url)) | ||
stopifnot(rlang::is_scalar_character(title)) | ||
stopifnot(rlang::is_scalar_character(type)) | ||
stopifnot(rlang::is_character(labels)) | ||
stopifnot(rlang::is_character(label_colors)) | ||
stopifnot(rlang::is_character(font_colors)) | ||
stopifnot(rlang::is_scalar_character(created_at)) | ||
stopifnot(rlang::is_scalar_character(updated_at)) | ||
} | ||
|
||
tibble::tibble( | ||
url, | ||
title, | ||
type, | ||
labels, | ||
label_colors, | ||
font_colors, | ||
created_at, | ||
updated_at | ||
) | ||
|
||
} | ||
|
||
get_gh_issues_raw <- function(owner, repo, labels) { | ||
if (!is.null(labels)) { | ||
stopifnot(identical(length(labels), 1L)) | ||
} | ||
gh::gh( | ||
"GET /repos/:owner/:repo/issues", | ||
owner = owner, | ||
repo = repo, | ||
labels = labels | ||
) | ||
} | ||
|
||
extract_issue_info <- function(issues) { | ||
|
||
if (identical(length(issues), 0L)) { | ||
return(new_tbl_github_issues(empty = TRUE)) | ||
} | ||
|
||
issues %>% | ||
purrr::map_df(function(.x) { | ||
new_tbl_github_issues( | ||
url = .x$html_url, | ||
title = .x$title, | ||
type = dplyr::case_when( | ||
grepl("/pull/[0-9]+$", .x$html_url) ~ "PR", | ||
TRUE ~ "issue" | ||
), | ||
labels = purrr::map_chr(.x$labels, "name") %>% | ||
paste(., collapse = ","), | ||
label_colors = purrr::map_chr(.x$labels, "color") %>% | ||
paste0("#", ., collapse = ","), | ||
font_colors = purrr::map_chr(.x$labels, "color") %>% | ||
paste0("#", .) %>% | ||
font_color(.) %>% | ||
paste(., collapse = ","), | ||
created_at = .x$created_at, | ||
updated_at = .x$updated_at | ||
) | ||
}) | ||
} | ||
|
||
get_gh_issues <- function(owner, repo, labels) { | ||
get_gh_issues_raw(owner, repo, labels) %>% | ||
extract_issue_info() %>% | ||
dplyr::mutate( | ||
org = owner, | ||
repo = repo, | ||
full_repo = paste0(owner, "/", repo) | ||
) | ||
} | ||
|
||
keep_opted_in <- function(orgs) { | ||
|
||
# Repos that wish to opt in should be manually added here | ||
opt_in_repos <- tibble::tribble( | ||
~carpentries_org, ~repo, | ||
"carpentries-incubator", "hpc-intro", | ||
) | ||
|
||
dplyr::inner_join( | ||
orgs, opt_in_repos, | ||
by = c("carpentries_org", "repo") | ||
) | ||
} | ||
|
||
keep_hpc_carpentry_repos <- function(orgs) { | ||
dplyr::filter( | ||
orgs, carpentries_org == "hpc-carpentry" | ||
) | ||
} | ||
|
||
keep_other_repos <- function(orgs) { | ||
other_repos <- tibble::tribble( | ||
~carpentries_org, ~repo, | ||
"hpc-carpentry", "hpc-carpentry.github.io", | ||
) | ||
|
||
dplyr::inner_join( | ||
orgs, other_repos, | ||
by = c("carpentries_org", "repo") | ||
) | ||
} | ||
|
||
|
||
list_organizations <- c( | ||
"HPC Carpentry" = "hpc-carpentry", | ||
"The Carpentries Incubator" = "carpentries-incubator" | ||
) | ||
|
||
list_help_wanted <- purrr::imap_dfr( | ||
list_organizations, | ||
function(.x, .y) { | ||
orgs <- get_list_repos( | ||
.x, ignore_archived = TRUE, | ||
ignore_pattern = "^\\d{4}-\\d{2}-\\d{2}" | ||
) | ||
|
||
lessons <- orgs %>% | ||
keep_opted_in() | ||
|
||
hpc_carpentry_lessons <- orgs %>% | ||
keep_hpc_carpentry() | ||
|
||
other_repos <- orgs %>% | ||
keep_other_repos() | ||
|
||
dplyr::bind_rows( | ||
lessons, | ||
hpc_carpentry_lessons, | ||
other_repos | ||
) %>% | ||
dplyr::distinct(carpentries_org, repo, .keep_all = TRUE) %>% | ||
purrr::pmap_df(function(carpentries_org, repo, description, ...) { | ||
message(" repo: ", repo, appendLF = FALSE) | ||
res <- purrr::map_dfr( | ||
c("help wanted", "good first issue"), | ||
~ get_gh_issues( | ||
owner = carpentries_org, repo = repo, labels = .x | ||
) | ||
) %>% | ||
dplyr::distinct(url, .keep_all = TRUE) | ||
message(" -- n issues: ", nrow(res)) | ||
res %>% | ||
dplyr::mutate( | ||
description = description, | ||
## remove GitHub emoji from repo description | ||
clean_description = gsub(":([a-z0-9_]+):", "", description), | ||
org_name = .y) | ||
}) | ||
} | ||
) | ||
|
||
|
||
jsonlite::write_json(list_help_wanted, "_data/help_wanted_issues.json") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
source("R/utils.R") | ||
|
||
LIFE_CYCLE_TAGS <- c("pre-alpha", "alpha", "beta", "stable") | ||
# The tags below will be filtered out in the json | ||
COMMON_TAGS <- c( | ||
"carpentries", | ||
"carpentries-incubator", | ||
"carpentries-lesson", | ||
"carpentryconnect", | ||
"data-carpentry", | ||
"hpc-carpentry", | ||
"datacarpentry", | ||
"education", | ||
"lesson" | ||
) | ||
|
||
check_missing_repo_info <- function(.d, field) { | ||
if (any(!nzchar(.d[[field]]))) { | ||
paste0( | ||
"Missing repo ", sQuote(field), " for: \n", | ||
paste0(" - ", .d$repo_url[!nzchar(.d[[field]])], collapse = "\n"), | ||
"\n" | ||
) | ||
} | ||
} | ||
|
||
check_repo_info <- function(.d, fields) { | ||
tryCatch({ | ||
out <- purrr::map( | ||
fields, ~ check_missing_repo_info(.d, .) | ||
) | ||
msgs <- purrr::keep(out, ~ !is.null(.)) | ||
|
||
if (length(msgs)) { | ||
stop(msgs, call. = FALSE) | ||
} | ||
|
||
cli::cli_alert_success("No issues detected!") | ||
}, | ||
error = function(err) { | ||
stop(err$message, call. = FALSE) | ||
}) | ||
} | ||
|
||
make_community_lessons_feed <- function(path, ...) { | ||
|
||
carp_inc <- get_org_topics("carpentries-incubator") | ||
hpc_carp <- get_org_topics("hpc-carpentry") | ||
|
||
res <- dplyr::bind_rows(carp_inc, hpc_carp) %>% | ||
dplyr::select(-private) %>% | ||
dplyr::filter(grepl("hpc-carpentry", github_topics)) %>% | ||
dplyr::filter(grepl("lesson", github_topics)) %>% | ||
extract_tag( | ||
life_cycle_tag, | ||
LIFE_CYCLE_TAGS, | ||
approach = "include", | ||
allow_multiple = FALSE, | ||
allow_empty = FALSE | ||
) %>% | ||
extract_tag( | ||
lesson_tags, | ||
COMMON_TAGS, | ||
approach = "exclude", | ||
allow_multiple = TRUE, | ||
allow_empty = TRUE | ||
) | ||
|
||
## checks | ||
check_repo_info(res, c("description", "rendered_site")) | ||
|
||
res %>% | ||
jsonlite::write_json(path = path) | ||
|
||
} | ||
|
||
make_community_lessons_feed("_data/hpc_lessons.json") |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All ye who use HPC, take note of this awesome action!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is giving us R with over 900 packages installed in just over 30 seconds!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Super cool!