Created
July 6, 2020 18:00
-
-
Save drakedevel/8133fc0906e3afb861c9c288b7ebb12d to your computer and use it in GitHub Desktop.
Generates a per-workflow report of billable GitHub actions usage in the last few days for an organization
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
from collections import Counter | |
from datetime import datetime, timedelta | |
from github import Github | |
API_KEY = '...' | |
CUTOFF = datetime.now() - timedelta(days=5) | |
ORGANIZATION = '...' | |
def analyze_repo(repo): | |
print(f'{repo.name}:') | |
for workflow in repo.get_workflows(): | |
print(f' {workflow.name}:') | |
totals = Counter() | |
for run in workflow.get_runs(): | |
if run.created_at < CUTOFF: | |
break | |
timing = run.timing() | |
for (platform, usage) in timing.billable.items(): | |
totals[platform] += usage['total_ms'] | |
for platform, total_ms in totals.items(): | |
total = timedelta(seconds=total_ms / 1e3) | |
print(f' {platform}: {total}') | |
def main(): | |
gh = Github(API_KEY) | |
front = gh.get_organization(ORGANIZATION) | |
repos = front.get_repos(type='private', sort='updated', direction='desc') | |
for repo in repos: | |
if repo.updated_at < CUTOFF: | |
break | |
analyze_repo(repo) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment