Skip to content

Instantly share code, notes, and snippets.

@karawoo
Created October 28, 2019 20:48
Show Gist options
  • Save karawoo/3d181d80063fe620de2b24ab049b51f3 to your computer and use it in GitHub Desktop.
Save karawoo/3d181d80063fe620de2b24ab049b51f3 to your computer and use it in GitHub Desktop.
Count number of code reviews on a repo
############################################
#### Calculate number of code reviews ####
############################################
## Needs a GitHub PAT or you'll hit rate limiting
library("gh")
library("purrr")
library("glue")
## Get all PRs to the repo
dccvalidator_prs <- gh(
"/repos/Sage-Bionetworks/dccvalidator/pulls",
state = "all",
.limit = 100
)
## Get the PR number of each
pr_numbers <- map_chr(dccvalidator_prs, function(x) x$number)
## Get all the reviews from each PR
get_reviews <- function(pr_number) {
reviews <- gh(
glue("/repos/Sage-Bionetworks/dccvalidator/pulls/{pr_number}/reviews")
)
}
## Get all reviews from all PRs in the repo
reviews <- map(pr_numbers, get_reviews)
## Only count "approved" and "changes requested" for now; otherwise each inline
## comment gets counted as its own review
get_review_count <- function(reviews) {
accept_reject <- map_lgl(
reviews,
function(x) {
result <- try(
x$state %in% c("APPROVED", "CHANGES_REQUESTED"),
silent = TRUE
)
if (inherits(result, "try-error")) {
result <- FALSE
}
result
}
)
length(reviews[accept_reject])
}
## Count reviews
sum(map_dbl(reviews, get_review_count))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment