← Back to Skills

commit-with-validation

majiayu000
Updated Today
1 views
58
9
58
View on GitHub
Metaautomation

About

This skill creates a single atomic commit with standardized formatting, GitHub issue linking, and pre-commit hook validation for WescoBar workflows. It's designed for use after quality gates pass in Phase 4, Step 2 of the Conductor workflow, ensuring all tests pass with an audit score β‰₯ 8.0. The commit follows conventional commit types and includes automated attribution for Claude-generated code.

Quick Install

Claude Code

Recommended
Plugin CommandRecommended
/plugin add https://github.com/majiayu000/claude-skill-registry
Git CloneAlternative
git clone https://github.com/majiayu000/claude-skill-registry.git ~/.claude/skills/commit-with-validation

Copy and paste this command in Claude Code to install this skill

Documentation

Commit with Validation

Purpose

Create a single atomic commit with standardized message format, proper GitHub issue linking, and pre-commit hook execution, following WescoBar git discipline.

When to Use

  • Conductor workflow Phase 4, Step 2 (after all quality gates pass)
  • After completing feature implementation
  • Before creating pull request
  • When all tests pass and audit score β‰₯ 8.0

Commit Message Format

<type>: <subject>

<body>

Fixes #<issue-number>

πŸ€– Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>

Types

  • feat - New feature
  • fix - Bug fix
  • refactor - Code restructuring
  • test - Test additions/changes
  • docs - Documentation changes
  • chore - Build/tooling changes

Instructions

Step 1: Validate Pre-Requisites

echo "β†’ Validating commit prerequisites..."

# Check we're on a feature branch
CURRENT_BRANCH=$(git branch --show-current)
if [[ ! "$CURRENT_BRANCH" =~ ^feature/ ]]; then
  echo "❌ Error: Not on feature branch (current: $CURRENT_BRANCH)"
  exit 1
fi

# Check there are staged or unstaged changes
if [ -z "$(git status --porcelain)" ]; then
  echo "❌ Error: No changes to commit"
  exit 1
fi

# Extract issue number from branch name
if [[ "$CURRENT_BRANCH" =~ feature/issue-([0-9]+) ]]; then
  ISSUE_NUMBER="${BASH_REMATCH[1]}"
  echo "βœ… Issue number from branch: #$ISSUE_NUMBER"
else
  echo "⚠️ Warning: Cannot extract issue number from branch"
  echo "Enter issue number manually:"
  read ISSUE_NUMBER
fi

Step 2: Build Commit Message

# Get commit type
echo "Select commit type:"
echo "  1. feat - New feature"
echo "  2. fix - Bug fix"
echo "  3. refactor - Code restructuring"
echo "  4. test - Tests"
echo "  5. docs - Documentation"
read -p "Choose (1-5): " TYPE_CHOICE

case $TYPE_CHOICE in
  1) COMMIT_TYPE="feat" ;;
  2) COMMIT_TYPE="fix" ;;
  3) COMMIT_TYPE="refactor" ;;
  4) COMMIT_TYPE="test" ;;
  5) COMMIT_TYPE="docs" ;;
  *) COMMIT_TYPE="feat" ;;
esac

# Get subject (from issue title or manual)
ISSUE_TITLE=$1  # Optional parameter

if [ -n "$ISSUE_TITLE" ]; then
  SUBJECT="$ISSUE_TITLE"
else
  echo "Enter commit subject:"
  read SUBJECT
fi

# Get body details (from implementation summary or manual)
IMPLEMENTATION_SUMMARY=$2  # Optional parameter

if [ -n "$IMPLEMENTATION_SUMMARY" ]; then
  BODY="$IMPLEMENTATION_SUMMARY"
else
  echo "Enter commit body (implementation details):"
  read BODY
fi

Step 3: Format Commit Message

# Build commit message using heredoc
COMMIT_MESSAGE=$(cat <<EOF
${COMMIT_TYPE}: ${SUBJECT}

${BODY}

Fixes #${ISSUE_NUMBER}

πŸ€– Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <[email protected]>
EOF
)

# Preview commit message
echo ""
echo "=== Commit Message Preview ==="
echo "$COMMIT_MESSAGE"
echo "============================="
echo ""

Step 4: Stage All Changes

echo "β†’ Staging all changes..."

# Stage all changes (modified, new, deleted)
git add .

# Show what will be committed
echo ""
echo "Files to be committed:"
git diff --cached --name-status
echo ""

# Count changes
FILES_CHANGED=$(git diff --cached --name-only | wc -l)
echo "Total files: $FILES_CHANGED"

Step 5: Validate Pre-Commit Requirements

# CRITICAL: Verify no --no-verify flag will be used
echo "⚠️ Pre-commit hooks will run (--no-verify is FORBIDDEN)"

# Check if pre-commit hooks exist
if [ -f .git/hooks/pre-commit ]; then
  echo "βœ… Pre-commit hook found - will execute"
  HAS_HOOKS=true
else
  echo "ℹ️ No pre-commit hooks configured"
  HAS_HOOKS=false
fi

Step 6: Create Commit

echo "β†’ Creating commit..."

# Create commit with message (hooks run automatically)
# NEVER use --no-verify (FORBIDDEN per CLAUDE.md)
if git commit -m "$COMMIT_MESSAGE"; then
  COMMIT_HASH=$(git rev-parse --short HEAD)
  echo "βœ… Commit created: $COMMIT_HASH"
  COMMIT_SUCCESS=true
else
  COMMIT_EXIT_CODE=$?
  echo "❌ Commit failed (exit code: $COMMIT_EXIT_CODE)"
  COMMIT_SUCCESS=false
fi

Step 7: Handle Pre-Commit Hook Failures

if [ "$COMMIT_SUCCESS" = false ]; then
  echo ""
  echo "⚠️ Pre-commit hooks may have failed or rejected commit"
  echo ""
  echo "Common causes:"
  echo "  - Linting errors"
  echo "  - Formatting issues"
  echo "  - Type errors"
  echo "  - Test failures"
  echo ""
  echo "Actions:"
  echo "  1. Check hook output above"
  echo "  2. Fix issues"
  echo "  3. Re-run commit-with-validation"
  echo ""
  echo "❌ DO NOT use --no-verify to bypass hooks"

  exit $COMMIT_EXIT_CODE
fi

Step 8: Handle Hook Auto-Fixes

# If hooks modified files (e.g., prettier, eslint --fix)
if [ -n "$(git status --porcelain)" ]; then
  echo "⚠️ Pre-commit hooks modified files"
  echo ""
  echo "Modified files:"
  git status --short
  echo ""

  # Check if we should amend (ONLY if safe)
  LAST_COMMIT_AUTHOR=$(git log -1 --format='%an %ae')
  CURRENT_USER="$(git config user.name) $(git config user.email)"

  if [ "$LAST_COMMIT_AUTHOR" = "$CURRENT_USER" ]; then
    # Check not pushed
    if git status | grep -q "Your branch is ahead"; then
      echo "Options:"
      echo "  1. Amend last commit (add hook fixes)"
      echo "  2. Create new commit with hook fixes"
      read -p "Choose (1/2): " AMEND_CHOICE

      if [ "$AMEND_CHOICE" = "1" ]; then
        git add .
        git commit --amend --no-edit
        echo "βœ… Commit amended with hook fixes"
      else
        git add .
        git commit -m "chore: Apply pre-commit hook fixes"
        echo "βœ… Created separate commit for hook fixes"
      fi
    else
      echo "⚠️ Commit already pushed - creating new commit for fixes"
      git add .
      git commit -m "chore: Apply pre-commit hook fixes"
    fi
  else
    echo "⚠️ Last commit not by you - creating new commit"
    git add .
    git commit -m "chore: Apply pre-commit hook fixes"
  fi
fi

Step 9: Verify Commit

echo ""
echo "=== Commit Summary ==="
git log -1 --stat
echo "======================"

# Return commit info
COMMIT_HASH=$(git rev-parse HEAD)
COMMIT_SHORT_HASH=$(git rev-parse --short HEAD)

echo ""
echo "βœ… Commit successful"
echo "   Hash: $COMMIT_SHORT_HASH"
echo "   Message: ${COMMIT_TYPE}: ${SUBJECT}"
echo "   Issue: #${ISSUE_NUMBER}"
echo "   Files: $FILES_CHANGED"

Output Format

Success

{
  "status": "success",
  "commit": {
    "hash": "a1b2c3d",
    "type": "feat",
    "subject": "Add user dark mode preference toggle",
    "issue": 137,
    "filesChanged": 12,
    "hookRan": true,
    "hookModified": false
  }
}

Hooks Modified Files

{
  "status": "success",
  "commit": {
    "hash": "a1b2c3d",
    "amended": true,
    "hookModified": true,
    "hookChanges": ["Prettier formatted 3 files", "ESLint fixed 2 issues"]
  }
}

Commit Failed (Hooks Rejected)

{
  "status": "error",
  "error": "Pre-commit hooks rejected commit",
  "issues": [
    "Linting errors in src/components/Settings.tsx",
    "TypeScript errors in src/types/index.ts"
  ],
  "action": "Fix issues and retry - DO NOT use --no-verify"
}

Integration with Conductor

Used in conductor Phase 4, Step 2:

### Phase 4: PR Creation and Documentation

**Step 2: Create SINGLE Atomic Commit**

⚠️ CRITICAL: This is the ONLY commit step in entire workflow.

Use `commit-with-validation` skill:
- Input: issue_number, issue_title, implementation_summary
- Pre-commit hooks: Will run automatically
- Validation: Tests, audit, build already passed (Phase 3)

Expected result:
- Single atomic commit with all changes
- Proper issue linking: Fixes #137
- Pre-commit hooks executed successfully
- Commit pushed to feature branch (not yet - push separately)

If hooks fail:
  β†’ Fix issues
  β†’ Re-run commit-with-validation
  β†’ NEVER use --no-verify

If hooks modify files:
  β†’ Option to amend commit (if safe)
  β†’ Or create separate hook-fixes commit

Git Discipline Rules

From CLAUDE.md:

βœ… MUST Do

  • Let pre-commit hooks run (they run automatically)
  • Create single atomic commit per feature
  • Use proper issue linking: Fixes #123
  • Include co-authoring attribution
  • Check authorship before amending

❌ NEVER Do

  • git commit --no-verify (FORBIDDEN)
  • Force push to main/development (destructive)
  • Amend commits already pushed
  • Amend other developers' commits
  • Bypass hooks or validation

Related Skills

  • create-pull-request - PR creation after commit
  • push-with-retry - Push commit with retry logic
  • quality-gate - Pre-commit validation

Best Practices

  1. One commit per feature - Atomic changes only
  2. Run quality gates first - Commit only after validation passes
  3. Let hooks run - Never bypass with --no-verify
  4. Check authorship - Before amending commits
  5. Use heredoc for messages - Ensures proper formatting
  6. Link issues properly - Fixes #123 exact format

Notes

  • This is the ONLY commit point in conductor workflow
  • All quality validation happens before this step
  • Pre-commit hooks must succeed (no bypass)
  • Amend only if safe (not pushed, your commit)
  • Commit message format is standardized for consistency

GitHub Repository

majiayu000/claude-skill-registry
Path: skills/commit-with-validation

Related Skills

content-collections

Meta

This skill provides a production-tested setup for Content Collections, a TypeScript-first tool that transforms Markdown/MDX files into type-safe data collections with Zod validation. Use it when building blogs, documentation sites, or content-heavy Vite + React applications to ensure type safety and automatic content validation. It covers everything from Vite plugin configuration and MDX compilation to deployment optimization and schema validation.

View skill

sglang

Meta

SGLang is a high-performance LLM serving framework that specializes in fast, structured generation for JSON, regex, and agentic workflows using its RadixAttention prefix caching. It delivers significantly faster inference, especially for tasks with repeated prefixes, making it ideal for complex, structured outputs and multi-turn conversations. Choose SGLang over alternatives like vLLM when you need constrained decoding or are building applications with extensive prefix sharing.

View skill

Algorithmic Art Generation

Meta

This skill helps developers create algorithmic art using p5.js, focusing on generative art, computational aesthetics, and interactive visualizations. It automatically activates for topics like "generative art" or "p5.js visualization" and guides you through creating unique algorithms with features like seeded randomness, flow fields, and particle systems. Use it when you need to build reproducible, code-driven artistic patterns.

View skill

cloudflare-turnstile

Meta

This skill provides comprehensive guidance for implementing Cloudflare Turnstile as a CAPTCHA-alternative bot protection system. It covers integration for forms, login pages, API endpoints, and frameworks like React/Next.js/Hono, while handling invisible challenges that maintain user experience. Use it when migrating from reCAPTCHA, debugging error codes, or implementing token validation and E2E tests.

View skill