Skip to content

Commit 97524af

Browse files
committed
chore: add pre-commit hook for conventional commit verification
1 parent 95d3e3f commit 97524af

2 files changed

Lines changed: 58 additions & 0 deletions

File tree

.githooks/commit-msg

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/sh
2+
# Verify commit message follows conventional commit format
3+
# https://www.conventionalcommits.org/
4+
5+
commit_msg_file="$1"
6+
commit_msg=$(cat "$commit_msg_file")
7+
8+
# Skip merge commits
9+
if echo "$commit_msg" | grep -qE "^Merge "; then
10+
exit 0
11+
fi
12+
13+
# Conventional commit types from @commitlint/config-conventional
14+
types="build|chore|ci|docs|feat|fix|perf|refactor|revert|style|test"
15+
16+
# Pattern: type(optional-scope): description
17+
# The description must start with lowercase and not end with period
18+
pattern="^($types)(\(.+\))?(!)?: .+"
19+
20+
if ! echo "$commit_msg" | head -1 | grep -qE "$pattern"; then
21+
echo "ERROR: Commit message does not follow conventional commit format."
22+
echo ""
23+
echo "Expected format: <type>(<scope>): <description>"
24+
echo ""
25+
echo "Valid types: build, chore, ci, docs, feat, fix, perf, refactor, revert, style, test"
26+
echo ""
27+
echo "Examples:"
28+
echo " feat: add new feature"
29+
echo " fix(parser): resolve parsing issue"
30+
echo " docs: update README"
31+
echo ""
32+
echo "Your commit message:"
33+
echo " $(head -1 "$commit_msg_file")"
34+
exit 1
35+
fi

crates/rmcp/build.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Install git hooks on build
2+
fn main() {
3+
// Only run in the workspace root (not when building as a dependency)
4+
let manifest_dir = std::env::var("CARGO_MANIFEST_DIR").unwrap();
5+
let workspace_root = std::path::Path::new(&manifest_dir)
6+
.parent()
7+
.and_then(|p| p.parent());
8+
9+
if let Some(root) = workspace_root {
10+
let githooks_dir = root.join(".githooks");
11+
let git_dir = root.join(".git");
12+
13+
// Only configure if we're in the actual workspace (not a dependency)
14+
// and git directory exists
15+
if githooks_dir.exists() && git_dir.exists() {
16+
// Configure git to use our hooks directory
17+
let _ = std::process::Command::new("git")
18+
.args(["config", "core.hooksPath", ".githooks"])
19+
.current_dir(root)
20+
.output();
21+
}
22+
}
23+
}

0 commit comments

Comments
 (0)