Repository navigation
Expand file tree
/
Copy pathprojects.qmd
More file actions
111 lines (99 loc) · 3.39 KB
/
Copy pathprojects.qmd
File metadata and controls
111 lines (99 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
---
title: "Projects"
description: |
Ongoing analysis projects from the group
---
Ongoing analysis and research projects from the group. For completed work, see our [publications](pubs.qmd). For reusable tools, see our [software](software.qmd).
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = FALSE, message = FALSE, warning = FALSE)
library(magrittr)
# Hide projects not updated in this many months (set to NULL to disable)
stale_months <- 12
```
```{r load-team}
# Load team members and create lookup by GitHub username
team <- fs::dir_ls("_data/team", regexp = "\\w+\\-\\w+\\.yml") |>
purrr::map(yaml::read_yaml)
team_by_github <- team %>%
purrr::keep(~ !is.null(.x$github) && .x$github != "") %>%
purrr::set_names(purrr::map_chr(., "github"))
```
```{r, results='asis'}
projects <- yaml::read_yaml("_data/projects.yml")
projects %>%
purrr::map(function(p) {
# Fetch repo info
repo_info <- tryCatch(
gh::gh("/repos/{repo}", repo = p$repo),
error = function(e) list(
name = basename(p$repo),
description = "No description available",
html_url = paste0("https://github.com/", p$repo),
language = NA,
stargazers_count = NA,
pushed_at = NA
)
)
# Fetch contributors
contributors <- tryCatch(
gh::gh("/repos/{repo}/contributors", repo = p$repo, per_page = 100),
error = function(e) list()
)
# Match contributors to team members
team_contributors <- contributors %>%
purrr::keep(~ .x$login %in% names(team_by_github)) %>%
purrr::map(function(c) {
tm <- team_by_github[[c$login]]
list(
name = tm$name,
github = c$login,
avatar_url = c$avatar_url,
contributions = c$contributions
)
})
list(
name = repo_info$name,
description = p$description %||% repo_info$description %||% "No description available",
url = p$url %||% repo_info$html_url,
repo = p$repo,
language = repo_info$language,
stars = repo_info$stargazers_count %||% 0,
updated = if (!is.null(repo_info$pushed_at)) substr(repo_info$pushed_at, 1, 10) else NA,
team_contributors = team_contributors
)
}) %>%
# Filter out stale projects
purrr::keep(~ !is.null(.x)) %>%
purrr::keep(~ {
if (is.null(stale_months) || is.na(.x$updated)) return(TRUE)
as.Date(.x$updated) > Sys.Date() - (stale_months * 30)
}) %>%
# Sort by stars descending
{ .[order(purrr::map_dbl(., "stars"), decreasing = TRUE)] } %>%
purrr::map_chr(function(e) {
# Format contributors section as raw markdown/HTML
contributors_section <- ""
if (length(e$team_contributors) > 0) {
contributor_items <- purrr::map_chr(e$team_contributors, function(c) {
sprintf(
'<a href="https://github.com/%s" title="%s"><img src="%s" alt="%s" width="32" height="32"></a>',
c$github, c$name, c$avatar_url, c$name
)
})
contributors_section <- paste(contributor_items, collapse = " ")
}
knitr::knit_expand(
"_project-item.Rmd",
name = e$name,
description = stringr::str_squish(e$description),
url = e$url,
repo = e$repo,
language = e$language %||% "",
stars = e$stars %||% "",
updated = e$updated %||% "",
contributors_section = contributors_section
)
}) %>%
{ knitr::knit_child(text = unlist(.), quiet = TRUE) } %>%
cat(sep = "\n")
```