from github import Github from pymongo import MongoClient from credentials import access_token, organization_name, mongo_uri, mongo_db_name # MongoDB credentials collection_name = 'repositories' # Connect to GitHub g = Github(access_token) org = g.get_organization(organization_name) # Connect to MongoDB client = MongoClient(mongo_uri) db = client[mongo_db_name] collection = db[collection_name] # Get all repositories in the organization repos = org.get_repos() # Iterate through repositories for repo in repos: # Get contributors contributors = repo.get_contributors() contributors_count = contributors.totalCount # Get commits commits = repo.get_commits() total_commits = commits.totalCount languages_used = repo.get_languages() repo_info = { 'name': repo.name, 'full_name': repo.full_name, 'description': repo.description, 'created_at': repo.created_at, 'updated_at': repo.updated_at, 'html_url': repo.html_url, 'clone_url': repo.clone_url, 'language': repo.language, 'forks_count': repo.forks_count, 'stargazers_count': repo.stargazers_count, 'watchers_count': repo.watchers_count, 'default_branch': repo.default_branch, 'open_issues_count': repo.open_issues_count, 'total_issues_count': len(repo.get_issues()), 'size': repo.size, 'license': getattr(repo.license, 'name', None), 'contributors_count': contributors_count, 'total_commits': total_commits, } # Insert repository information into MongoDB collection.insert_one(repo_info) # Close MongoDB connection client.close()