mirror of
https://github.com/NoFxAiOS/nofx.git
synced 2026-07-05 20:11:13 +08:00
feat: pr validation
This commit is contained in:
413
scripts/pr-check.sh
Executable file
413
scripts/pr-check.sh
Executable file
@@ -0,0 +1,413 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 🔍 PR Health Check Script
|
||||
# Analyzes your PR and gives suggestions on how to meet the new standards
|
||||
# This script only analyzes and suggests - it won't modify your code
|
||||
|
||||
set -e
|
||||
|
||||
# Colors
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
CYAN='\033[0;36m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Counters
|
||||
ISSUES_FOUND=0
|
||||
WARNINGS_FOUND=0
|
||||
PASSED_CHECKS=0
|
||||
|
||||
# Helper functions
|
||||
log_section() {
|
||||
echo ""
|
||||
echo -e "${CYAN}═══════════════════════════════════════════${NC}"
|
||||
echo -e "${CYAN} $1${NC}"
|
||||
echo -e "${CYAN}═══════════════════════════════════════════${NC}"
|
||||
}
|
||||
|
||||
log_check() {
|
||||
echo -e "${BLUE}🔍 Checking: $1${NC}"
|
||||
}
|
||||
|
||||
log_pass() {
|
||||
echo -e "${GREEN}✅ PASS: $1${NC}"
|
||||
((PASSED_CHECKS++))
|
||||
}
|
||||
|
||||
log_warning() {
|
||||
echo -e "${YELLOW}⚠️ WARNING: $1${NC}"
|
||||
((WARNINGS_FOUND++))
|
||||
}
|
||||
|
||||
log_error() {
|
||||
echo -e "${RED}❌ ISSUE: $1${NC}"
|
||||
((ISSUES_FOUND++))
|
||||
}
|
||||
|
||||
log_suggestion() {
|
||||
echo -e "${CYAN}💡 Suggestion: $1${NC}"
|
||||
}
|
||||
|
||||
log_command() {
|
||||
echo -e "${GREEN} Run: ${NC}$1"
|
||||
}
|
||||
|
||||
# Welcome
|
||||
echo ""
|
||||
echo "╔═══════════════════════════════════════════╗"
|
||||
echo "║ NOFX PR Health Check ║"
|
||||
echo "║ Analyze your PR and get suggestions ║"
|
||||
echo "╚═══════════════════════════════════════════╝"
|
||||
echo ""
|
||||
|
||||
# Check if we're in a git repo
|
||||
if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
|
||||
log_error "Not a git repository"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Get current branch
|
||||
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
||||
echo -e "${BLUE}Current branch: ${GREEN}$CURRENT_BRANCH${NC}"
|
||||
|
||||
if [ "$CURRENT_BRANCH" = "main" ] || [ "$CURRENT_BRANCH" = "dev" ]; then
|
||||
log_error "You're on the $CURRENT_BRANCH branch. Please switch to your PR branch."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check if upstream exists
|
||||
if ! git remote | grep -q "^upstream$"; then
|
||||
log_warning "Upstream remote not found"
|
||||
log_suggestion "Add upstream remote:"
|
||||
log_command "git remote add upstream https://github.com/tinkle-community/nofx.git"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# ═══════════════════════════════════════════
|
||||
# 1. GIT BRANCH CHECKS
|
||||
# ═══════════════════════════════════════════
|
||||
log_section "1. Git Branch Status"
|
||||
|
||||
# Check if branch is up to date with upstream
|
||||
log_check "Is branch based on latest upstream/dev?"
|
||||
if git remote | grep -q "^upstream$"; then
|
||||
git fetch upstream -q 2>/dev/null || true
|
||||
|
||||
if git merge-base --is-ancestor upstream/dev HEAD 2>/dev/null; then
|
||||
log_pass "Branch is up to date with upstream/dev"
|
||||
else
|
||||
log_error "Branch is not based on latest upstream/dev"
|
||||
log_suggestion "Rebase your branch:"
|
||||
log_command "git fetch upstream && git rebase upstream/dev"
|
||||
echo ""
|
||||
fi
|
||||
else
|
||||
log_warning "Cannot check - upstream remote not configured"
|
||||
fi
|
||||
|
||||
# Check for merge conflicts
|
||||
log_check "Any merge conflicts?"
|
||||
if git diff --check > /dev/null 2>&1; then
|
||||
log_pass "No merge conflicts detected"
|
||||
else
|
||||
log_error "Merge conflicts detected"
|
||||
log_suggestion "Resolve conflicts and commit"
|
||||
fi
|
||||
|
||||
# ═══════════════════════════════════════════
|
||||
# 2. COMMIT MESSAGE CHECKS
|
||||
# ═══════════════════════════════════════════
|
||||
log_section "2. Commit Messages"
|
||||
|
||||
# Get commits in this branch (not in upstream/dev)
|
||||
if git remote | grep -q "^upstream$"; then
|
||||
COMMITS=$(git log upstream/dev..HEAD --oneline 2>/dev/null || git log --oneline -10)
|
||||
else
|
||||
COMMITS=$(git log --oneline -10)
|
||||
fi
|
||||
|
||||
COMMIT_COUNT=$(echo "$COMMITS" | wc -l | tr -d ' ')
|
||||
echo -e "${BLUE}Found $COMMIT_COUNT commit(s) in your branch${NC}"
|
||||
echo ""
|
||||
|
||||
# Check each commit message
|
||||
echo "$COMMITS" | while read -r line; do
|
||||
COMMIT_MSG=$(echo "$line" | cut -d' ' -f2-)
|
||||
|
||||
# Check if follows conventional commits
|
||||
if echo "$COMMIT_MSG" | grep -qE "^(feat|fix|docs|style|refactor|perf|test|chore|ci|security)(\(.+\))?: .+"; then
|
||||
log_pass "\"$COMMIT_MSG\""
|
||||
else
|
||||
log_warning "\"$COMMIT_MSG\""
|
||||
log_suggestion "Should follow format: type(scope): description"
|
||||
echo " Examples:"
|
||||
echo " - feat(exchange): add OKX integration"
|
||||
echo " - fix(trader): resolve position bug"
|
||||
echo ""
|
||||
fi
|
||||
done
|
||||
|
||||
# Suggest PR title based on commits
|
||||
echo ""
|
||||
log_check "Suggested PR title:"
|
||||
SUGGESTED_TITLE=$(git log --pretty=%s upstream/dev..HEAD 2>/dev/null | head -1 || git log --pretty=%s -1)
|
||||
echo -e "${GREEN} \"$SUGGESTED_TITLE\"${NC}"
|
||||
echo ""
|
||||
|
||||
# ═══════════════════════════════════════════
|
||||
# 3. CODE QUALITY - BACKEND (Go)
|
||||
# ═══════════════════════════════════════════
|
||||
if find . -name "*.go" -not -path "./vendor/*" -not -path "./.git/*" | grep -q .; then
|
||||
log_section "3. Backend Code Quality (Go)"
|
||||
|
||||
# Check if Go is installed
|
||||
if ! command -v go &> /dev/null; then
|
||||
log_warning "Go not installed - skipping backend checks"
|
||||
log_suggestion "Install Go: https://go.dev/doc/install"
|
||||
else
|
||||
# Check go fmt
|
||||
log_check "Go code formatting (go fmt)"
|
||||
UNFORMATTED=$(gofmt -l . 2>/dev/null | grep -v vendor || true)
|
||||
if [ -z "$UNFORMATTED" ]; then
|
||||
log_pass "All Go files are formatted"
|
||||
else
|
||||
log_error "Some files need formatting:"
|
||||
echo "$UNFORMATTED" | head -5 | while read -r file; do
|
||||
echo " - $file"
|
||||
done
|
||||
log_suggestion "Format your code:"
|
||||
log_command "go fmt ./..."
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# Check go vet
|
||||
log_check "Go static analysis (go vet)"
|
||||
if go vet ./... > /tmp/vet-output.txt 2>&1; then
|
||||
log_pass "No issues found by go vet"
|
||||
else
|
||||
log_error "Go vet found issues:"
|
||||
head -10 /tmp/vet-output.txt | sed 's/^/ /'
|
||||
log_suggestion "Fix the issues above"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# Check tests exist
|
||||
log_check "Do tests exist?"
|
||||
TEST_FILES=$(find . -name "*_test.go" -not -path "./vendor/*" | wc -l)
|
||||
if [ "$TEST_FILES" -gt 0 ]; then
|
||||
log_pass "Found $TEST_FILES test file(s)"
|
||||
else
|
||||
log_warning "No test files found"
|
||||
log_suggestion "Add tests for your changes"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# Run tests
|
||||
log_check "Running Go tests..."
|
||||
if go test ./... -v > /tmp/test-output.txt 2>&1; then
|
||||
log_pass "All tests passed"
|
||||
else
|
||||
log_error "Some tests failed:"
|
||||
grep -E "FAIL|ERROR" /tmp/test-output.txt | head -10 | sed 's/^/ /' || true
|
||||
log_suggestion "Fix failing tests:"
|
||||
log_command "go test ./... -v"
|
||||
echo ""
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# ═══════════════════════════════════════════
|
||||
# 4. CODE QUALITY - FRONTEND
|
||||
# ═══════════════════════════════════════════
|
||||
if [ -d "web" ]; then
|
||||
log_section "4. Frontend Code Quality"
|
||||
|
||||
# Check if npm is installed
|
||||
if ! command -v npm &> /dev/null; then
|
||||
log_warning "npm not installed - skipping frontend checks"
|
||||
log_suggestion "Install Node.js: https://nodejs.org/"
|
||||
else
|
||||
cd web
|
||||
|
||||
# Check if node_modules exists
|
||||
if [ ! -d "node_modules" ]; then
|
||||
log_warning "Dependencies not installed"
|
||||
log_suggestion "Install dependencies:"
|
||||
log_command "cd web && npm install"
|
||||
cd ..
|
||||
else
|
||||
# Check linting
|
||||
log_check "Frontend linting"
|
||||
if npm run lint > /tmp/lint-output.txt 2>&1; then
|
||||
log_pass "No linting issues"
|
||||
else
|
||||
log_error "Linting issues found:"
|
||||
tail -20 /tmp/lint-output.txt | sed 's/^/ /' || true
|
||||
log_suggestion "Fix linting issues:"
|
||||
log_command "cd web && npm run lint -- --fix"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# Check type errors
|
||||
log_check "TypeScript type checking"
|
||||
if npm run type-check > /tmp/typecheck-output.txt 2>&1; then
|
||||
log_pass "No type errors"
|
||||
else
|
||||
log_error "Type errors found:"
|
||||
tail -20 /tmp/typecheck-output.txt | sed 's/^/ /' || true
|
||||
log_suggestion "Fix type errors in your code"
|
||||
echo ""
|
||||
fi
|
||||
|
||||
# Check build
|
||||
log_check "Frontend build"
|
||||
if npm run build > /tmp/build-output.txt 2>&1; then
|
||||
log_pass "Build successful"
|
||||
else
|
||||
log_error "Build failed:"
|
||||
tail -20 /tmp/build-output.txt | sed 's/^/ /' || true
|
||||
log_suggestion "Fix build errors"
|
||||
echo ""
|
||||
fi
|
||||
fi
|
||||
|
||||
cd ..
|
||||
fi
|
||||
fi
|
||||
|
||||
# ═══════════════════════════════════════════
|
||||
# 5. PR SIZE CHECK
|
||||
# ═══════════════════════════════════════════
|
||||
log_section "5. PR Size"
|
||||
|
||||
if git remote | grep -q "^upstream$"; then
|
||||
ADDED=$(git diff --numstat upstream/dev...HEAD | awk '{sum+=$1} END {print sum+0}')
|
||||
DELETED=$(git diff --numstat upstream/dev...HEAD | awk '{sum+=$2} END {print sum+0}')
|
||||
TOTAL=$((ADDED + DELETED))
|
||||
FILES_CHANGED=$(git diff --name-only upstream/dev...HEAD | wc -l)
|
||||
|
||||
echo -e "${BLUE}Lines changed: ${GREEN}+$ADDED ${RED}-$DELETED ${NC}(total: $TOTAL)"
|
||||
echo -e "${BLUE}Files changed: ${GREEN}$FILES_CHANGED${NC}"
|
||||
echo ""
|
||||
|
||||
if [ "$TOTAL" -lt 100 ]; then
|
||||
log_pass "Small PR (<100 lines) - ideal for quick review"
|
||||
elif [ "$TOTAL" -lt 500 ]; then
|
||||
log_pass "Medium PR (100-500 lines) - reasonable size"
|
||||
elif [ "$TOTAL" -lt 1000 ]; then
|
||||
log_warning "Large PR (500-1000 lines) - consider splitting"
|
||||
log_suggestion "Breaking into smaller PRs makes review faster"
|
||||
else
|
||||
log_error "Very large PR (>1000 lines) - strongly consider splitting"
|
||||
log_suggestion "Split into multiple smaller PRs, each with a focused change"
|
||||
echo ""
|
||||
fi
|
||||
fi
|
||||
|
||||
# ═══════════════════════════════════════════
|
||||
# 6. DOCUMENTATION CHECK
|
||||
# ═══════════════════════════════════════════
|
||||
log_section "6. Documentation"
|
||||
|
||||
# Check if README or docs were updated
|
||||
log_check "Documentation updates"
|
||||
if git remote | grep -q "^upstream$"; then
|
||||
DOC_CHANGES=$(git diff --name-only upstream/dev...HEAD | grep -E "\.(md|txt)$" || true)
|
||||
|
||||
if [ -n "$DOC_CHANGES" ]; then
|
||||
log_pass "Documentation files updated"
|
||||
echo "$DOC_CHANGES" | sed 's/^/ - /'
|
||||
else
|
||||
# Check if this is a feature/fix that might need docs
|
||||
COMMIT_TYPES=$(git log --pretty=%s upstream/dev..HEAD | grep -oE "^(feat|fix)" || true)
|
||||
if [ -n "$COMMIT_TYPES" ]; then
|
||||
log_warning "No documentation updates found"
|
||||
log_suggestion "Consider updating docs if your changes affect usage"
|
||||
echo ""
|
||||
else
|
||||
log_pass "No documentation update needed"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# ═══════════════════════════════════════════
|
||||
# 7. ROADMAP ALIGNMENT
|
||||
# ═══════════════════════════════════════════
|
||||
log_section "7. Roadmap Alignment"
|
||||
|
||||
log_check "Does your PR align with the roadmap?"
|
||||
echo ""
|
||||
echo "Current priorities (Phase 1):"
|
||||
echo " ✅ Security enhancements"
|
||||
echo " ✅ AI model integrations"
|
||||
echo " ✅ Exchange integrations (OKX, Bybit, Lighter, EdgeX)"
|
||||
echo " ✅ UI/UX improvements"
|
||||
echo " ✅ Performance optimizations"
|
||||
echo " ✅ Bug fixes"
|
||||
echo ""
|
||||
log_suggestion "Check roadmap: https://github.com/tinkle-community/nofx/blob/dev/docs/roadmap/README.md"
|
||||
echo ""
|
||||
|
||||
# ═══════════════════════════════════════════
|
||||
# FINAL REPORT
|
||||
# ═══════════════════════════════════════════
|
||||
log_section "Summary Report"
|
||||
|
||||
echo ""
|
||||
echo -e "${GREEN}✅ Passed checks: $PASSED_CHECKS${NC}"
|
||||
echo -e "${YELLOW}⚠️ Warnings: $WARNINGS_FOUND${NC}"
|
||||
echo -e "${RED}❌ Issues found: $ISSUES_FOUND${NC}"
|
||||
echo ""
|
||||
|
||||
# Overall assessment
|
||||
if [ "$ISSUES_FOUND" -eq 0 ] && [ "$WARNINGS_FOUND" -eq 0 ]; then
|
||||
echo "╔═══════════════════════════════════════════╗"
|
||||
echo "║ 🎉 Excellent! Your PR looks great! ║"
|
||||
echo "║ Ready to submit or update your PR ║"
|
||||
echo "╚═══════════════════════════════════════════╝"
|
||||
elif [ "$ISSUES_FOUND" -eq 0 ]; then
|
||||
echo "╔═══════════════════════════════════════════╗"
|
||||
echo "║ 👍 Good! Minor warnings found ║"
|
||||
echo "║ Consider addressing warnings ║"
|
||||
echo "╚═══════════════════════════════════════════╝"
|
||||
elif [ "$ISSUES_FOUND" -le 3 ]; then
|
||||
echo "╔═══════════════════════════════════════════╗"
|
||||
echo "║ ⚠️ Issues found - Please fix ║"
|
||||
echo "║ See suggestions above ║"
|
||||
echo "╚═══════════════════════════════════════════╝"
|
||||
else
|
||||
echo "╔═══════════════════════════════════════════╗"
|
||||
echo "║ ❌ Multiple issues found ║"
|
||||
echo "║ Please address issues before submitting ║"
|
||||
echo "╚═══════════════════════════════════════════╝"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "📖 Next steps:"
|
||||
echo ""
|
||||
|
||||
if [ "$ISSUES_FOUND" -gt 0 ] || [ "$WARNINGS_FOUND" -gt 0 ]; then
|
||||
echo "1. Fix the issues and warnings listed above"
|
||||
echo "2. Run this script again to verify: ./scripts/pr-check.sh"
|
||||
echo "3. Commit your fixes"
|
||||
echo "4. Push to your PR: git push origin $CURRENT_BRANCH"
|
||||
else
|
||||
echo "1. Push your changes: git push origin $CURRENT_BRANCH"
|
||||
echo "2. Create or update your PR on GitHub"
|
||||
echo "3. Wait for automated CI checks"
|
||||
echo "4. Address reviewer feedback"
|
||||
fi
|
||||
|
||||
echo ""
|
||||
echo "📚 Resources:"
|
||||
echo " - Contributing Guide: https://github.com/tinkle-community/nofx/blob/dev/CONTRIBUTING.md"
|
||||
echo " - Migration Guide: https://github.com/tinkle-community/nofx/blob/dev/docs/community/MIGRATION_ANNOUNCEMENT.md"
|
||||
echo ""
|
||||
|
||||
# Cleanup temp files
|
||||
rm -f /tmp/vet-output.txt /tmp/test-output.txt /tmp/lint-output.txt /tmp/typecheck-output.txt /tmp/build-output.txt
|
||||
|
||||
echo "✨ Analysis complete! Good luck with your PR! 🚀"
|
||||
echo ""
|
||||
335
scripts/pr-fix.sh
Executable file
335
scripts/pr-fix.sh
Executable file
@@ -0,0 +1,335 @@
|
||||
#!/bin/bash
|
||||
|
||||
# 🔄 PR Migration Script for Contributors
|
||||
# This script helps you migrate your PR to the new format
|
||||
# Run this in your local fork to update your PR automatically
|
||||
|
||||
set -e
|
||||
|
||||
# Colors
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m' # No Color
|
||||
|
||||
# Helper functions
|
||||
log_info() {
|
||||
echo -e "${BLUE}ℹ️ $1${NC}"
|
||||
}
|
||||
|
||||
log_success() {
|
||||
echo -e "${GREEN}✅ $1${NC}"
|
||||
}
|
||||
|
||||
log_warning() {
|
||||
echo -e "${YELLOW}⚠️ $1${NC}"
|
||||
}
|
||||
|
||||
log_error() {
|
||||
echo -e "${RED}❌ $1${NC}"
|
||||
}
|
||||
|
||||
confirm() {
|
||||
read -p "$(echo -e ${YELLOW}"$1 (y/N): "${NC})" -n 1 -r
|
||||
echo
|
||||
[[ $REPLY =~ ^[Yy]$ ]]
|
||||
}
|
||||
|
||||
# Welcome message
|
||||
echo ""
|
||||
echo "╔═══════════════════════════════════════════╗"
|
||||
echo "║ NOFX PR Migration Tool ║"
|
||||
echo "║ Migrate your PR to the new format ║"
|
||||
echo "╚═══════════════════════════════════════════╝"
|
||||
echo ""
|
||||
|
||||
# Check if we're in a git repo
|
||||
if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
|
||||
log_error "Not a git repository. Please run this from your NOFX fork."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Check current branch
|
||||
CURRENT_BRANCH=$(git rev-parse --abbrev-ref HEAD)
|
||||
log_info "Current branch: $CURRENT_BRANCH"
|
||||
|
||||
if [ "$CURRENT_BRANCH" = "main" ] || [ "$CURRENT_BRANCH" = "dev" ]; then
|
||||
log_warning "You're on the $CURRENT_BRANCH branch."
|
||||
log_info "This script should be run on your PR branch."
|
||||
|
||||
# List branches
|
||||
log_info "Your branches:"
|
||||
git branch
|
||||
|
||||
echo ""
|
||||
read -p "Enter your PR branch name: " PR_BRANCH
|
||||
|
||||
if [ -z "$PR_BRANCH" ]; then
|
||||
log_error "No branch specified. Exiting."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
git checkout "$PR_BRANCH" || {
|
||||
log_error "Failed to checkout branch $PR_BRANCH"
|
||||
exit 1
|
||||
}
|
||||
|
||||
CURRENT_BRANCH="$PR_BRANCH"
|
||||
fi
|
||||
|
||||
log_success "Working on branch: $CURRENT_BRANCH"
|
||||
|
||||
echo ""
|
||||
log_info "What this script will do:"
|
||||
echo " 1. ✅ Verify you're rebased on latest upstream/dev"
|
||||
echo " 2. ✅ Check and format Go code (go fmt)"
|
||||
echo " 3. ✅ Run Go linting (go vet)"
|
||||
echo " 4. ✅ Run Go tests"
|
||||
echo " 5. ✅ Check frontend code (if modified)"
|
||||
echo " 6. ✅ Give you feedback and suggestions"
|
||||
echo ""
|
||||
log_warning "Make sure you've already run: git fetch upstream && git rebase upstream/dev"
|
||||
echo ""
|
||||
|
||||
if ! confirm "Continue with migration?"; then
|
||||
log_info "Migration cancelled"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Step 1: Verify upstream sync
|
||||
echo ""
|
||||
log_info "Step 1: Verifying upstream sync..."
|
||||
|
||||
# Check if upstream remote exists
|
||||
if ! git remote | grep -q "^upstream$"; then
|
||||
log_warning "Upstream remote not found. Adding it..."
|
||||
git remote add upstream https://github.com/tinkle-community/nofx.git
|
||||
git fetch upstream
|
||||
log_success "Added upstream remote"
|
||||
fi
|
||||
|
||||
# Check if we're up to date with upstream/dev
|
||||
if git merge-base --is-ancestor upstream/dev HEAD; then
|
||||
log_success "Your branch is up to date with upstream/dev"
|
||||
else
|
||||
log_warning "Your branch is not based on latest upstream/dev"
|
||||
log_info "Please run first: git fetch upstream && git rebase upstream/dev"
|
||||
|
||||
if confirm "Try to rebase now?"; then
|
||||
git fetch upstream
|
||||
if git rebase upstream/dev; then
|
||||
log_success "Successfully rebased on upstream/dev"
|
||||
else
|
||||
log_error "Rebase failed. Please resolve conflicts manually."
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
log_warning "Skipping rebase. Results may not be accurate."
|
||||
fi
|
||||
fi
|
||||
|
||||
# Step 2: Backend checks (if Go files exist)
|
||||
if find . -name "*.go" -not -path "./vendor/*" | grep -q .; then
|
||||
echo ""
|
||||
log_info "Step 2: Running backend checks..."
|
||||
|
||||
# Check if Go is installed
|
||||
if ! command -v go &> /dev/null; then
|
||||
log_warning "Go not found. Skipping backend checks."
|
||||
log_info "Install Go: https://go.dev/doc/install"
|
||||
else
|
||||
# Format Go code
|
||||
log_info "Formatting Go code..."
|
||||
if go fmt ./...; then
|
||||
log_success "Go code formatted"
|
||||
|
||||
# Check if there are changes
|
||||
if ! git diff --quiet; then
|
||||
log_info "Formatting created changes. Committing..."
|
||||
git add .
|
||||
git commit -m "chore: format Go code with go fmt" || true
|
||||
fi
|
||||
else
|
||||
log_warning "Go formatting had issues (non-critical)"
|
||||
fi
|
||||
|
||||
# Run go vet
|
||||
log_info "Running go vet..."
|
||||
if go vet ./...; then
|
||||
log_success "Go vet passed"
|
||||
else
|
||||
log_warning "Go vet found issues. Please review them."
|
||||
if confirm "Continue anyway?"; then
|
||||
log_info "Continuing..."
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Run tests
|
||||
log_info "Running Go tests..."
|
||||
if go test ./...; then
|
||||
log_success "All Go tests passed"
|
||||
else
|
||||
log_warning "Some tests failed. Please fix them before pushing."
|
||||
if confirm "Continue anyway?"; then
|
||||
log_info "Continuing..."
|
||||
else
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
else
|
||||
log_info "Step 2: No Go files found, skipping backend checks"
|
||||
fi
|
||||
|
||||
# Step 3: Frontend checks (if web directory exists)
|
||||
if [ -d "web" ]; then
|
||||
echo ""
|
||||
log_info "Step 3: Running frontend checks..."
|
||||
|
||||
# Check if npm is installed
|
||||
if ! command -v npm &> /dev/null; then
|
||||
log_warning "npm not found. Skipping frontend checks."
|
||||
log_info "Install Node.js: https://nodejs.org/"
|
||||
else
|
||||
cd web
|
||||
|
||||
# Install dependencies if needed
|
||||
if [ ! -d "node_modules" ]; then
|
||||
log_info "Installing dependencies..."
|
||||
npm install
|
||||
fi
|
||||
|
||||
# Run linter
|
||||
log_info "Running linter..."
|
||||
if npm run lint; then
|
||||
log_success "Linting passed"
|
||||
else
|
||||
log_warning "Linting found issues"
|
||||
log_info "Attempting to auto-fix..."
|
||||
npm run lint -- --fix || true
|
||||
|
||||
# Commit fixes if any
|
||||
if ! git diff --quiet; then
|
||||
git add .
|
||||
git commit -m "chore: fix linting issues" || true
|
||||
fi
|
||||
fi
|
||||
|
||||
# Type check
|
||||
log_info "Running type check..."
|
||||
if npm run type-check; then
|
||||
log_success "Type checking passed"
|
||||
else
|
||||
log_warning "Type checking found issues. Please fix them."
|
||||
fi
|
||||
|
||||
# Build
|
||||
log_info "Testing build..."
|
||||
if npm run build; then
|
||||
log_success "Build successful"
|
||||
else
|
||||
log_error "Build failed. Please fix build errors."
|
||||
cd ..
|
||||
exit 1
|
||||
fi
|
||||
|
||||
cd ..
|
||||
fi
|
||||
else
|
||||
log_info "Step 3: No frontend changes, skipping frontend checks"
|
||||
fi
|
||||
|
||||
# Step 4: Check PR title format
|
||||
echo ""
|
||||
log_info "Step 4: Checking PR title format..."
|
||||
|
||||
# Get the commit messages to suggest a title
|
||||
COMMITS=$(git log upstream/dev..HEAD --oneline)
|
||||
COMMIT_COUNT=$(echo "$COMMITS" | wc -l | tr -d ' ')
|
||||
|
||||
log_info "Found $COMMIT_COUNT commit(s) in your PR"
|
||||
|
||||
if [ "$COMMIT_COUNT" -eq 1 ]; then
|
||||
SUGGESTED_TITLE=$(git log -1 --pretty=%s)
|
||||
else
|
||||
SUGGESTED_TITLE=$(git log --pretty=%s upstream/dev..HEAD | head -1)
|
||||
fi
|
||||
|
||||
log_info "Current/suggested title: $SUGGESTED_TITLE"
|
||||
|
||||
# Check if it follows conventional commits
|
||||
if echo "$SUGGESTED_TITLE" | grep -qE "^(feat|fix|docs|style|refactor|perf|test|chore|ci|security)(\(.+\))?: .+"; then
|
||||
log_success "Title follows Conventional Commits format"
|
||||
else
|
||||
log_warning "Title doesn't follow Conventional Commits format"
|
||||
echo ""
|
||||
echo "Conventional Commits format:"
|
||||
echo " <type>(<scope>): <description>"
|
||||
echo ""
|
||||
echo "Types: feat, fix, docs, style, refactor, perf, test, chore, ci, security"
|
||||
echo ""
|
||||
echo "Examples:"
|
||||
echo " feat(exchange): add OKX integration"
|
||||
echo " fix(trader): resolve position tracking bug"
|
||||
echo " docs(readme): update installation guide"
|
||||
echo ""
|
||||
|
||||
read -p "Enter new title (or press Enter to keep current): " NEW_TITLE
|
||||
|
||||
if [ -n "$NEW_TITLE" ]; then
|
||||
log_info "You can update the PR title on GitHub after pushing"
|
||||
log_info "Suggested title: $NEW_TITLE"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Step 5: Push changes
|
||||
echo ""
|
||||
log_info "Step 5: Ready to push changes"
|
||||
|
||||
# Check if there are changes to push
|
||||
if git diff upstream/dev..HEAD --quiet; then
|
||||
log_info "No changes to push"
|
||||
else
|
||||
log_info "Changes ready to push to origin/$CURRENT_BRANCH"
|
||||
|
||||
if confirm "Push changes now?"; then
|
||||
log_info "Pushing to origin/$CURRENT_BRANCH..."
|
||||
if git push -f origin "$CURRENT_BRANCH"; then
|
||||
log_success "Successfully pushed changes!"
|
||||
else
|
||||
log_error "Failed to push. You may need to push manually:"
|
||||
echo " git push -f origin $CURRENT_BRANCH"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
log_info "Skipped push. You can push manually later:"
|
||||
echo " git push -f origin $CURRENT_BRANCH"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Summary
|
||||
echo ""
|
||||
echo "╔═══════════════════════════════════════════╗"
|
||||
echo "║ ✅ Migration Complete! ║"
|
||||
echo "╚═══════════════════════════════════════════╝"
|
||||
echo ""
|
||||
|
||||
log_success "Your PR has been migrated!"
|
||||
|
||||
echo ""
|
||||
log_info "Next steps:"
|
||||
echo " 1. Check your PR on GitHub"
|
||||
echo " 2. Update PR title if needed (Conventional Commits format)"
|
||||
echo " 3. Wait for CI checks to run"
|
||||
echo " 4. Address any reviewer feedback"
|
||||
echo ""
|
||||
|
||||
log_info "Need help? Ask in the PR comments or Telegram!"
|
||||
log_info "Telegram: https://t.me/nofx_dev_community"
|
||||
|
||||
echo ""
|
||||
log_success "Thank you for contributing to NOFX! 🚀"
|
||||
echo ""
|
||||
Reference in New Issue
Block a user