Last active
March 24, 2022 15:19
-
-
Save SeanFromIT/83d5b429e613bbe1154dcdd1cd530623 to your computer and use it in GitHub Desktop.
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
import github3, os, subprocess | |
#Also requires gh CLI && gh extension install geoffreywiseman/gh-actuse | |
# You must create this admin auth-token at https://github.com/settings/tokens with admin:org permissions | |
# You must authorize for each & every org by clicking the Enable/Disable SSO button-Authorize | |
# Export it as env var GH_PAT | |
token = os.getenv('GH_PAT') | |
g = github3.login(token=token) | |
#Connect to our orgs | |
my_org = g.organization("myorg") | |
repos = list(my_org.repositories(type="all")) | |
for repo in repos: | |
cmd = 'gh actuse ' + str(repo) | |
try: | |
results = subprocess.run(cmd, shell=True, check=True, capture_output=True, text=True) | |
cmdOutput = results.stdout | |
except subprocess.CalledProcessError as e: | |
print(e) | |
continue | |
usage = 0 | |
for line in cmdOutput.split("\n"): | |
if "Repo Total Usage" in line: | |
print(line) | |
usage = line[20:] | |
##process/output accordingly... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment