A pre-commit hook that automatically appends task IDs from branch names to commit messages
Project description
pre-commit-taskid
A pre-commit hook that automatically appends task IDs from branch names to commit messages.
Overview
This pre-commit hook extracts task IDs from your branch names and automatically appends them to your commit messages. It's designed to work with branch naming conventions like:
feature-1234bugfix-5678hotfix-9012
When you make a commit, the hook will extract the numeric ID (e.g., 1234) from your branch name and append it to your commit message in the format #1234.
Installation
Prerequisites
- Python 3.8 or higher
- pre-commit package installed
Using pip
pip install pre-commit-taskid
From Source
git clone https://github.com/yourusername/pre-commit-taskid.git
cd pre-commit-taskid
pip install -e .
Usage
- Add the hook to your
.pre-commit-config.yamlfile:
repos:
- repo: https://github.com/yourusername/pre-commit-taskid
rev: v0.1.0 # Use the specific version tag
hooks:
- id: taskid-prepender
- Install the pre-commit hooks:
pre-commit install --hook-type prepare-commit-msg
- Make commits as usual. The hook will automatically append the task ID to your commit messages.
Examples
Branch Name: feature-1234
Original commit message:
Add new login functionality
Modified commit message:
Add new login functionality (#1234)
Branch Name: bugfix-5678
Original commit message:
Fix null pointer exception in user service
Modified commit message:
Fix null pointer exception in user service #5678
Error Handling
- If no task ID is found in the branch name, the hook will log a warning but allow the commit to proceed without modification.
- If there are any errors during execution, the hook will log the error and exit with a non-zero status code.
Configuration
No additional configuration is required. The hook will work out of the box with branch names that follow the format branchName-{taskID}.
Development
Testing
This project uses pytest for testing. The tests are organized into unit tests and integration tests.
Running Tests
You can run the tests using the provided script:
# Run all tests
run-taskid-tests
# Or using pytest directly
pytest
# Run only unit tests
pytest -m unit
# Run only integration tests
pytest -m integration
# Generate coverage report
pytest --cov=pre_commit_taskid --cov-report=term-missing
Test Structure
- Unit Tests: Test individual functions in isolation
- Integration Tests: Test the hook in a real Git repository
Development Setup
To set up the development environment:
# Clone the repository
git clone https://github.com/yourusername/pre-commit-taskid.git
cd pre-commit-taskid
# Install the package in development mode with dev dependencies
pip install -e ".[dev]"
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 pre_commit_taskid-0.1.1.tar.gz.
File metadata
- Download URL: pre_commit_taskid-0.1.1.tar.gz
- Upload date:
- Size: 31.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f2e8d75608af0607b7461c247e7731a274a1e51bf89775aaa6dc2d7f0aafd59d
|
|
| MD5 |
31b3a764fe7102f2a2efb37c5bb8bd00
|
|
| BLAKE2b-256 |
f5f7ef6240ca16744b02fcf5bd518bbd6cb0fb1ad06ab88f70a04a5665b37736
|
File details
Details for the file pre_commit_taskid-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pre_commit_taskid-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c968d4a84c1cd5d000efc53c22b6579be430994c86daaf3277074dbe4a4edcac
|
|
| MD5 |
90c4aa1b86f521034b8dcde1a0f146ff
|
|
| BLAKE2b-256 |
97fad7ed9fefec337ad27662e2c9c2ae8c293e0a95a21688313f9c2e44b99a70
|