Created
October 11, 2023 12:15
-
-
Save vanatteveldt/81ca4e6bedb16b428316aef75b53a878 to your computer and use it in GitHub Desktop.
This file contains 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
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