Vibe-guided bskyoauth and custom repo example code in Golang 🤖 probably not safe to use in prod
1#!/bin/sh
2#
3# Git pre-commit hook for bskyoauth
4# Runs code quality, security checks, and tests before allowing commit
5#
6# To install: cp scripts/pre-commit .git/hooks/pre-commit && chmod +x .git/hooks/pre-commit
7# To bypass: git commit --no-verify
8
9set -e
10
11echo "🔍 Running pre-commit checks..."
12echo ""
13
14# Check code formatting
15echo "📝 Checking code formatting..."
16UNFORMATTED=$(gofmt -l .)
17if [ -n "$UNFORMATTED" ]; then
18 echo ""
19 echo "❌ Code is not formatted! Please run:"
20 echo " gofmt -w ."
21 echo ""
22 echo "Unformatted files:"
23 echo "$UNFORMATTED"
24 echo ""
25 echo "To bypass: git commit --no-verify"
26 exit 1
27fi
28echo "✅ Code is properly formatted"
29echo ""
30
31# Check if golangci-lint is installed
32if ! command -v golangci-lint >/dev/null 2>&1; then
33 echo "⚠️ golangci-lint not found. Installing..."
34 go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
35 if [ $? -ne 0 ]; then
36 echo "❌ Failed to install golangci-lint"
37 echo " You can install it manually: https://golangci-lint.run/welcome/install/"
38 echo " To bypass: git commit --no-verify"
39 exit 1
40 fi
41fi
42
43# Run golangci-lint
44echo "🔎 Running golangci-lint..."
45GOLANGCI_LINT_PATH=$(go env GOPATH)/bin/golangci-lint
46if [ ! -f "$GOLANGCI_LINT_PATH" ]; then
47 GOLANGCI_LINT_PATH="$HOME/go/bin/golangci-lint"
48fi
49
50if ! $GOLANGCI_LINT_PATH run --timeout=5m; then
51 echo ""
52 echo "❌ Linting issues found! Please fix before committing."
53 echo " Run: golangci-lint run for details"
54 echo " To bypass: git commit --no-verify"
55 exit 1
56fi
57echo "✅ No linting issues found"
58echo ""
59
60# Check if govulncheck is installed
61if ! command -v govulncheck >/dev/null 2>&1; then
62 echo "⚠️ govulncheck not found. Installing..."
63 go install golang.org/x/vuln/cmd/govulncheck@latest
64 if [ $? -ne 0 ]; then
65 echo "❌ Failed to install govulncheck"
66 exit 1
67 fi
68fi
69
70# Run govulncheck
71echo "🔒 Running govulncheck..."
72GOVULNCHECK_PATH=$(go env GOPATH)/bin/govulncheck
73if [ ! -f "$GOVULNCHECK_PATH" ]; then
74 GOVULNCHECK_PATH="$HOME/go/bin/govulncheck"
75fi
76
77$GOVULNCHECK_PATH ./... 2>&1 | grep -E "(No vulnerabilities found|Your code is affected)" || {
78 echo ""
79 echo "❌ Vulnerabilities detected! Please fix before committing."
80 echo " Run: govulncheck ./... for details"
81 echo " To bypass: git commit --no-verify"
82 exit 1
83}
84
85# Check if vulnerabilities were found
86if $GOVULNCHECK_PATH ./... 2>&1 | grep -q "Your code is affected by [1-9]"; then
87 echo ""
88 echo "❌ Vulnerabilities detected! Please fix before committing."
89 echo " Run: govulncheck ./... for details"
90 echo " To bypass: git commit --no-verify"
91 exit 1
92fi
93
94echo "✅ No vulnerabilities found"
95echo ""
96
97# Run tests
98echo "🧪 Running tests..."
99if ! go test -race -timeout=30s ./...; then
100 echo ""
101 echo "❌ Tests failed! Please fix before committing."
102 echo " To bypass: git commit --no-verify"
103 exit 1
104fi
105
106echo "✅ All tests passed"
107echo ""
108
109# Run go mod verify
110echo "📦 Verifying dependencies..."
111if ! go mod verify; then
112 echo ""
113 echo "❌ Dependency verification failed!"
114 echo " To bypass: git commit --no-verify"
115 exit 1
116fi
117
118echo "✅ Dependencies verified"
119echo ""
120
121echo "✨ All pre-commit checks passed!"
122exit 0