Skip to content

Commit 251d824

Browse files
authored
Merge pull request #1 from mubbi/feature/commit-lint-package
feat(commitlint): added the package codes
2 parents 3961cdf + 83a491d commit 251d824

17 files changed

+1074
-0
lines changed

.github/CONTRIBUTING.md

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# Contributing Guide
2+
3+
Thank you for considering contributing to Laravel Commit Lint!
4+
5+
## Prerequisites
6+
7+
- PHP >= 8.0
8+
- Composer
9+
- Git
10+
- PHPUnit
11+
- Bash (for hook scripts)
12+
13+
Ensure these are installed and available in your environment before contributing.
14+
15+
## How to Contribute
16+
17+
### Conventional Commits Example
18+
19+
```
20+
feat(auth): add login functionality
21+
22+
fix(hook): correct regex for commit message validation
23+
```
24+
25+
See [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) for more details.
26+
27+
## Code of Conduct
28+
Please be respectful and follow the [Contributor Covenant](https://www.contributor-covenant.org/).
29+
30+
## Reporting Issues
31+
Open an issue with details and steps to reproduce.
32+
33+
For questions, reach out via GitHub Discussions or open an issue.
34+
35+
36+
## Development
37+
38+
- Requires Bash, PHP, and PHPUnit to be available in your environment.
39+
40+
## Testing
41+
42+
Run tests and generate coverage reports and clover XML file:
43+
```bash
44+
vendor/bin/phpunit --colors=always --testdox
45+
```
46+
47+
Coverage enforcement: The pre-push hook will block pushes if coverage is below 80%. Review the HTML report in the `coverage/` directory for details.
48+
49+
## Development Setup
50+
51+
To contribute to this project, please set up the git hooks to ensure commit message linting and test coverage enforcement:
52+
53+
1. **Copy hooks to your local git hooks directory:**
54+
```sh
55+
cp .github/hooks/* .git/hooks/
56+
chmod +x .git/hooks/commit-msg .git/hooks/pre-push
57+
```
58+
59+
2. **Verify hooks are executable:**
60+
```sh
61+
ls -l .git/hooks/commit-msg .git/hooks/pre-push
62+
```
63+
64+
3. **Contribute as usual:**
65+
- Make your changes.
66+
- Commit with a message following the Conventional Commits format.
67+
- Push your branch. The pre-push hook will run tests and enforce minimum 80% coverage.
68+
69+
If you encounter any issues with the hooks, ensure you have the required dependencies installed and that your environment allows execution of shell scripts.
70+
71+
## Resources
72+
73+
- [Laravel Package Development Documentation](https://laravel.com/docs/12.x/packages)
74+
- [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/)
75+
- [PHPUnit Documentation](https://phpunit.de/documentation.html)
76+

.github/SECURITY.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Security Policy
2+
3+
## Reporting a Vulnerability
4+
If you discover a security vulnerability, please email hello@mubbi.me or open a private issue on GitHub.
5+
6+
- Do not disclose vulnerabilities publicly until they are resolved.
7+
- Provide details and steps to reproduce the issue.
8+
9+
## Supported Versions
10+
Only the latest major version is supported for security updates.
11+
12+
## Responsible Disclosure
13+
We appreciate responsible disclosure and will respond promptly to valid reports.

.github/hooks/commit-msg

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
#!/bin/sh
2+
# commitlint.sh - Enforce Conventional Commits in commit messages
3+
set -e
4+
5+
# Set up cleanup trap for any temporary files
6+
trap 'rm -f /tmp/commitlint-* 2>/dev/null || true' EXIT
7+
8+
# Colors for output
9+
RED='\033[0;31m'
10+
GREEN='\033[0;32m'
11+
YELLOW='\033[1;33m'
12+
NC='\033[0m' # No Color
13+
14+
echo "${YELLOW}🔍 Validating commit message format...${NC}"
15+
16+
# Check if this is a merge commit
17+
if [ -f .git/MERGE_HEAD ]; then
18+
echo "${GREEN}✅ Merge commit detected, skipping validation${NC}"
19+
exit 0
20+
fi
21+
22+
# Read the commit message
23+
COMMIT_MSG_FILE="$1"
24+
if [ -z "$COMMIT_MSG_FILE" ]; then
25+
echo "Usage: $0 <commit-msg-file>"
26+
exit 1
27+
fi
28+
29+
if [ ! -f "$COMMIT_MSG_FILE" ]; then
30+
echo "${RED}❌ Commit message file not found: $COMMIT_MSG_FILE${NC}"
31+
exit 1
32+
fi
33+
34+
COMMIT_MSG=$(head -n1 "$COMMIT_MSG_FILE")
35+
36+
# Skip empty commits
37+
if [ -z "$COMMIT_MSG" ] || [ "$COMMIT_MSG" = "" ]; then
38+
echo "${RED}❌ Empty commit message${NC}"
39+
exit 1
40+
fi
41+
42+
# Skip special commits that don't need conventional format validation
43+
# Also skip versioned commits like 10.x or [10.x] (to match workflow logic)
44+
if printf "%s" "$COMMIT_MSG" | grep -Eq "^(Merge|WIP|Revert)"; then
45+
echo "${GREEN}✅ Special commit type detected, skipping conventional format validation${NC}"
46+
exit 0
47+
fi
48+
49+
# Conventional Commits regex (type[optional scope]: subject)
50+
CONVENTIONAL_REGEX='^(build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test)(\([a-zA-Z0-9_-]+\))?: .{1,}'
51+
52+
# Log the commit message for debugging (safely quoted)
53+
printf "${YELLOW}Checking message: %s${NC}\n" "$COMMIT_MSG"
54+
55+
if printf "%s" "$COMMIT_MSG" | grep -Eq "$CONVENTIONAL_REGEX"; then
56+
echo "${GREEN}✅ Commit message format is valid${NC}"
57+
exit 0
58+
else
59+
echo ""
60+
echo "${RED}❌ Commit message does not follow Conventional Commits format!${NC}"
61+
echo ""
62+
echo "${YELLOW}Expected format:${NC}"
63+
echo " ${GREEN}type(scope): description${NC}"
64+
echo ""
65+
echo "${YELLOW}Valid types:${NC}"
66+
echo " feat: A new feature"
67+
echo " fix: A bug fix"
68+
echo " docs: Documentation only changes"
69+
echo " style: Changes that do not affect the meaning of the code"
70+
echo " refactor: A code change that neither fixes a bug nor adds a feature"
71+
echo " test: Adding missing tests or correcting existing tests"
72+
echo " chore: Changes to the build process or auxiliary tools"
73+
echo " perf: A code change that improves performance"
74+
echo " ci: Changes to CI configuration files and scripts"
75+
echo " build: Changes that affect the build system"
76+
echo " revert: Reverts a previous commit"
77+
echo ""
78+
echo "${YELLOW}Examples:${NC}"
79+
echo " ${GREEN}feat(auth): add user authentication${NC}"
80+
echo " ${GREEN}fix(api): resolve validation error in user endpoint${NC}"
81+
echo " ${GREEN}docs: update API documentation${NC}"
82+
echo ""
83+
echo "See: https://www.conventionalcommits.org/en/v1.0.0/"
84+
exit 1
85+
fi

.github/hooks/pre-push

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#!/bin/sh
2+
# Git pre-push hook to run PHPUnit tests and enforce minimum coverage threshold
3+
4+
set -e
5+
6+
COVERAGE_FILE="coverage/coverage.xml"
7+
MIN_COVERAGE=80
8+
9+
# Run PHPUnit with Clover coverage
10+
vendor/bin/phpunit
11+
12+
if [ ! -f "$COVERAGE_FILE" ]; then
13+
echo "[pre-push] ❌ Coverage report not found at $COVERAGE_FILE. Push aborted."
14+
exit 1
15+
fi
16+
17+
# Extract total statements and covered statements using POSIX-compliant sed
18+
STATEMENTS=$(sed -n 's/.*statements="\([0-9][0-9]*\)".*/\1/p' "$COVERAGE_FILE" | head -n 1)
19+
COVERED=$(sed -n 's/.*coveredstatements="\([0-9][0-9]*\)".*/\1/p' "$COVERAGE_FILE" | head -n 1)
20+
21+
# Debug info (optional)
22+
echo "[pre-push] Detected Statements: ${STATEMENTS:-<missing>}, Covered: ${COVERED:-<missing>}"
23+
24+
# Validate parsed values
25+
if ! echo "$STATEMENTS" | grep -Eq '^[0-9]+$'; then
26+
echo "[pre-push] ❌ Invalid or missing statements count. Push aborted."
27+
exit 1
28+
fi
29+
if ! echo "$COVERED" | grep -Eq '^[0-9]+$'; then
30+
echo "[pre-push] ❌ Invalid or missing covered statements count. Push aborted."
31+
exit 1
32+
fi
33+
34+
if [ "$STATEMENTS" -eq 0 ]; then
35+
echo "[pre-push] ❌ Zero statements found. Coverage meaningless. Push aborted."
36+
exit 1
37+
fi
38+
39+
# Calculate percentage with POSIX awk
40+
COVERAGE_PERCENT=$(awk "BEGIN {printf \"%.2f\", ($COVERED / $STATEMENTS) * 100}")
41+
42+
# Validate percentage output
43+
if [ -z "$COVERAGE_PERCENT" ]; then
44+
echo "[pre-push] ❌ Could not calculate coverage percent. Push aborted."
45+
exit 1
46+
fi
47+
48+
# Float comparison using awk (portable)
49+
IS_BELOW=$(awk "BEGIN {print ($COVERAGE_PERCENT < $MIN_COVERAGE) ? 1 : 0}")
50+
51+
if [ "$IS_BELOW" -eq 1 ]; then
52+
echo "[pre-push] ❌ Test coverage ${COVERAGE_PERCENT}% is below required ${MIN_COVERAGE}%. Push aborted."
53+
exit 1
54+
else
55+
echo "[pre-push] ✅ Test coverage ${COVERAGE_PERCENT}% meets minimum ${MIN_COVERAGE}%. Push allowed."
56+
exit 0
57+
fi

0 commit comments

Comments
 (0)