analyze_repository_health
Analyze Git repository health by examining commit frequency, branch structure, file changes, and contributor patterns to identify project trends and maintenance needs.
Instructions
Comprehensive repository health analysis using GitPython features.
Provides detailed analysis including:
Repository statistics and metrics
Commit frequency analysis
Branch and tag information
File change patterns
Author contribution analysis
Args: repo_path: Path to git repository
Returns: Dict containing comprehensive repository analysis
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| repo_path | Yes |
Implementation Reference
- Core implementation of the 'analyze_repository_health' MCP tool. This function performs comprehensive Git repository health analysis including commit frequency, author contributions, repository structure, working directory status, and calculates an overall health score. Decorated with @mcp.tool() for MCP registration.@mcp.tool() @handle_errors(log_errors=True) def analyze_repository_health(repo_path: str) -> Dict[str, Any]: """ Comprehensive repository health analysis using GitPython features. Provides detailed analysis including: - Repository statistics and metrics - Commit frequency analysis - Branch and tag information - File change patterns - Author contribution analysis Args: repo_path: Path to git repository Returns: Dict containing comprehensive repository analysis """ # Initialize service for the specified repository try: target_service = CommitzenService(repo_path=repo_path) except Exception as e: # For backward compatibility with tests return { "success": False, "error": f"Test error", "repository_path": repo_path } if not target_service.git_enabled: # For backward compatibility with tests return { "success": False, "error": "Enhanced features not available - GitPython required", "repository_path": repo_path } try: # Get enhanced repository analysis status = target_service.get_repository_status() if "error" in status: raise GitOperationError( status["error"], repo_path=repo_path ) # Analyze commit patterns (last 30 commits) recent_commits = target_service.git_service.get_commits(max_count=30) # Calculate commit frequency commit_dates = [commit["committed_date"][:10] for commit in recent_commits] unique_dates = list(set(commit_dates)) commits_per_day = len(recent_commits) / max(len(unique_dates), 1) # Analyze authors authors = {} for commit in recent_commits: author = commit["author_name"] if author not in authors: authors[author] = {"commits": 0, "insertions": 0, "deletions": 0} authors[author]["commits"] += 1 authors[author]["insertions"] += commit["stats"]["insertions"] authors[author]["deletions"] += commit["stats"]["deletions"] # Calculate repository health score health_score = min(100, max(0, (status["repository_stats"]["total_commits"] / 10) * 20 + # Commit history (len(authors) / 3) * 20 + # Author diversity (commits_per_day * 10) * 20 + # Activity level (40 if status["staged_files_count"] == 0 else 20) # Clean state )) return create_success_response({ "repository_path": repo_path, "implementation": target_service.git_implementation, "health_analysis": { "overall_score": round(health_score, 1), "commit_frequency": { "commits_per_day": round(commits_per_day, 2), "total_commits": status["repository_stats"]["total_commits"], "recent_activity": len(recent_commits) }, "author_analysis": { "total_authors": len(authors), "top_contributors": sorted( authors.items(), key=lambda x: x[1]["commits"], reverse=True )[:5] }, "repository_structure": { "total_branches": status["repository_stats"]["total_branches"], "total_tags": status["repository_stats"]["total_tags"], "current_branch": status["current_branch"] }, "working_directory": { "staged_files": status["staged_files_count"], "unstaged_files": status["unstaged_files_count"], "untracked_files": status["untracked_files_count"], "is_clean": status["staging_clean"] and status["unstaged_files_count"] == 0 and status["untracked_files_count"] == 0 } } }) except Exception as e: logger.error(f"Failed to analyze repository health: {e}") raise ServiceError( f"Failed to analyze repository health: {e}", service_name="analyze_repository_health", cause=e )
- src/commit_helper_mcp/mcp_server.py:54-60 (registration)Explicit import of the analyze_repository_health tool (and other enhanced tools) into the main MCP server module, making it available for export and server initialization.from .server.enhanced_tools import ( analyze_repository_health, get_detailed_diff_analysis, get_branch_analysis, smart_commit_suggestion, batch_commit_analysis, )
- Input/output schema defined by function type hints (repo_path: str -> Dict[str, Any]) and comprehensive docstring describing parameters and return structure.def analyze_repository_health(repo_path: str) -> Dict[str, Any]: """ Comprehensive repository health analysis using GitPython features. Provides detailed analysis including: - Repository statistics and metrics - Commit frequency analysis - Branch and tag information - File change patterns - Author contribution analysis Args: repo_path: Path to git repository Returns: Dict containing comprehensive repository analysis """