Skip to content

Instantly share code, notes, and snippets.

@mrbobbytables
Last active January 26, 2021 12:52
Show Gist options
  • Save mrbobbytables/a3c36100a3c611845eaf8d4ad3ea9a96 to your computer and use it in GitHub Desktop.
Save mrbobbytables/a3c36100a3c611845eaf8d4ad3ea9a96 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# Copyright 2021 Google LLC.
# SPDX-License-Identifier: Apache-2.0
import os
import sys
import csv
from github import Github
if len(sys.argv) == 1:
print('No org specified')
sys.exit(1)
GITHUB_TOKEN = os.getenv('GITHUB_TOKEN')
if GITHUB_TOKEN == None:
print("Token not found.")
sys.exit(1)
repo_stats=[]
g = Github(GITHUB_TOKEN)
org = g.get_organization(sys.argv[1])
for repo in org.get_repos(type='all', sort='updated', direction='asc'):
try:
latest_commit = repo.get_commits()[0]
repo_stats.append([repo.name, repo.get_commit(sha=latest_commit.sha).last_modified])
except:
repo_stats.append([repo.name, 'Empty'])
with open(sys.argv[1]+'.csv', 'w', newline='') as file:
writer = csv.writer(file)
writer.writerows(repo_stats)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment