Generate Git Timesheets from commit history
Project description
Git Timesheet Generator
A Python package to generate git timesheets from commit history, specifically filtering for commits by a particular author.
Overview
This tool analyzes git commit history across multiple repositories and:
- Filters commits by author name/email
- Estimates time spent on each commit (in 15-minute increments)
- Adjusts time based on commit message keywords
- Groups work by day and week
- Formats output as a readable timesheet
Requirements
- Python 3.8+
- pytz library
- click library
Installation
From PyPI
# Create and activate a virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install the package
pip install git-timesheet
From Source
# Clone the repository
git clone https://github.com/mcgarrah/git-timesheet.git
cd git-timesheet
# Create and activate a virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install in development mode
pip install -e .
Configuration
The tool supports configuration files to set default values. It looks for configuration files in the following locations (in order of precedence):
.timesheetrcin the current directorytimesheet.iniin the current directory.timesheetrcin the user's home directorytimesheet.iniin the user's.configdirectoryconfig.iniin the user's.config/git-timesheetdirectory
You can create a configuration file using the ggts init command, or manually create one with the following format:
[defaults]
# Author pattern to filter commits
author = michael mcgarrah
# Default timezone for dates
timezone = US/Eastern
# Minutes between commits to consider them part of the same work session
session_timeout = 60
Command-line arguments always override values from configuration files.
Usage
# Generate a timesheet
ggts generate [OPTIONS]
# Initialize configuration
ggts init
Options
--base-dir PATH: Base directory containing git repositories (default: current directory)--since DATE: Show commits more recent than a specific date (e.g., "2 weeks ago")--until DATE: Show commits older than a specific date--repos REPO: Specific repository names to include (can be used multiple times)--output FORMAT: Output format (text, csv, markdown, or md, default: text)--author PATTERN: Filter commits by author (default from config or "mcgarrah")--timezone TIMEZONE: Timezone for dates (default from config or "UTC")--output-file PATH: Write output to file instead of stdout--session-timeout MINUTES: Minutes between commits to consider them part of the same work session (default from config or 60)
Examples
Generate timesheet for the last 2 weeks
ggts generate --since="2 weeks ago"
Generate timesheet for specific repositories
ggts generate --repos food_service_nutrition --repos food-intelligence-app --since="1 month ago"
Generate timesheet for a specific date range
ggts generate --since="2023-01-01" --until="2023-01-31"
Generate timesheet with specific author pattern
ggts generate --author="michael mcgarrah" --since="2 weeks ago"
Generate timesheet in US Eastern timezone
ggts generate --since="1 month ago" --timezone="US/Eastern"
Generate CSV output for spreadsheet import
ggts generate --since="1 month ago" --output=csv --output-file=timesheet.csv
Generate markdown output for pretty formatting
ggts generate --since="1 month ago" --output=markdown --output-file=timesheet.md
Initialize configuration
ggts init
Output Formats
Text Format
Plain text output organized by weeks and days, showing detailed commit information with timezone abbreviations.
CSV Format
Comma-separated values format suitable for importing into spreadsheet applications like Excel or Google Sheets. Includes timezone information for each entry.
Markdown Format
Pretty markdown format with tables organized by week, suitable for viewing in markdown readers or converting to HTML. Includes time ranges and timezone abbreviations for each task to better understand work sessions.
Time Estimation Logic
- Base time: 15 minutes per commit
- Bug fixes/issues: +15 minutes
- New features/implementations: +30 minutes
- Refactoring/improvements: +15 minutes
- Commits close together (within 60 minutes by default) are considered part of the same work session
Timezone Support
The tool supports various timezone formats:
- IANA timezone names (e.g., "America/New_York")
- Common US timezone aliases (e.g., "US/Eastern")
- Short timezone abbreviations (e.g., "EST", "EDT")
- Prefixed short timezone abbreviations (e.g., "US/EST")
Development
Setup Development Environment
# Clone the repository
git clone https://github.com/mcgarrah/git-timesheet.git
cd git-timesheet
# Create and activate a virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install development dependencies
pip install -e ".[dev]"
Testing
The project includes a comprehensive test suite using pytest. To run the tests:
# Run all tests
pytest
# Run with coverage report
pytest --cov=git_timesheet
# Run a specific test file
pytest tests/test_timezone.py
Test Structure
-
Unit Tests: Test individual functions in isolation
test_timezone.py: Tests for timezone conversion and abbreviationtest_git_operations.py: Tests for git repository detection and log retrievaltest_formatting.py: Tests for output formatting functions
-
Integration Tests: Test the entire workflow
test_integration.py: End-to-end tests using temporary git repositories
Building Documentation
pip install -e ".[docs]"
cd docs
make html
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file git_timesheet-0.1.2.tar.gz.
File metadata
- Download URL: git_timesheet-0.1.2.tar.gz
- Upload date:
- Size: 22.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d66d7aba0a473dc5f3b274d96fcd3e001d32c684399c0469a79407323dc10c44
|
|
| MD5 |
53ec7ad40d76f9cddf7289e29ed25970
|
|
| BLAKE2b-256 |
aff0f8055de39c1301d6ea18b112a2a15ff2457d7c1bbff458ce53483ed0c820
|
File details
Details for the file git_timesheet-0.1.2-py3-none-any.whl.
File metadata
- Download URL: git_timesheet-0.1.2-py3-none-any.whl
- Upload date:
- Size: 18.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
74288d90ec4ac26b662c9db5640c1c19930554aa717b66858a360bc62a1d3ef9
|
|
| MD5 |
f286f3fcf600b0ff9aaa492340a8f8e5
|
|
| BLAKE2b-256 |
4023d928b510bd250154d07b4e7490d705648e489c5094dc18e25973934a593e
|