/ scripts / report-git-sync.sh
report-git-sync.sh
  1  #!/bin/bash
  2  set -e
  3  
  4  # Colors for output
  5  RED='\033[0;31m'
  6  GREEN='\033[0;32m'
  7  YELLOW='\033[1;33m'
  8  NC='\033[0m' # No Color
  9  
 10  echo "================================="
 11  echo "📊 GIT-SYNC SYNC REPORT"
 12  echo "================================="
 13  echo "📅 Date: $(date)"
 14  echo ""
 15  
 16  # Helper function to print section headers
 17  print_section() {
 18      echo "---------------------------------"
 19      echo "📌 $1"
 20      echo "---------------------------------"
 21  }
 22  
 23  # Helper function to print success
 24  print_success() {
 25      echo -e "${GREEN}✅ $1${NC}"
 26  }
 27  
 28  # Helper function to print warning
 29  print_warning() {
 30      echo -e "${YELLOW}⚠️  $1${NC}"
 31  }
 32  
 33  # Helper function to print error
 34  print_error() {
 35      echo -e "${RED}❌ $1${NC}"
 36  }
 37  
 38  # 1. Check if Git-Sync Container is Running
 39  print_section "Container Status"
 40  if docker ps --format '{{.Names}}' | grep -q "git_sync_dev"; then
 41      print_success "Git-Sync container (git_sync_dev) is running."
 42  else
 43      print_error "Git-Sync container (git_sync_dev) is not running. Start it with: ./scripts/up-dev.sh"
 44      exit 1
 45  fi
 46  
 47  # 2. Get Latest Commit in Local Repository
 48  print_section "Local Repository Latest Commit"
 49  if docker exec git_sync_dev test -d "/repos/local/.git"; then
 50      LATEST_COMMIT=$(docker exec git_sync_dev git -C /repos/local rev-parse HEAD)
 51      LATEST_COMMIT_MSG=$(docker exec git_sync_dev git -C /repos/local log -1 --pretty=%B)
 52      LATEST_COMMIT_TIME=$(docker exec git_sync_dev git -C /repos/local log -1 --pretty=%cd)
 53      echo "Commit: $LATEST_COMMIT"
 54      echo "Message: $LATEST_COMMIT_MSG"
 55      echo "Time: $LATEST_COMMIT_TIME"
 56  else
 57      print_error "Local repository not initialized at /repos/local."
 58      exit 1
 59  fi
 60  
 61  # 3. Analyze Logs for Sync Activity
 62  print_section "Latest Sync Activity by Remote"
 63  while IFS='|' read -r remote_name type url enabled; do
 64      if [ "$enabled" -eq 1 ]; then
 65          echo "Remote: $remote_name ($type, $url)"
 66          # Search logs for the last sync to this remote
 67          LAST_SYNC=$(docker logs git_sync_dev 2>&1 | grep "Successfully synced.*$remote_name" | tail -n 1)
 68          if [ -n "$LAST_SYNC" ]; then
 69              # Extract timestamp and message
 70              TIMESTAMP=$(echo "$LAST_SYNC" | grep -oE "^\[[^]]+\]" | head -n 1)
 71              if [ "$type" = "git" ] || [ "$type" = "radicle" ]; then
 72                  # For Git and Radicle, assume the latest commit was synced
 73                  echo "Last Synced Commit: $LATEST_COMMIT"
 74                  echo "Commit Message: $LATEST_COMMIT_MSG"
 75              else
 76                  # For Rclone (IA, Web3), look for the bundle file name in logs
 77                  BUNDLE_FILE=$(echo "$LAST_SYNC" | grep -oE "repo-[0-9]+\.bundle" | head -n 1)
 78                  if [ -n "$BUNDLE_FILE" ]; then
 79                      echo "Last Synced Bundle: $BUNDLE_FILE"
 80                  else
 81                      echo "Last Synced Bundle: Unknown"
 82                  fi
 83              fi
 84              echo "Timestamp: $TIMESTAMP"
 85              print_success "Status: Successfully synced"
 86          else
 87              print_warning "Status: No successful sync found in logs for $remote_name"
 88          fi
 89          echo ""
 90      else
 91          print_warning "Skipping disabled remote: $remote_name"
 92          echo ""
 93      fi
 94  done < config/git-sync/remotes.conf
 95  
 96  # 4. Check for Failed Syncs
 97  print_section "Failed Syncs (Last 10 Errors)"
 98  FAILED_SYNCS=$(docker logs git_sync_dev 2>&1 | grep "\[ERROR\].*Failed to sync" | tail -n 10)
 99  if [ -n "$FAILED_SYNCS" ]; then
100      echo "$FAILED_SYNCS"
101  else
102      print_success "No failed syncs found in recent logs."
103  fi
104  
105  # 5. Summary
106  print_section "Summary"
107  echo "Latest Local Commit: $LATEST_COMMIT"
108  echo "Check the above sections for sync status per remote."
109  echo "If a remote has not been synced recently, check logs or run diagnostics:"
110  echo "  ./scripts/diagnose-git-sync.sh"
111  
112  echo ""
113  echo "================================="
114  echo "✅ Report Generation Completed"
115  echo "================================="