Skip to content

Instantly share code, notes, and snippets.

@oreoshake
Last active June 14, 2020 19:41
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 oreoshake/65c52ac2ed0f91ca3afc011e968539a9 to your computer and use it in GitHub Desktop.
Save oreoshake/65c52ac2ed0f91ca3afc011e968539a9 to your computer and use it in GitHub Desktop.
A simple script to keep tabs on an organizations use of default branches. It requires a personal access token for private repos.
# End qualified immunity
# End cash bail
# Defund the police
# Invest in addiction treatment, education, and healthcare
#
# Donate: https://www.naacpldf.org/support/fiscal-responsibility/
#
# git branch -m master main
# git push -u origin main
# Change the default branch (and updated the protected branch)
# open https://github.com/<owner>/<repo>/settings/branches
require 'octokit'
client = Octokit::Client.new(access_token: ENV['GITHUB_TOKEN'], auto_paginate: true)
repos = client.org_repos("your_org_name_here").filter(&:archived?).group_by(&:default_branch)
counts = repos.map do |default_branch, repos|
[default_branch, repos.count]
end
sorted = counts.sort_by do |default_branch, count|
-count
end
puts
puts
puts
filtered = sorted.filter do |branch, count|
count <= 1
end
filtered.each do |branch, count|
puts [branch, "has", count, "repos"].join(" ")
end
name: stats
on:
push:
schedule:
- cron: '0 0 * * *' # Once per day at midnight
jobs:
stats:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Ruby
uses: actions/setup-ruby@v1
with:
ruby-version: 2.6
- name: Run script
run: |
gem install --no-document octokit
GITHUB_TOKEN=${{ secrets.PAT }} ruby stats.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment