Last active
September 1, 2024 19:25
-
-
Save JesseGuerrero/740667982c93f113eaf8eba0620d9eb6 to your computer and use it in GitHub Desktop.
Get Lines Changed Highscores (Powershell)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #Run in top directory of Git project and run the powershell script | |
| #You can also ask ChatGPT to change this to Java or Python, etc. | |
| $authorStats = @{} | |
| $author = "" | |
| git log --pretty="%H|%an" --numstat | ForEach-Object { | |
| # If the line starts with digits, it's a file change entry | |
| if ($_ -match "^\d+\s+\d+\s") { | |
| $parts = $_ -split "\s+" | |
| $add = [int]$parts[0] | |
| $subs = [int]$parts[1] | |
| # Ensure author is valid before adding stats | |
| if ($author -ne "") { | |
| $authorStats[$author].Add += $add | |
| $authorStats[$author].Subs += $subs | |
| } | |
| } | |
| # If the line contains "|", it's a new commit entry | |
| elseif ($_ -match "\|") { | |
| $parts = $_ -split "\|" | |
| $author = $parts[1].Trim() | |
| # Initialize the author's stats if not already done | |
| if (-not $authorStats.ContainsKey($author)) { | |
| $authorStats[$author] = New-Object PSObject -Property @{ | |
| Add = 0 | |
| Subs = 0 | |
| } | |
| } | |
| } | |
| } | |
| # Output the results | |
| $authorStats.GetEnumerator() | ForEach-Object { | |
| $author = $_.Key | |
| $add = $_.Value.Add | |
| $subs = $_.Value.Subs | |
| $changed = $add + $subs | |
| Write-Output "${author}:`n Added lines: $add`n Removed lines: $subs`n Changed lines: $changed`n" | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment