Skip to content

Instantly share code, notes, and snippets.

@jhollist
Last active June 20, 2017 05:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jhollist/d8fab495a6b8663a075898f426155ec5 to your computer and use it in GitHub Desktop.
Save jhollist/d8fab495a6b8663a075898f426155ec5 to your computer and use it in GitHub Desktop.
# Got too many private repos in a GitHub Organization?
# This will list all of the private repos you have access to and rank them by
# days since last push and total number of commits.
# Add PAT to .Renviron - mine is obscured
# cat("GITHUB_PAT=yourowngithubpatgoeshere\n",
# file=file.path(normalizePath("~/"), ".Renviron"),
# append=TRUE)
# Install gh pacakge from github
# devtools::install_github("r-lib/gh")
library(gh)
library(dplyr)
library(lubridate)
# Want a data frame that lists repo, repo URL, date created, date last updated,
# days since last updated, number of commits.
# A function to count number of commits
count_commits <- function(gh_response_item){
endp <- paste("/repos",
gh_response_item$owner$login,
gh_response_item$name,
"commits", sep = "/")
gh_r <- gh(endp)
length(gh_r)
}
private_repos <- gh("/orgs/usepa/repos", type = "private")
names <- unlist(lapply(private_repos, function(x) x$name))
owners <- unlist(lapply(private_repos, function(x) x$owner$login))
urls <- unlist(lapply(private_repos, function(x) x$html_url))
created <- unlist(lapply(private_repos, function(x) x$created_at)) %>%
ymd_hms() %>%
format("%Y-%m-%d") %>%
as.Date()
updated <- unlist(lapply(private_repos, function(x) x$pushed_at)) %>%
ymd_hms() %>%
format("%Y-%m-%d") %>%
as.Date()
num_commits <- unlist(lapply(private_repos, function(x) count_commits(x)))
private_repo_stats <- data.frame(repo = names,
#url = urls,
date_created = created,
date_last_push = updated,
days_since_updated = as.numeric(today() - updated),
number_commits = num_commits) %>%
arrange(desc(days_since_updated), number_commits)
# > private_repo_stats
# repo date_created date_last_push days_since_updated number_commits
# 1 NBH_PCB 2015-06-04 2015-06-04 746 1
# 2 401C 2015-07-14 2016-12-19 182 30
# 3 cyano_open_sci_aag 2017-03-24 2017-04-04 76 19
# 4 lakemorpho_manuscript 2017-05-23 2017-06-09 10 8
# 5 reproducible_lakes 2017-06-13 2017-06-19 0 6
# 6 cyano_space_time 2017-05-01 2017-06-19 0 17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment