Skip to content

Commit

Permalink
docs: ChangesByDayOfWeek example ( Fixes #295 )
Browse files Browse the repository at this point in the history
  • Loading branch information
James Brundage committed Sep 25, 2024
1 parent 5534586 commit 5019296
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions Examples/ChangesByDayOfWeek.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<#
.SYNOPSIS
Generates a Mermaid graph of changes by day of week.
.DESCRIPTION
Generates a Mermaid graph of changes by day of week.
#>
param()

$gitRemote = git remote
$headBranch = git remote |
Select-Object -First 1 |
git remote show |
Select-Object -ExpandProperty HeadBranch

$currentBranch = git branch | ? IsCurrentBranch
if ($currentBranchName -eq $headBranch) {
Write-Warning "Not graphing the main branch."
return
}

$commitList =
if ($currentBranch -ne $headBranch) {
git log "$($gitRemote.RemoteName)/$headBranch..$CurrentBranch"
} else {
git log
}

$groupedChangedSet = $currentBranchCommits |
Group-Object { $_.CommitDate.DayOfWeek } -NoElement

if ($env:GITHUB_STEP_SUMMARY) {
"
~~~mermaid
$(
@(
"pie title Changes by Day Of Week"
foreach ($changeSet in $groupedChangedSet) {
(' ' * 4) + '"' + $($changeSet.Name) + '"' + ' : ' + ($changeSet.Count)
}
) -join [Environment]::NewLine)
~~~
" |
Out-File -Append -FilePath $env:GITHUB_STEP_SUMMARY
}

0 comments on commit 5019296

Please sign in to comment.