Skip to content

Commit

Permalink
✨ adding maintainability json output
Browse files Browse the repository at this point in the history
  • Loading branch information
MaaniBeigy committed Aug 11, 2024
1 parent ee5b056 commit 5752970
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .logs/maintainability.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"maintainability": "93.8%%"
}
Binary file modified .logs/maintainability.txt
Binary file not shown.
38 changes: 38 additions & 0 deletions .shell/maintainability.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Delete the 'maintainability.txt' file if it exists
Get-ChildItem -Path . -Recurse -Filter 'maintainability.txt' | Remove-Item -Force

# Run radon to calculate the maintainability index and save the output to a log file
poetry run python -m radon mi pycvcqv -s | Out-File -FilePath ".logs/maintainability.txt" -Append

# Extract and calculate the maintainability score
$maintainabilityScores = poetry run python -m radon mi pycvcqv -s | Select-String -Pattern '\((.*?)\)' | ForEach-Object {
$_.Matches.Value.Trim('()')
}

# Calculate the average maintainability score
$total = 0
$count = 0

foreach ($score in $maintainabilityScores) {
$total += [double]$score
$count++
}

$averageMaintainability = if ($count -gt 0) {
$average = $total / $count
"{0:N1}%%" -f $average
}
else {
"0.0%%"
}

# Output the maintainability score (for verification)
Write-Output "maintainability: $averageMaintainability"

# Create an object to store the maintainability in JSON format
$jsonOutput = @{
maintainability = $averageMaintainability
} | ConvertTo-Json

# Save the JSON output to a file
$jsonOutput | Set-Content -Path ".logs/maintainability.json"

0 comments on commit 5752970

Please sign in to comment.