import os
from collections import Counter
from graph_sitter import Codebase
from graph_sitter.extensions.attribution.main import add_attribution_to_symbols
from graph_sitter.git.repo_operator.repo_operator import RepoOperator
from graph_sitter.git.schemas.repo_config import RepoConfig
from graph_sitter.sdk.codebase.config import ProjectConfig
from graph_sitter.shared.enums.programming_language import ProgrammingLanguage
def analyze_contributors(codebase):
"""Analyze contributors to the codebase and their impact."""
print("\n🔍 Contributor Analysis:")
# Define which authors are considered AI
ai_authors = ['devin[bot]', 'graph-sitter[bot]', 'github-actions[bot]', 'dependabot[bot]']
# Add attribution information to all symbols
print("Adding attribution information to symbols...")
add_attribution_to_symbols(codebase, ai_authors)
# Collect statistics about contributors
contributor_stats = Counter()
ai_contributor_stats = Counter()
print("Analyzing symbol attributions...")
for symbol in codebase.symbols:
if hasattr(symbol, 'last_editor') and symbol.last_editor:
contributor_stats[symbol.last_editor] += 1
# Track if this is an AI contributor
if any(ai in symbol.last_editor for ai in ai_authors):
ai_contributor_stats[symbol.last_editor] += 1
# Print top contributors overall
print("\n👥 Top Contributors by Symbols Authored:")
for contributor, count in contributor_stats.most_common(10):
is_ai = any(ai in contributor for ai in ai_authors)
ai_indicator = "🤖" if is_ai else "👤"
print(f" {ai_indicator} {contributor}: {count} symbols")
# Print top AI contributors if any
if ai_contributor_stats:
print("\n🤖 Top AI Contributors:")
for contributor, count in ai_contributor_stats.most_common(5):
print(f" • {contributor}: {count} symbols")
# Initialize codebase from current directory
if os.path.exists(".git"):
repo_path = os.getcwd()
repo_config = RepoConfig.from_repo_path(repo_path)
repo_operator = RepoOperator(repo_config=repo_config)
project = ProjectConfig.from_repo_operator(
repo_operator=repo_operator,
programming_language=ProgrammingLanguage.PYTHON
)
codebase = Codebase(projects=[project])
# Run the contributor analysis
analyze_contributors(codebase)