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-9012user/feature-3456release/v1.0-7890
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/0xsirsaif/pre-commit-taskid.git
cd pre-commit-taskid
pip install -e .
Usage
1. Add to your pre-commit config
Add the hook to your .pre-commit-config.yaml file:
repos:
- repo: https://github.com/0xsirsaif/pre-commit-taskid
rev: v0.1.0 # Use the specific version tag
hooks:
- id: taskid-prepender
stages: [prepare-commit-msg] # CRITICAL: This line is required!
2. Install the hook
# IMPORTANT: Must specify the prepare-commit-msg hook type
pre-commit install --hook-type prepare-commit-msg
3. Make commits as usual
The hook will automatically append the task ID to your commit messages.
Examples
Example 1: Feature Branch
# Create a feature branch
git checkout -b feature-1234
# Make changes and commit
git add .
git commit -m "Add login functionality"
# Resulting commit message:
# "Add login functionality (#1234)"
Example 2: Bugfix Branch
# Create a bugfix branch
git checkout -b bugfix-5678
# Make changes and commit
git add .
git commit -m "Fix null pointer exception"
# Resulting commit message:
# "Fix null pointer exception (#5678)"
Example 3: Branch with Path
# Create a branch with a path
git checkout -b user/feature-3456
# Make changes and commit
git add .
git commit -m "Add user profile"
# Resulting commit message:
# "Add user profile (#3456)"
Troubleshooting
Hook Not Running
If the hook isn't running:
-
Ensure you've installed it with the correct hook type:
pre-commit install --hook-type prepare-commit-msg
-
Verify the hook is installed:
ls -la .git/hooks/prepare-commit-msg
-
Check your
.pre-commit-config.yamlincludesstages: [prepare-commit-msg]
Task ID Not Extracted
If the task ID isn't being extracted:
-
Ensure your branch name follows the pattern with a hyphen followed by numbers at the end:
- ✅
feature-1234 - ✅
user/feature-1234 - ❌
feature_1234 - ❌
feature1234
- ✅
-
Check the branch name:
git branch --show-current
Parentheses Around Task ID
If you don't see parentheses around the task ID (e.g., #(1234) instead of #1234):
- Update to the latest version of the package
- Clean the pre-commit cache:
pre-commit clean
Advanced Configuration
Using with Local Hooks
You can also use the hook locally without specifying a repository:
repos:
- repo: local
hooks:
- id: taskid-prepender
name: Task ID Prepender
entry: pre-commit-taskid
language: python
stages: [prepare-commit-msg]
additional_dependencies: ["pre-commit-taskid==0.1.0"]
Manual Testing
To test the hook manually:
# Create a test commit message
echo "Test commit" > .git/COMMIT_EDITMSG
# Run the hook manually
pre-commit-taskid .git/COMMIT_EDITMSG
# Check the result
cat .git/COMMIT_EDITMSG
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/0xsirsaif/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.
Metadata
Release files for pre-commit-taskid 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pre_commit_taskid-0.1.2.tar.gz | 31.9 kB | Without provenance | Details for pre_commit_taskid-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pre_commit_taskid-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for pre_commit_taskid-0.1.2-py3-none-any.whl |
Total release size: 36.5 kB
Release files / pre_commit_taskid-0.1.2.tar.gz
| Download URL | pre_commit_taskid-0.1.2.tar.gz |
|---|---|
| Size | 31.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ab77fe8186561052378425c682ff375e4dcec5bfe38467580bf79c3ee2baeba0
|
|
BLAKE2b-256 checksum How to use checksums |
5da2f1083ebb84c5cb70f7fc0c6d9def21c5c4df1f6fe083ec98a6921ea75518
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.4
|
Release files / pre_commit_taskid-0.1.2-py3-none-any.whl
| Download URL | pre_commit_taskid-0.1.2-py3-none-any.whl |
|---|---|
| Size | 4.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
61ab8dcfdc27eea198fa7c619dbce75f1ab993308f6f678d543cbdc7c12774eb
|
|
BLAKE2b-256 checksum How to use checksums |
1f110b4f97015d9bf06cc6f7ec6fae0c3dff64ff1b198ab23b9fb8c7466d8b42
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.5.4
|
Security for pre-commit-taskid 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.