-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathpre-commit.ps1
More file actions
28 lines (23 loc) · 939 Bytes
/
pre-commit.ps1
File metadata and controls
28 lines (23 loc) · 939 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env powershell
# Initialize a variable to track errors
$errorOccurred = $false
$repoRoot = Get-Location # Git hooks run in the repository root
$metadataPath = Join-Path $repoRoot "metadata" # Metadata subdirectory
# Get all JSON files in the directory and its subdirectories
$jsonFiles = Get-ChildItem -Path $metadataPath -Recurse -Filter *.json
foreach ($file in $jsonFiles) {
try {
# Try to read and convert the JSON file to a PSObject or Hashtable object
# This will throw an error if the JSON is not valid
$jsonContent = Get-Content -Path $file.FullName -Raw | ConvertFrom-Json
} catch {
Write-Host "$($file.Name) has syntax errors."
$errorOccurred = $true
}
}
# Set the exit code based on whether any errors occurred
if ($errorOccurred) {
exit 1 # Exit with a non-zero code to indicate failure
} else {
exit 0 # Exit with zero code to indicate success
}