refactor: use the new utils.ps1 script for operations

This commit is contained in:
Bjarke Sporring
2026-01-21 10:51:59 +01:00
parent 5582b9fcbd
commit 4b9d2449c8
8 changed files with 164 additions and 311 deletions

View File

@@ -10,52 +10,53 @@
- answers.txt exists with correct information about commit history
#>
. "$PSScriptRoot\..\..\util.ps1"
Write-Host "`n=== Verifying Module 02 Solution ===" -ForegroundColor Cyan
$allChecksPassed = $true
$challengeRoot = "$PSScriptRoot\challenge"
# Check if challenge directory exists
if (-not (Test-Path "challenge")) {
Write-Host "[FAIL] Challenge directory not found. Did you run setup.ps1?" -ForegroundColor Red
if (-not (Test-Path $challengeRoot)) {
Write-Fail "Challenge directory not found. Did you run setup.ps1?" -ForegroundColor Red
exit 1
}
Set-Location "challenge"
# Check if git repository exists
if (-not (Test-Path ".git")) {
Write-Host "[FAIL] Not a git repository. Did you run setup.ps1?" -ForegroundColor Red
Set-Location ..
if (-not (Test-Path "$challengeRoot\.git")) {
Write-Fail "Not a git repository. Did you run setup.ps1?" -ForegroundColor Red
exit 1
}
# Check if answers.md exists
if (-not (Test-Path "answers.md")) {
Write-Host "[FAIL] answers.md not found. Did you run setup.ps1?" -ForegroundColor Red
Write-Host "[HINT] The setup script should have created answers.md for you" -ForegroundColor Yellow
if (-not (Test-Path "$challengeRoot\answers.md")) {
Write-Fail "answers.md not found. Did you run setup.ps1?" -ForegroundColor Red
Write-Hint "The setup script should have created answers.md for you" -ForegroundColor Yellow
$allChecksPassed = $false
} else {
Write-Host "[PASS] answers.md exists" -ForegroundColor Green
Write-Pass "answers.md exists" -ForegroundColor Green
# Read the answers file
$answers = Get-Content "answers.md" -Raw
$answers = Get-Content "$challengeRoot\answers.md" -Raw
$answersLower = $answers.ToLower()
# Check 1: Contains "5" or "five" for commit count
if ($answersLower -match "5|five|fem") {
Write-Host "[PASS] Correct commit count found" -ForegroundColor Green
Write-Pass "Correct commit count found" -ForegroundColor Green
} else {
Write-Host "[FAIL] Commit count not found or incorrect" -ForegroundColor Red
Write-Host "[HINT] Use 'git log --oneline' to count commits easily" -ForegroundColor Yellow
Write-Fail "Commit count not found or incorrect" -ForegroundColor Red
Write-Hint "Use 'git log --oneline' to count commits easily" -ForegroundColor Yellow
$allChecksPassed = $false
}
# Check 2: Contains "database" keyword for third commit
if ($answersLower -match "database") {
Write-Host "[PASS] Third commit message identified" -ForegroundColor Green
Write-Pass "Third commit message identified" -ForegroundColor Green
} else {
Write-Host "[FAIL] Third commit message not found" -ForegroundColor Red
Write-Host "[HINT] Use 'git log' to see commit messages in order" -ForegroundColor Yellow
Write-Fail "Third commit message not found" -ForegroundColor Red
Write-Hint "Use 'git log' to see commit messages in order" -ForegroundColor Yellow
$allChecksPassed = $false
}
@@ -64,38 +65,37 @@ if (-not (Test-Path "answers.md")) {
$hasDatabase = $answersLower -match "database"
if ($hasAuth -and $hasDatabase) {
Write-Host "[PASS] Both files identified for bug fix commit" -ForegroundColor Green
Write-Pass "Both files identified for bug fix commit" -ForegroundColor Green
} elseif ($hasAuth -or $hasDatabase) {
Write-Host "[PARTIAL] Only one file found - there are TWO files modified in this commit" -ForegroundColor Yellow
Write-Host "[HINT] Use 'git log --stat' or 'git show <commit-hash> --name-only' to see ALL files changed" -ForegroundColor Yellow
Write-Hint "Use 'git log --stat' or 'git show <commit-hash> --name-only' to see ALL files changed" -ForegroundColor Yellow
$allChecksPassed = $false
} else {
Write-Host "[FAIL] Files modified in bug fix commit not found" -ForegroundColor Red
Write-Host "[HINT] Use 'git log --stat' to see which files were changed in each commit" -ForegroundColor Yellow
Write-Fail "Files modified in bug fix commit not found" -ForegroundColor Red
Write-Hint "Use 'git log --stat' to see which files were changed in each commit" -ForegroundColor Yellow
$allChecksPassed = $false
}
# Check 4: Contains "config" keyword for staged file
if ($answersLower -match "config.py") {
Write-Host "[PASS] Staged file identified" -ForegroundColor Green
Write-Pass "Staged file identified" -ForegroundColor Green
} else {
Write-Host "[FAIL] Staged file not identified" -ForegroundColor Red
Write-Host "[HINT] Use 'git status' or 'git diff --staged' to see staged changes" -ForegroundColor Yellow
Write-Fail "Staged file not identified" -ForegroundColor Red
Write-Hint "Use 'git status' or 'git diff --staged' to see staged changes" -ForegroundColor Yellow
$allChecksPassed = $false
}
# Check 5: Contains "unicorn" for the secret code
if ($answersLower -match "unicorn") {
Write-Host "[PASS] Secret code found!" -ForegroundColor Green
Write-Pass "Secret code found!" -ForegroundColor Green
} else {
Write-Host "[FAIL] Secret code not found" -ForegroundColor Red
Write-Host "[HINT] Use 'git diff <commit3> <commit4> database.py' to find the secret code" -ForegroundColor Yellow
Write-Fail "Secret code not found" -ForegroundColor Red
Write-Hint "Use 'git diff <commit3> <commit4> database.py' to find the secret code" -ForegroundColor Yellow
$allChecksPassed = $false
}
}
Set-Location ..
# Final summary
if ($allChecksPassed) {