-
Notifications
You must be signed in to change notification settings - Fork 1
python package
BrunoV21 edited this page Apr 11, 2025
·
1 revision
The git_recap Python package provides core functionality for fetching and processing Git activity data from multiple providers.
git_recap/
├── __init__.py
├── fetcher.py
├── utils.py
└── providers/
├── __init__.py
├── base_fetcher.py
├── github_fetcher.py
├── gitlab_fetcher.py
└── azure_fetcher.py
Main entry point that:
- Parses command line arguments
- Initializes provider-specific fetchers
- Aggregates results from multiple providers
- Handles error cases and validation
Provider-specific implementations following the base fetcher interface:
Abstract base class defining the common interface:
class BaseFetcher(ABC):
@abstractmethod
def get_authored_messages(self) -> List[Dict]:
"""Fetch all authored messages within date range"""
@abstractmethod
def validate_credentials(self) -> bool:
"""Verify authentication credentials"""-
github_fetcher.py: GitHub integration via PyGitHub -
gitlab_fetcher.py: GitLab integration via python-gitlab -
azure_fetcher.py: Azure DevOps integration via azure-devops
Helper functions including:
-
parse_entries_to_txt(): Formats raw entries into readable text -
validate_dates(): Ensures proper date range formatting -
filter_by_author(): Filters messages by specified authors
Install from PyPI:
pip install git-recapOr install from source:
git clone https://github.com/yourusername/git_recap.git
cd git_recap
pip install .from datetime import datetime, timedelta
from git_recap.providers import GitHubFetcher
from git_recap.utils import parse_entries_to_txt
# Initialize fetcher
fetcher = GitHubFetcher(
pat="your_github_pat",
start_date=datetime.now() - timedelta(days=7),
end_date=datetime.now(),
repos=["repo1", "repo2"],
authors=["user1"]
)
# Fetch and format messages
messages = fetcher.get_authored_messages()
summary = parse_entries_to_txt(messages)
print(summary)git-recap --provider github \
--pat YOUR_PAT \
--start-date 2023-01-01 \
--end-date 2023-01-31 \
--repos repo1 repo2 \
--authors user1To add support for a new Git provider:
- Create a new fetcher class inheriting from
BaseFetcher - Implement all required abstract methods
- Add provider-specific logic for:
- Authentication
- Repository listing
- Message fetching
- Error handling
Example skeleton:
from git_recap.providers.base_fetcher import BaseFetcher
class NewProviderFetcher(BaseFetcher):
def __init__(self, pat: str, **kwargs):
super().__init__(pat, **kwargs)
# Initialize provider client
def get_authored_messages(self) -> List[Dict]:
# Implementation here
pass
def validate_credentials(self) -> bool:
# Implementation here
passRun tests with:
python -m pytest tests/Key test files:
-
tests/test_parser.py: Tests for message parsing -
tests/test_dummy_parser.py: Mock provider tests
- PyGithub (for GitHub integration)
- python-gitlab (for GitLab integration)
- azure-devops (for Azure DevOps integration)