Skip to content

Commit

Permalink
feat(Get-Stats.Cmd.ps1): add PowerShell script to retrieve git statis…
Browse files Browse the repository at this point in the history
…tics

The PowerShell script `Get-Stats.Cmd.ps1` has been added to the `Core/Commands/Get-Stats` directory. This script retrieves git statistics using the `git log` command with the `--numstat` and `--pretty=format:` options. It parses the output to extract the number of additions, deletions, and the filename for each commit. The script then groups the statistics by filename and calculates the total additions and deletions for each file. Finally, it sorts the statistics in descending order based on the total additions and deletions and selects the top N results specified by the `$Top` parameter.
  • Loading branch information
Bluzzi committed Jan 9, 2024
1 parent d5d7e27 commit 5295bbc
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Core/Commands/Get-Stats/Get-Stats.Cmd.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
function Get-Stats {
param(
[int]$Top = 10
)

$gitLogOutput = git log --numstat --pretty=format:

$stats = $gitLogOutput | ForEach-Object {
if ($_ -match '^(?<additions>\d+)\s+(?<deletions>\d+)\s+(?<filename>.+)$') {
[PSCustomObject]@{
Filename = $Matches['filename']
Additions = [int]$Matches['additions']
Deletions = [int]$Matches['deletions']
}
}
}

$groupedStats = $stats | Group-Object Filename | ForEach-Object {
[PSCustomObject]@{
Filename = $_.Name
TotalAdditions = ($_.Group | Measure-Object -Property Additions -Sum).Sum
TotalDeletions = ($_.Group | Measure-Object -Property Deletions -Sum).Sum
}
}

$sortedStats = $groupedStats | Sort-Object TotalAdditions, TotalDeletions -Descending

$sortedStats | Select-Object -First $Top
}

0 comments on commit 5295bbc

Please sign in to comment.