tenets.core.git
Package¶
Git integration package.
This package provides comprehensive git repository analysis capabilities including repository metrics, blame analysis, history chronicling, and statistical insights. It extracts valuable context from version control history to understand code evolution, team dynamics, and development patterns.
The git package enables tenets to leverage version control information for better context building, all without requiring any external API calls.
Main components: - GitAnalyzer: Core git repository analyzer - BlameAnalyzer: Line-by-line authorship tracking - Chronicle: Repository history narrative generator - GitStatsAnalyzer: Comprehensive repository statistics
Example usage
from tenets.core.git import GitAnalyzer from tenets.config import TenetsConfig
config = TenetsConfig() analyzer = GitAnalyzer(config)
Get recent commits¶
commits = analyzer.get_recent_commits(limit=10) for commit in commits: print(f"{commit['sha']}: {commit['message']}")
Analyze repository statistics¶
from tenets.core.git import analyze_git_stats stats = analyze_git_stats(Path(".")) print(f"Health score: {stats.health_score}")
Classes¶
CommitInfodataclass
¶
GitAnalyzer¶
Attributes¶
rootinstance-attribute
¶
repoinstance-attribute
¶
Functions¶
is_repo¶
is_git_repo¶
Return True if the given path (or current root) is inside a git repo.
If a path is provided, update internal root and repo accordingly.
changed_files¶
get_recent_commits¶
get_recent_commits(path: Optional[Path] = None, limit: int = 10, files: Optional[List[str]] = None) -> List[Dict[str, Any]]
Return recent commits as dictionaries suitable for formatting.
Each item contains: sha, author, email, message, date (ISO date string).
get_contributors¶
get_contributors(path: Optional[Path] = None, files: Optional[List[str]] = None, limit: int = 20) -> List[Dict[str, Any]]
Return contributors with commit counts.
Returns a list of dicts: { name, email, commits } sorted by commits desc.
get_current_branch¶
Return current branch name, or 'HEAD' when detached/unknown.
current_branch¶
Alias for get_current_branch() for backward compatibility.
get_tracked_files¶
Return list of tracked files in the repository.
get_file_history¶
Return commit history for a specific file.
get_changes_since¶
get_changes_since(path: Optional[Path] = None, since: str = '1 week ago', files: Optional[List[str]] = None) -> List[Dict[str, Any]]
Return a lightweight list of changes since a given time.
Each item contains: sha, message, date.
get_commits_since¶
get_commits_since(since: datetime, max_count: int = 1000, author: Optional[str] = None, branch: Optional[str] = None, include_merges: bool = True) -> List[Any]
Return raw commit objects since a given datetime.
PARAMETER | DESCRIPTION |
---|---|
since | Start datetime (inclusive) TYPE: |
max_count | Maximum number of commits TYPE: |
author | Optional author filter |
branch | Optional branch name |
include_merges | Whether to include merge commits TYPE: |
RETURNS | DESCRIPTION |
---|---|
List[Any] | List of GitPython commit objects |
get_commits¶
get_commits(since: Optional[datetime] = None, until: Optional[datetime] = None, max_count: int = 1000, author: Optional[str] = None, branch: Optional[str] = None) -> List[Dict[str, Any]]
Return commits between two dates.
This method was missing and called by momentum.py.
PARAMETER | DESCRIPTION |
---|---|
since | Start datetime (inclusive) |
until | End datetime (exclusive) |
max_count | Maximum number of commits TYPE: |
author | Optional author filter |
branch | Optional branch name |
RETURNS | DESCRIPTION |
---|---|
List[Dict[str, Any]] | List of commit dictionaries with standard fields |
recent_commits¶
blame¶
Return list of (author, line) for a file using git blame.
BlameAnalyzer¶
Analyzer for git blame operations.
Provides line-by-line authorship analysis using git blame, helping understand code ownership and evolution patterns.
ATTRIBUTE | DESCRIPTION |
---|---|
config | Configuration object |
logger | Logger instance |
_blame_cache | Cache for blame results |
Initialize blame analyzer.
PARAMETER | DESCRIPTION |
---|---|
config | TenetsConfig instance TYPE: |
Attributes¶
configinstance-attribute
¶
loggerinstance-attribute
¶
Functions¶
analyze_file¶
analyze_file(repo_path: Path, file_path: str, ignore_whitespace: bool = True, follow_renames: bool = True) -> FileBlame
Analyze blame for a single file.
Performs git blame analysis on a file to understand line-by-line authorship.
PARAMETER | DESCRIPTION |
---|---|
repo_path | Path to git repository TYPE: |
file_path | Path to file relative to repo root TYPE: |
ignore_whitespace | Ignore whitespace changes TYPE: |
follow_renames | Follow file renames TYPE: |
RETURNS | DESCRIPTION |
---|---|
FileBlame | Blame analysis for the file TYPE: |
Example
analyzer = BlameAnalyzer(config) blame = analyzer.analyze_file(Path("."), "src/main.py") print(f"Primary author: {blame.primary_author}")
analyze_directory¶
analyze_directory(repo_path: Path, directory: str = '.', file_pattern: str = '*', recursive: bool = True, max_files: int = 100) -> BlameReport
Analyze blame for all files in a directory.
Performs comprehensive blame analysis across multiple files to understand ownership patterns.
PARAMETER | DESCRIPTION |
---|---|
repo_path | Path to git repository TYPE: |
directory | Directory to analyze TYPE: |
file_pattern | File pattern to match TYPE: |
recursive | Whether to recurse into subdirectories TYPE: |
max_files | Maximum files to analyze TYPE: |
RETURNS | DESCRIPTION |
---|---|
BlameReport | Comprehensive blame analysis TYPE: |
Example
analyzer = BlameAnalyzer(config) report = analyzer.analyze_directory( ... Path("."), ... directory="src", ... file_pattern="*.py" ... ) print(f"Bus factor: {report.bus_factor}")
get_line_history¶
get_line_history(repo_path: Path, file_path: str, line_number: int, max_depth: int = 10) -> List[Dict[str, Any]]
Get history of changes for a specific line.
Traces the evolution of a specific line through git history.
PARAMETER | DESCRIPTION |
---|---|
repo_path | Path to git repository TYPE: |
file_path | Path to file TYPE: |
line_number | Line number to trace TYPE: |
max_depth | Maximum history depth to retrieve TYPE: |
RETURNS | DESCRIPTION |
---|---|
List[Dict[str, Any]] | List[Dict[str, Any]]: History of line changes |
Example
analyzer = BlameAnalyzer(config) history = analyzer.get_line_history( ... Path("."), ... "src/main.py", ... 42 ... ) for change in history: ... print(f"{change['date']}: {change['author']}")
BlameLinedataclass
¶
BlameLine(line_number: int, content: str, author: str, author_email: str, commit_sha: str, commit_date: datetime, commit_message: str, is_original: bool = False, age_days: int = 0, previous_authors: List[str] = list())
Information for a single line from git blame.
Represents authorship information for a specific line of code, including who wrote it, when, and in which commit.
ATTRIBUTE | DESCRIPTION |
---|---|
line_number | Line number in file TYPE: |
content | Content of the line TYPE: |
author | Author name TYPE: |
author_email | Author email TYPE: |
commit_sha | Commit SHA that introduced this line TYPE: |
commit_date | Date when line was introduced TYPE: |
commit_message | Commit message (first line) TYPE: |
is_original | Whether this is from the original commit TYPE: |
age_days | Age of the line in days TYPE: |
previous_authors | List of previous authors if line was modified |
Attributes¶
line_numberinstance-attribute
¶
contentinstance-attribute
¶
authorinstance-attribute
¶
author_emailinstance-attribute
¶
commit_shainstance-attribute
¶
commit_dateinstance-attribute
¶
commit_messageinstance-attribute
¶
is_originalclass-attribute
instance-attribute
¶
age_daysclass-attribute
instance-attribute
¶
previous_authorsclass-attribute
instance-attribute
¶
is_recentproperty
¶
Check if line was recently modified.
RETURNS | DESCRIPTION |
---|---|
bool | True if modified within last 30 days TYPE: |
BlameReportdataclass
¶
BlameReport(files_analyzed: int = 0, total_lines: int = 0, total_authors: int = 0, file_blames: Dict[str, FileBlame] = dict(), author_summary: Dict[str, Dict[str, Any]] = dict(), ownership_distribution: Dict[str, float] = dict(), collaboration_matrix: Dict[Tuple[str, str], int] = dict(), knowledge_map: Dict[str, Set[str]] = dict(), recommendations: List[str] = list(), hot_files: List[Dict[str, Any]] = list(), single_author_files: List[str] = list(), abandoned_code: Dict[str, int] = dict(), _bus_factor_override: Optional[int] = None, _collab_score_override: Optional[float] = None)
Comprehensive blame analysis report.
Provides detailed authorship analysis across multiple files, identifying ownership patterns, knowledge distribution, and collaboration insights.
ATTRIBUTE | DESCRIPTION |
---|---|
files_analyzed | Number of files analyzed TYPE: |
total_lines | Total lines analyzed TYPE: |
total_authors | Total unique authors TYPE: |
file_blames | Blame data for each file |
author_summary | Summary statistics per author |
ownership_distribution | How ownership is distributed |
collaboration_matrix | Who modified whose code |
knowledge_map | Knowledge areas per author |
recommendations | Actionable recommendations |
hot_files | Files with most contributors |
single_author_files | Files with only one author |
abandoned_code | Code from inactive authors |
Attributes¶
files_analyzedclass-attribute
instance-attribute
¶
total_linesclass-attribute
instance-attribute
¶
total_authorsclass-attribute
instance-attribute
¶
file_blamesclass-attribute
instance-attribute
¶
author_summaryclass-attribute
instance-attribute
¶
ownership_distributionclass-attribute
instance-attribute
¶
collaboration_matrixclass-attribute
instance-attribute
¶
knowledge_mapclass-attribute
instance-attribute
¶
recommendationsclass-attribute
instance-attribute
¶
hot_filesclass-attribute
instance-attribute
¶
single_author_filesclass-attribute
instance-attribute
¶
abandoned_codeclass-attribute
instance-attribute
¶
bus_factorproperty
writable
¶
Calculate bus factor based on blame data.
RETURNS | DESCRIPTION |
---|---|
int | Bus factor (number of critical authors) TYPE: |
collaboration_scoreproperty
writable
¶
Calculate collaboration score.
Higher scores indicate more collaborative development.
RETURNS | DESCRIPTION |
---|---|
float | Collaboration score (0-100) TYPE: |
Functions¶
FileBlamedataclass
¶
FileBlame(file_path: str, total_lines: int = 0, blame_lines: List[BlameLine] = list(), authors: Set[str] = set(), author_stats: Dict[str, Dict[str, Any]] = dict(), commit_shas: Set[str] = set(), oldest_line: Optional[BlameLine] = None, newest_line: Optional[BlameLine] = None, age_distribution: Dict[str, int] = dict(), ownership_map: Dict[str, List[Tuple[int, int]]] = dict(), hot_spots: List[Tuple[int, int]] = list())
Blame information for an entire file.
Aggregates line-by-line blame information to provide file-level authorship insights and ownership patterns.
ATTRIBUTE | DESCRIPTION |
---|---|
file_path | Path to the file TYPE: |
total_lines | Total number of lines TYPE: |
blame_lines | List of blame information per line |
authors | Set of unique authors |
author_stats | Statistics per author |
commit_shas | Set of unique commits |
oldest_line | Oldest line in file |
newest_line | Newest line in file |
age_distribution | Distribution of line ages |
ownership_map | Line ranges owned by each author |
hot_spots | Lines that changed frequently |
Attributes¶
file_pathinstance-attribute
¶
total_linesclass-attribute
instance-attribute
¶
blame_linesclass-attribute
instance-attribute
¶
authorsclass-attribute
instance-attribute
¶
author_statsclass-attribute
instance-attribute
¶
commit_shasclass-attribute
instance-attribute
¶
oldest_lineclass-attribute
instance-attribute
¶
newest_lineclass-attribute
instance-attribute
¶
age_distributionclass-attribute
instance-attribute
¶
ownership_mapclass-attribute
instance-attribute
¶
hot_spotsclass-attribute
instance-attribute
¶
primary_authorproperty
¶
author_diversityproperty
¶
Calculate author diversity score.
Higher scores indicate more distributed authorship.
RETURNS | DESCRIPTION |
---|---|
float | Diversity score (0-1) TYPE: |
Chronicle¶
Main chronicle analyzer for git repositories.
Analyzes git history to create a narrative view of repository evolution, identifying patterns, trends, and significant events.
ATTRIBUTE | DESCRIPTION |
---|---|
config | Configuration object |
logger | Logger instance |
git_analyzer | Git analyzer instance TYPE: |
Initialize chronicle analyzer.
PARAMETER | DESCRIPTION |
---|---|
config | TenetsConfig instance TYPE: |
Attributes¶
configinstance-attribute
¶
loggerinstance-attribute
¶
git_analyzerinstance-attribute
¶
Functions¶
analyze¶
analyze(repo_path: Path, since: Optional[str] = None, until: Optional[str] = None, author: Optional[str] = None, branch: Optional[str] = None, include_merges: bool = True, include_stats: bool = True, max_commits: int = 1000) -> ChronicleReport
Analyze repository history and create chronicle report.
Creates a comprehensive narrative of repository evolution including commits, contributors, trends, and significant events.
PARAMETER | DESCRIPTION |
---|---|
repo_path | Path to git repository TYPE: |
since | Start date or relative time (e.g., "2 weeks ago") |
until | End date or relative time |
author | Filter by specific author |
branch | Specific branch to analyze |
include_merges | Whether to include merge commits TYPE: |
include_stats | Whether to include detailed statistics TYPE: |
max_commits | Maximum commits to analyze TYPE: |
RETURNS | DESCRIPTION |
---|---|
ChronicleReport | Comprehensive chronicle analysis TYPE: |
Example
chronicle = Chronicle(config) report = chronicle.analyze( ... Path("."), ... since="1 month ago", ... include_stats=True ... ) print(report.summary)
ChronicleBuilder¶
High-level builder that assembles a simple chronicle dict for CLI.
This composes the existing Chronicle and GitAnalyzer without duplicating analysis logic. It converts inputs to what Chronicle expects and returns a compact, CLI-friendly dictionary.
The CLI tests patch this class, but we provide a functional default for real usage.
Attributes¶
configinstance-attribute
¶
loggerinstance-attribute
¶
Functions¶
build_chronicle¶
build_chronicle(repo_path: Path, *, since: Optional[object] = None, until: Optional[object] = None, branch: Optional[str] = None, authors: Optional[List[str]] = None, include_merges: bool = True, limit: Optional[int] = None) -> Dict[str, Any]
Build a chronicle summary for the given repository.
PARAMETER | DESCRIPTION |
---|---|
repo_path | Path to a git repository TYPE: |
since | Start time (datetime or relative/ISO string) |
until | End time (datetime or relative/ISO string) |
branch | Branch name to analyze |
authors | Optional author filters (currently advisory) |
include_merges | Include merge commits TYPE: |
limit | Max commits to analyze (advisory to Chronicle) |
RETURNS | DESCRIPTION |
---|---|
Dict[str, Any] | A dictionary with keys expected by the CLI views. |
ChronicleReportdataclass
¶
ChronicleReport(period_start: datetime, period_end: datetime, total_commits: int = 0, total_contributors: int = 0, commits: List[CommitSummary] = list(), daily_activity: List[DayActivity] = list(), contributor_stats: Dict[str, Dict[str, Any]] = dict(), commit_type_distribution: Dict[str, int] = dict(), file_change_frequency: List[Tuple[str, int]] = list(), hot_periods: List[Dict[str, Any]] = list(), quiet_periods: List[Dict[str, Any]] = list(), significant_events: List[Dict[str, Any]] = list(), trends: List[str] = list(), summary: str = '')
Comprehensive chronicle report of repository history.
Provides a complete narrative view of repository evolution including commits, contributors, trends, and significant events.
ATTRIBUTE | DESCRIPTION |
---|---|
period_start | Start of chronicle period TYPE: |
period_end | End of chronicle period TYPE: |
total_commits | Total commits in period TYPE: |
total_contributors | Total unique contributors TYPE: |
commits | List of commit summaries TYPE: |
daily_activity | Daily activity breakdown TYPE: |
contributor_stats | Statistics by contributor |
commit_type_distribution | Distribution of commit types |
file_change_frequency | Most frequently changed files |
hot_periods | Periods of high activity |
quiet_periods | Periods of low activity |
significant_events | Notable events (releases, major changes) |
trends | Identified trends in development |
summary | Executive summary of the period TYPE: |
Attributes¶
period_startinstance-attribute
¶
period_endinstance-attribute
¶
total_commitsclass-attribute
instance-attribute
¶
total_contributorsclass-attribute
instance-attribute
¶
commitsclass-attribute
instance-attribute
¶
daily_activityclass-attribute
instance-attribute
¶
contributor_statsclass-attribute
instance-attribute
¶
commit_type_distributionclass-attribute
instance-attribute
¶
file_change_frequencyclass-attribute
instance-attribute
¶
hot_periodsclass-attribute
instance-attribute
¶
quiet_periodsclass-attribute
instance-attribute
¶
significant_eventsclass-attribute
instance-attribute
¶
trendsclass-attribute
instance-attribute
¶
summaryclass-attribute
instance-attribute
¶
most_active_dayproperty
¶
Get the most active day.
RETURNS | DESCRIPTION |
---|---|
Optional[DayActivity] | Optional[DayActivity]: Most active day or None |
activity_levelproperty
¶
Determine overall activity level.
RETURNS | DESCRIPTION |
---|---|
str | Activity level (high, moderate, low) TYPE: |
Functions¶
CommitSummarydataclass
¶
CommitSummary(sha: str, author: str, email: str, date: datetime, message: str, files_changed: int = 0, lines_added: int = 0, lines_removed: int = 0, is_merge: bool = False, is_revert: bool = False, tags: List[str] = list(), branch: Optional[str] = None, issue_refs: List[str] = list(), pr_refs: List[str] = list())
Summary information for a single commit.
Provides a concise representation of a commit with key information for historical analysis and reporting.
ATTRIBUTE | DESCRIPTION |
---|---|
sha | Commit SHA (short form) TYPE: |
author | Commit author name TYPE: |
email | Author email TYPE: |
date | Commit date TYPE: |
message | Commit message (first line) TYPE: |
files_changed | Number of files changed TYPE: |
lines_added | Lines added TYPE: |
lines_removed | Lines removed TYPE: |
is_merge | Whether this is a merge commit TYPE: |
is_revert | Whether this is a revert commit TYPE: |
tags | Associated tags |
branch | Branch name if available |
issue_refs | Referenced issue numbers |
pr_refs | Referenced PR numbers |
Attributes¶
shainstance-attribute
¶
authorinstance-attribute
¶
emailinstance-attribute
¶
dateinstance-attribute
¶
messageinstance-attribute
¶
files_changedclass-attribute
instance-attribute
¶
lines_addedclass-attribute
instance-attribute
¶
lines_removedclass-attribute
instance-attribute
¶
is_mergeclass-attribute
instance-attribute
¶
is_revertclass-attribute
instance-attribute
¶
tagsclass-attribute
instance-attribute
¶
branchclass-attribute
instance-attribute
¶
issue_refsclass-attribute
instance-attribute
¶
pr_refsclass-attribute
instance-attribute
¶
net_linesproperty
¶
Calculate net lines changed.
RETURNS | DESCRIPTION |
---|---|
int | Lines added minus lines removed TYPE: |
commit_typeproperty
¶
Determine commit type from message.
RETURNS | DESCRIPTION |
---|---|
str | Commit type (feat, fix, docs, etc.) TYPE: |
Functions¶
DayActivitydataclass
¶
DayActivity(date: datetime, commits: List[CommitSummary] = list(), total_commits: int = 0, unique_authors: Set[str] = set(), lines_added: int = 0, lines_removed: int = 0, files_touched: Set[str] = set(), commit_types: Dict[str, int] = dict(), peak_hour: Optional[int] = None, first_commit_time: Optional[datetime] = None, last_commit_time: Optional[datetime] = None)
Activity summary for a single day.
Aggregates all repository activity for a specific day to provide daily development rhythm insights.
ATTRIBUTE | DESCRIPTION |
---|---|
date | Date of activity TYPE: |
commits | List of commits on this day TYPE: |
total_commits | Total commit count TYPE: |
unique_authors | Set of unique authors |
lines_added | Total lines added TYPE: |
lines_removed | Total lines removed TYPE: |
files_touched | Set of files modified |
commit_types | Distribution of commit types |
peak_hour | Hour with most commits |
first_commit_time | Time of first commit |
last_commit_time | Time of last commit |
Attributes¶
dateinstance-attribute
¶
commitsclass-attribute
instance-attribute
¶
total_commitsclass-attribute
instance-attribute
¶
unique_authorsclass-attribute
instance-attribute
¶
lines_addedclass-attribute
instance-attribute
¶
lines_removedclass-attribute
instance-attribute
¶
files_touchedclass-attribute
instance-attribute
¶
commit_typesclass-attribute
instance-attribute
¶
peak_hourclass-attribute
instance-attribute
¶
first_commit_timeclass-attribute
instance-attribute
¶
last_commit_timeclass-attribute
instance-attribute
¶
CommitStatsdataclass
¶
CommitStats(total_commits: int = 0, commits_per_day: float = 0.0, commits_per_week: float = 0.0, commits_per_month: float = 0.0, commit_size_avg: float = 0.0, commit_size_median: float = 0.0, commit_size_std: float = 0.0, largest_commit: Dict[str, Any] = dict(), smallest_commit: Dict[str, Any] = dict(), merge_commits: int = 0, revert_commits: int = 0, fix_commits: int = 0, feature_commits: int = 0, hourly_distribution: List[int] = (lambda: [0] * 24)(), daily_distribution: List[int] = (lambda: [0] * 7)(), monthly_distribution: List[int] = (lambda: [0] * 12)())
Statistics for commits.
Provides detailed statistical analysis of commit patterns including frequency, size, timing, and distribution metrics.
ATTRIBUTE | DESCRIPTION |
---|---|
total_commits | Total number of commits TYPE: |
commits_per_day | Average commits per day TYPE: |
commits_per_week | Average commits per week TYPE: |
commits_per_month | Average commits per month TYPE: |
commit_size_avg | Average commit size (lines changed) TYPE: |
commit_size_median | Median commit size TYPE: |
commit_size_std | Standard deviation of commit size TYPE: |
largest_commit | Largest single commit |
smallest_commit | Smallest single commit |
merge_commits | Number of merge commits TYPE: |
revert_commits | Number of revert commits TYPE: |
fix_commits | Number of fix commits TYPE: |
feature_commits | Number of feature commits TYPE: |
hourly_distribution | Commits by hour of day |
daily_distribution | Commits by day of week |
monthly_distribution | Commits by month |
Attributes¶
total_commitsclass-attribute
instance-attribute
¶
commits_per_dayclass-attribute
instance-attribute
¶
commits_per_weekclass-attribute
instance-attribute
¶
commits_per_monthclass-attribute
instance-attribute
¶
commit_size_avgclass-attribute
instance-attribute
¶
commit_size_medianclass-attribute
instance-attribute
¶
commit_size_stdclass-attribute
instance-attribute
¶
largest_commitclass-attribute
instance-attribute
¶
smallest_commitclass-attribute
instance-attribute
¶
merge_commitsclass-attribute
instance-attribute
¶
revert_commitsclass-attribute
instance-attribute
¶
fix_commitsclass-attribute
instance-attribute
¶
feature_commitsclass-attribute
instance-attribute
¶
hourly_distributionclass-attribute
instance-attribute
¶
daily_distributionclass-attribute
instance-attribute
¶
monthly_distributionclass-attribute
instance-attribute
¶
merge_ratioproperty
¶
Calculate merge commit ratio.
RETURNS | DESCRIPTION |
---|---|
float | Ratio of merge commits to total TYPE: |
fix_ratioproperty
¶
Calculate fix commit ratio.
RETURNS | DESCRIPTION |
---|---|
float | Ratio of fix commits to total TYPE: |
ContributorStatsdataclass
¶
ContributorStats(total_contributors: int = 0, active_contributors: int = 0, new_contributors: int = 0, contributor_commits: Dict[str, int] = dict(), contributor_lines: Dict[str, int] = dict(), contributor_files: Dict[str, Set[str]] = dict(), top_contributors: List[Tuple[str, int]] = list(), contribution_inequality: float = 0.0, collaboration_graph: Dict[Tuple[str, str], int] = dict(), timezone_distribution: Dict[str, int] = dict(), retention_rate: float = 0.0, churn_rate: float = 0.0)
Statistics for contributors.
Provides analysis of contributor patterns, productivity metrics, and team dynamics based on git history.
ATTRIBUTE | DESCRIPTION |
---|---|
total_contributors | Total unique contributors TYPE: |
active_contributors | Contributors active in last 30 days TYPE: |
new_contributors | New contributors in period TYPE: |
contributor_commits | Commits per contributor |
contributor_lines | Lines changed per contributor |
contributor_files | Files touched per contributor |
top_contributors | Most active contributors |
contribution_inequality | Gini coefficient of contributions TYPE: |
collaboration_graph | Who works with whom |
timezone_distribution | Contributors by timezone |
retention_rate | Contributor retention rate TYPE: |
churn_rate | Contributor churn rate TYPE: |
Attributes¶
total_contributorsclass-attribute
instance-attribute
¶
active_contributorsclass-attribute
instance-attribute
¶
new_contributorsclass-attribute
instance-attribute
¶
contributor_commitsclass-attribute
instance-attribute
¶
contributor_linesclass-attribute
instance-attribute
¶
contributor_filesclass-attribute
instance-attribute
¶
top_contributorsclass-attribute
instance-attribute
¶
contribution_inequalityclass-attribute
instance-attribute
¶
collaboration_graphclass-attribute
instance-attribute
¶
timezone_distributionclass-attribute
instance-attribute
¶
retention_rateclass-attribute
instance-attribute
¶
churn_rateclass-attribute
instance-attribute
¶
avg_commits_per_contributorproperty
¶
Calculate average commits per contributor.
RETURNS | DESCRIPTION |
---|---|
float | Average commits TYPE: |
FileStatsdataclass
¶
FileStats(total_files: int = 0, active_files: int = 0, new_files: int = 0, deleted_files: int = 0, file_changes: Dict[str, int] = dict(), file_sizes: Dict[str, int] = dict(), largest_files: List[Tuple[str, int]] = list(), most_changed: List[Tuple[str, int]] = list(), file_age: Dict[str, int] = dict(), file_churn: Dict[str, float] = dict(), hot_files: List[str] = list(), stable_files: List[str] = list(), file_types: Dict[str, int] = dict())
Statistics for files.
Provides analysis of file-level metrics including change frequency, size distribution, and file lifecycle patterns.
ATTRIBUTE | DESCRIPTION |
---|---|
total_files | Total files in repository TYPE: |
active_files | Files changed in period TYPE: |
new_files | Files added in period TYPE: |
deleted_files | Files deleted in period TYPE: |
file_changes | Number of changes per file |
file_sizes | Size distribution of files |
largest_files | Largest files by line count |
most_changed | Most frequently changed files |
file_age | Age distribution of files |
file_churn | Churn rate per file |
hot_files | Files with high activity |
stable_files | Files with low activity |
file_types | Distribution by file type |
Attributes¶
total_filesclass-attribute
instance-attribute
¶
active_filesclass-attribute
instance-attribute
¶
new_filesclass-attribute
instance-attribute
¶
deleted_filesclass-attribute
instance-attribute
¶
file_changesclass-attribute
instance-attribute
¶
file_sizesclass-attribute
instance-attribute
¶
largest_filesclass-attribute
instance-attribute
¶
most_changedclass-attribute
instance-attribute
¶
file_ageclass-attribute
instance-attribute
¶
file_churnclass-attribute
instance-attribute
¶
hot_filesclass-attribute
instance-attribute
¶
stable_filesclass-attribute
instance-attribute
¶
file_typesclass-attribute
instance-attribute
¶
avg_file_sizeproperty
¶
Calculate average file size.
RETURNS | DESCRIPTION |
---|---|
float | Average size in lines TYPE: |
GitStatsAnalyzer¶
Analyzer for git repository statistics.
Provides comprehensive statistical analysis of git repositories to understand development patterns, team dynamics, and code health.
ATTRIBUTE | DESCRIPTION |
---|---|
config | Configuration object |
logger | Logger instance |
git_analyzer | Git analyzer instance TYPE: |
Initialize statistics analyzer.
PARAMETER | DESCRIPTION |
---|---|
config | TenetsConfig instance TYPE: |
Attributes¶
configinstance-attribute
¶
loggerinstance-attribute
¶
git_analyzerinstance-attribute
¶
Functions¶
analyze¶
analyze(repo_path: Path, since: Optional[str] = None, until: Optional[str] = None, branch: Optional[str] = None, include_files: bool = True, include_languages: bool = True, max_commits: int = 10000) -> RepositoryStats
Analyze repository statistics.
Performs comprehensive statistical analysis of a git repository to provide insights into development patterns and health.
PARAMETER | DESCRIPTION |
---|---|
repo_path | Path to git repository TYPE: |
since | Start date or relative time |
until | End date or relative time |
branch | Specific branch to analyze |
include_files | Whether to include file statistics TYPE: |
include_languages | Whether to analyze languages TYPE: |
max_commits | Maximum commits to analyze TYPE: |
RETURNS | DESCRIPTION |
---|---|
RepositoryStats | Comprehensive statistics TYPE: |
Example
analyzer = GitStatsAnalyzer(config) stats = analyzer.analyze(Path(".")) print(f"Health score: {stats.health_score}")
RepositoryStatsdataclass
¶
RepositoryStats(repo_age_days: int = 0, total_commits: int = 0, total_contributors: int = 0, total_files: int = 0, total_lines: int = 0, languages: Dict[str, int] = dict(), commit_stats: CommitStats = CommitStats(), contributor_stats: ContributorStats = ContributorStats(), file_stats: FileStats = FileStats(), growth_rate: float = 0.0, activity_trend: str = 'stable', health_score: float = 0.0, risk_factors: List[str] = list(), strengths: List[str] = list())
Overall repository statistics.
Aggregates various statistical analyses to provide comprehensive insights into repository health and development patterns.
ATTRIBUTE | DESCRIPTION |
---|---|
repo_age_days | Age of repository in days TYPE: |
total_commits | Total commits TYPE: |
total_contributors | Total contributors TYPE: |
total_files | Total files TYPE: |
total_lines | Total lines of code TYPE: |
languages | Programming languages used |
commit_stats | Commit statistics TYPE: |
contributor_stats | Contributor statistics TYPE: |
file_stats | File statistics TYPE: |
growth_rate | Repository growth rate TYPE: |
activity_trend | Recent activity trend TYPE: |
health_score | Overall health score TYPE: |
risk_factors | Identified risk factors |
strengths | Identified strengths |
Attributes¶
repo_age_daysclass-attribute
instance-attribute
¶
total_commitsclass-attribute
instance-attribute
¶
total_contributorsclass-attribute
instance-attribute
¶
total_filesclass-attribute
instance-attribute
¶
total_linesclass-attribute
instance-attribute
¶
languagesclass-attribute
instance-attribute
¶
commit_statsclass-attribute
instance-attribute
¶
contributor_statsclass-attribute
instance-attribute
¶
file_statsclass-attribute
instance-attribute
¶
growth_rateclass-attribute
instance-attribute
¶
activity_trendclass-attribute
instance-attribute
¶
health_scoreclass-attribute
instance-attribute
¶
risk_factorsclass-attribute
instance-attribute
¶
strengthsclass-attribute
instance-attribute
¶
Functions¶
Functions¶
analyze_repository¶
analyze_repository(path: Optional[Path] = None, config: Optional[Any] = None) -> Dict[str, Any]
Analyze a git repository comprehensively.
This is a convenience function that creates a GitAnalyzer instance and performs basic repository analysis.
PARAMETER | DESCRIPTION |
---|---|
path | Path to repository (defaults to current directory) |
config | Optional TenetsConfig instance |
RETURNS | DESCRIPTION |
---|---|
Dict[str, Any] | Dictionary with repository information including branch, |
Dict[str, Any] | recent commits, and contributors |
Example
from tenets.core.git import analyze_repository
repo_info = analyze_repository(Path("./my_project")) print(f"Current branch: {repo_info['branch']}") print(f"Recent commits: {len(repo_info['recent_commits'])}") print(f"Contributors: {len(repo_info['contributors'])}")
get_git_context¶
get_git_context(path: Optional[Path] = None, files: Optional[List[str]] = None, since: str = '1 week ago', config: Optional[Any] = None) -> Dict[str, Any]
Get git context for specific files or time period.
Retrieves relevant git information to provide context about recent changes, contributors, and activity patterns.
PARAMETER | DESCRIPTION |
---|---|
path | Repository path (defaults to current directory) |
files | Specific files to get context for |
since | Time period to analyze (e.g., "2 weeks ago") TYPE: |
config | Optional TenetsConfig instance |
RETURNS | DESCRIPTION |
---|---|
Dict[str, Any] | Dictionary with git context including commits, contributors, |
Dict[str, Any] | and activity summary |
Example
from tenets.core.git import get_git_context
context = get_git_context( ... files=["src/main.py", "src/utils.py"], ... since="1 month ago" ... ) print(f"Changes: {len(context['commits'])}") print(f"Active contributors: {len(context['contributors'])}")
analyze_blame¶
analyze_blame(repo_path: Path, target: str = '.', ignore_whitespace: bool = True, follow_renames: bool = True, max_files: int = 100, config: Optional[Any] = None) -> BlameReport
Analyze code ownership using git blame.
Performs line-by-line authorship analysis to understand code ownership patterns and identify knowledge holders.
PARAMETER | DESCRIPTION |
---|---|
repo_path | Path to git repository TYPE: |
target | File or directory to analyze TYPE: |
ignore_whitespace | Ignore whitespace changes in blame TYPE: |
follow_renames | Track file renames TYPE: |
max_files | Maximum files to analyze (for directories) TYPE: |
config | Optional TenetsConfig instance |
RETURNS | DESCRIPTION |
---|---|
BlameReport | BlameReport with comprehensive ownership analysis |
Example
from tenets.core.git import analyze_blame
blame = analyze_blame(Path("."), target="src/") print(f"Bus factor: {blame.bus_factor}") print(f"Primary authors: {blame.author_summary}")
Analyze single file¶
file_blame = analyze_blame(Path("."), target="main.py") print(f"Primary author: {file_blame.primary_author}")
get_file_ownership¶
get_file_ownership(repo_path: Path, file_path: str, config: Optional[Any] = None) -> Dict[str, Any]
Get ownership information for a specific file.
Quick function to get the primary author and ownership distribution for a single file.
PARAMETER | DESCRIPTION |
---|---|
repo_path | Repository path TYPE: |
file_path | Path to file relative to repo TYPE: |
config | Optional TenetsConfig instance |
RETURNS | DESCRIPTION |
---|---|
Dict[str, Any] | Dictionary with ownership information |
Example
from tenets.core.git import get_file_ownership
ownership = get_file_ownership(Path("."), "src/main.py") print(f"Primary author: {ownership['primary_author']}") print(f"Contributors: {ownership['contributors']}")
create_chronicle¶
create_chronicle(repo_path: Path, since: Optional[str] = None, until: Optional[str] = None, author: Optional[str] = None, include_stats: bool = True, max_commits: int = 1000, config: Optional[Any] = None) -> ChronicleReport
Create a narrative chronicle of repository history.
Generates a comprehensive narrative view of repository evolution including commits, contributors, trends, and significant events.
PARAMETER | DESCRIPTION |
---|---|
repo_path | Path to repository TYPE: |
since | Start date or relative time (e.g., "1 month ago") |
until | End date or relative time |
author | Filter by specific author |
include_stats | Include detailed statistics TYPE: |
max_commits | Maximum commits to analyze TYPE: |
config | Optional TenetsConfig instance |
RETURNS | DESCRIPTION |
---|---|
ChronicleReport | ChronicleReport with repository narrative |
Example
from tenets.core.git import create_chronicle
chronicle = create_chronicle( ... Path("."), ... since="3 months ago", ... include_stats=True ... ) print(chronicle.summary) print(f"Activity level: {chronicle.activity_level}") for event in chronicle.significant_events: print(f"{event['date']}: {event['description']}")
get_recent_history¶
get_recent_history(repo_path: Path, days: int = 7, config: Optional[Any] = None) -> Dict[str, Any]
Get recent repository history summary.
Quick function to get a summary of recent repository activity.
PARAMETER | DESCRIPTION |
---|---|
repo_path | Repository path TYPE: |
days | Number of days to look back TYPE: |
config | Optional TenetsConfig instance |
RETURNS | DESCRIPTION |
---|---|
Dict[str, Any] | Dictionary with recent history summary |
Example
from tenets.core.git import get_recent_history
history = get_recent_history(Path("."), days=14) print(f"Commits: {history['total_commits']}") print(f"Active contributors: {history['contributors']}") print(f"Most active day: {history['most_active_day']}")
analyze_git_stats¶
analyze_git_stats(repo_path: Path, since: Optional[str] = None, until: Optional[str] = None, include_files: bool = True, include_languages: bool = True, max_commits: int = 10000, config: Optional[Any] = None) -> RepositoryStats
Analyze comprehensive repository statistics.
Performs statistical analysis of repository to understand development patterns, team dynamics, and code health.
PARAMETER | DESCRIPTION |
---|---|
repo_path | Path to repository TYPE: |
since | Start date or relative time |
until | End date or relative time |
include_files | Whether to include file statistics TYPE: |
include_languages | Whether to analyze languages TYPE: |
max_commits | Maximum commits to analyze TYPE: |
config | Optional TenetsConfig instance |
RETURNS | DESCRIPTION |
---|---|
RepositoryStats | RepositoryStats with comprehensive metrics |
Example
from tenets.core.git import analyze_git_stats
stats = analyze_git_stats( ... Path("."), ... since="6 months ago", ... include_languages=True ... ) print(f"Health score: {stats.health_score}") print(f"Bus factor: {stats.contributor_stats.bus_factor}") print(f"Top languages: {stats.languages}")
View risk factors¶
for risk in stats.risk_factors: print(f"Risk: {risk}")
get_repository_health¶
Get a quick repository health assessment.
Provides a simplified health check with key metrics and actionable recommendations.
PARAMETER | DESCRIPTION |
---|---|
repo_path | Repository path TYPE: |
config | Optional TenetsConfig instance |
RETURNS | DESCRIPTION |
---|---|
Dict[str, Any] | Dictionary with health assessment |
Example
from tenets.core.git import get_repository_health
health = get_repository_health(Path(".")) print(f"Score: {health['score']}/100") print(f"Status: {health['status']}") for issue in health['issues']: print(f"Issue: {issue}")