Last active
June 14, 2020 19:41
-
-
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.
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
# 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 |
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
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