Created
April 21, 2016 18:41
-
-
Save jimhester/1379efd654ff36b0a412cc919a830a0a to your computer and use it in GitHub Desktop.
Programmatically determine forks of a repo with at least n commits. Does not try to disambiguate repeated force pushes.
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
# Q on @GitHub: does anyone now how to easily (ie automatically) list all forks | |
# of a repository that have more than N commits in the fork? | |
library(gh) # devtools::install_github("gaborcsardi/gh") | |
forks_n_commits <- function(owner, repo, n = 1) { | |
events <- gh("GET /networks/:owner/:repo/events", owner = owner, repo = repo, .limit = Inf) | |
fork_pushes <- Filter(function(x) x$type == "PushEvent" && x$repo$name != paste0(owner, "/", repo), | |
events) | |
sizes <- vapply(fork_pushes, function(x) as.integer(x$payload$distinct_size), integer(1)) | |
repos <- vapply(fork_pushes, function(x) x$repo$name, character(1)) | |
res <- setNames(aggregate(sizes, by = list(repos), FUN = sum), nm = c("repo", "n")) | |
res[res$n > n, ] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I got the following to work as I wanted:
UPDATE: This can be simplified a ton by using the "compare two commits" API, which you can use to directly get the number of commits the fork is ahead/behind the source. Example: https://api.github.com/repos/daattali/beautiful-jekyll/compare/daattali:master...alexwhan:master look at the
ahead_by
andbehind_by
return values