git-cliff-core) and a CLI binary (git-cliff). This modular design allows the changelog generation logic to be reused as a library while providing a powerful command-line interface.
Project Structure
The project follows a workspace architecture:Workspace Dependencies
Shared dependencies are managed at the workspace level in the rootCargo.toml:
- regex: Pattern matching for commit parsing
- glob: File pattern matching
- log: Logging infrastructure
- secrecy: Secure handling of sensitive data (API tokens)
- reqwest: HTTP client for remote integrations
- dirs: Platform-specific directory paths
- url: URL parsing and manipulation
Core Library (git-cliff-core)
The core library provides all the changelog generation functionality. It’s designed to be feature-flagged for flexibility:
Features
repo(default): Git repository parsing viagit2remote: Base for remote integrationsgithub: GitHub API integrationgitlab: GitLab API integrationgitea: Gitea API integrationbitbucket: Bitbucket API integrationazure_devops: Azure DevOps API integration
Key Modules
changelog
The central module that orchestrates changelog generation:
- Manages releases and their commits
- Handles template rendering
- Coordinates remote data fetching
- Processes commits and generates output
git-cliff-core/src/changelog.rs
commit
Represents Git commits with conventional commit parsing:
- Parse conventional commits
- Extract commit metadata (author, timestamp, etc.)
- Support custom commit parsers
- Handle commit footers and breaking changes
git-cliff-core/src/commit.rs
config
Configuration file parsing and management:
- TOML and YAML configuration files
- Embedded configurations from
Cargo.tomlorpyproject.toml - Commit parsers and preprocessors
- Link parsers for issue/PR references
git-cliff-core/src/config.rs
template
Tera-based templating engine with custom filters:
upper_first: Capitalize first charactersplit_regex: Split strings by regexreplace_regex: Replace regex matchesfind_regex: Find regex patterns
git-cliff-core/src/template.rs
release
Represents a release with associated commits:
- Group commits by release
- Track version information
- Calculate statistics
- Store remote metadata (contributors, PRs, etc.)
git-cliff-core/src/release.rs
remote
Remote repository integration (GitHub, GitLab, etc.):
github: GitHub API clientgitlab: GitLab API clientgitea: Gitea API clientbitbucket: Bitbucket API clientazure_devops: Azure DevOps API client
git-cliff-core/src/remote/
Other Modules
repo: Git repository operations viagit2tag: Git tag parsing and handlingcontributor: Contributor informationstatistics: Release statistics calculationsummary: Commit processing summarycommand: External command executionerror: Error types and handlingembed: Embedded file resources
CLI Binary (git-cliff)
The CLI provides the user interface to the core library:
Structure
main.rs: Entry point, argument parsing, changelog generationargs.rs: Command-line argument definitions (usingclap)lib.rs: Core CLI logic, configuration initializationlogger.rs: Logging setupprofiler.rs: Optional performance profilingbin/completions.rs: Shell completion generationbin/mangen.rs: Man page generation
Features
default: Update informer + all integrationsintegrations: All remote platform integrationsupdate-informer: Check for new versionsremote: Base remote supportgithub,gitlab,gitea,bitbucket,azure_devops: Platform-specificprofiler: Performance profiling support
Data Flow
Step-by-Step Process
-
Repository Access
- Open Git repository using
git2 - Read configuration from
cliff.toml,Cargo.toml, orpyproject.toml
- Open Git repository using
-
Commit Parsing
- Iterate through commit history
- Parse conventional commits (type, scope, description, breaking changes)
- Apply custom commit parsers from configuration
- Extract metadata (author, timestamp, SHA)
-
Filtering & Processing
- Filter commits by patterns (include/exclude)
- Skip commits based on configuration
- Parse links (issues, PRs) from commit messages
- Process commit preprocessors
-
Release Grouping
- Group commits between Git tags
- Create release objects with version information
- Calculate statistics (commit count, contributors, etc.)
-
Remote Data Fetching (if enabled)
- Connect to remote platform APIs
- Fetch contributors, pull requests, and commits
- Merge remote metadata with local data
-
Template Rendering
- Load header, body, and footer templates
- Render using Tera template engine
- Apply custom filters and context variables
-
Postprocessing
- Apply regex-based postprocessors
- Format and clean output
-
Output Generation
- Write to file or stdout
- Update existing changelog or create new one
Configuration System
Configuration can be loaded from multiple sources:- Dedicated config file:
cliff.toml(default) - Cargo manifest:
Cargo.tomlunder[package.metadata.git-cliff] - Python project:
pyproject.tomlunder[tool.git-cliff] - Embedded defaults: Built-in templates for common formats
config crate with TOML and YAML support.
Template Engine
Based on Tera, the template engine provides:- Variables: Access to releases, commits, version, etc.
- Filters: Transform data (uppercase, regex, etc.)
- Control flow: Conditionals and loops
- Custom functions: git-cliff-specific helpers
Error Handling
Errors are managed through a customError enum using thiserror:
Testing Strategy
The project uses:- Unit tests: In individual modules
- Integration tests: In
tests/directories - Snapshot tests: Using
expect-testfor output validation - CI checks: Clippy, rustfmt, and test coverage
Performance Considerations
- Lazy parsing: Commits are parsed on-demand
- Caching: Remote API responses are cached using
cacache - Async operations: Remote fetching uses Tokio for concurrent requests
- Optional features: Tree-shaking unused platform integrations
- Profiling support: Optional flamegraph generation for performance analysis
Build Profiles
The workspace defines optimized build profiles:dev: Fast compilation, panic=abortrelease: Maximum optimization, LTO enabled, stripped binariestest: Optimized for test performancebench: Debug symbols for profiling