Skip to content

Instantly share code, notes, and snippets.

@vanatteveldt
Created October 11, 2023 12:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vanatteveldt/81ca4e6bedb16b428316aef75b53a878 to your computer and use it in GitHub Desktop.
Save vanatteveldt/81ca4e6bedb16b428316aef75b53a878 to your computer and use it in GitHub Desktop.
library(gh)
library(tidyverse)
get_all_pages <- function(url, ...) {
result <- list()
for (page in 1:99999) {
message(str_c("[", page, "] ", do.call(glue::glue, list(url, ...))))
p <- gh(url, ..., page=page)
if (length(p) == 0) break
result[[as.character(page)]] <- p
}
unlist(result, recursive = FALSE)
}
parse_commit = function(commit) {
tibble(login=commit$committer$login,
message=commit$commit$message,
date=commit$commit$committer$date)
}
get_all_commits <- function(repo) {
get_all_pages("GET /repos/{repo}/commits", repo=repo) |>
map(parse_commit) |>
list_rbind() |>
add_column(repo=repo, .before = 1)
}
get_repos <- function(username) {
get_all_pages("GET /users/{username}/repos", username=username) |>
map_chr(\(repo) str_c(username, "/", repo$name))
}
repos <- map(c("vanatteveldt", "ccs-amsterdam"), get_repos) |>list_c()
users = c("vanatteveldt", "ccs-amsterdam")
commits <- users |>
map(get_repos) |>
list_c() |>
map(get_all_commits) |>
list_rbind()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment