Skip to content

Commit 7828d20

Browse files
baocinclaude
andcommitted
Improve preload script to detect successful scans
Updated scan_repo() function to check actual scan completion: - Captures git clone output to temp file - Checks for git.vet scan indicators (not just exit code) - Counts as success if scan completed, even if git clone failed - Extracts and displays findings count from output - Shows specific error messages when scans truly fail This fixes false negatives where scans complete successfully but git protocol returns non-zero exit code. Example output: [✓] [1/27] OWASP/WebGoat - Scan completed (123 findings) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 45bf869 commit 7828d20

1 file changed

Lines changed: 21 additions & 6 deletions

File tree

scripts/preload-cache.sh

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,22 +142,37 @@ scan_repo() {
142142
fi
143143

144144
local repo_dir="${TEMP_DIR}/$(echo "$repo" | tr '/' '_')"
145+
local output_file="${TEMP_DIR}/output_${index}.log"
145146

146147
log_info "[$index/$TOTAL] Scanning $repo..."
147148

148-
# Clone with timeout
149-
if timeout 300 git clone --depth 1 "$clone_url" "$repo_dir" > /dev/null 2>&1; then
150-
log_success "[$index/$TOTAL] $repo - Scan completed"
151-
rm -rf "$repo_dir"
149+
# Clone with timeout, capture output
150+
timeout 300 git clone --depth 1 "$clone_url" "$repo_dir" > "$output_file" 2>&1
151+
local exit_code=$?
152+
153+
# Check if scan actually completed by looking for git.vet output
154+
# The scan can complete successfully even if git clone returns non-zero
155+
if grep -q "git.vet.*Scan complete\|GIT.VET SECURITY REPORT\|findings" "$output_file"; then
156+
# Extract findings count if available
157+
local findings=$(grep -oP '\d+ findings' "$output_file" | head -1 || echo "")
158+
if [ -n "$findings" ]; then
159+
log_success "[$index/$TOTAL] $repo - Scan completed ($findings)"
160+
else
161+
log_success "[$index/$TOTAL] $repo - Scan completed"
162+
fi
163+
rm -rf "$repo_dir" "$output_file"
152164
return 0
153165
else
154-
local exit_code=$?
166+
# Check actual failure reason
155167
if [ $exit_code -eq 124 ]; then
156168
log_warn "[$index/$TOTAL] $repo - Timeout (>5min)"
169+
elif grep -q "fatal:\|error:" "$output_file"; then
170+
local error_msg=$(grep -m1 "fatal:\|error:" "$output_file" | cut -c1-60)
171+
log_error "[$index/$TOTAL] $repo - Failed: $error_msg"
157172
else
158173
log_error "[$index/$TOTAL] $repo - Failed (exit code: $exit_code)"
159174
fi
160-
rm -rf "$repo_dir" 2>/dev/null || true
175+
rm -rf "$repo_dir" "$output_file" 2>/dev/null || true
161176
return 1
162177
fi
163178
}

0 commit comments

Comments
 (0)