Skip to content

Commit

Permalink
docs: ChangesByCommitType Example ( Fixes #302, re #301 )
Browse files Browse the repository at this point in the history
  • Loading branch information
James Brundage committed Sep 25, 2024
1 parent 4403853 commit ce0e4fc
Showing 1 changed file with 46 additions and 0 deletions.
46 changes: 46 additions & 0 deletions Examples/ChangesByCommitType.ugit.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<#
.SYNOPSIS
Generates a Mermaid graph of changes by commit type.
.DESCRIPTION
Generates a Mermaid graph of changes by the conventional commit type.
#>
param()

Write-Information "Graphing $($MyInvocation.MyCommand.Name) for $($currentBranch.BranchName) branch."
$gitRemote = git remote
$headBranch = git remote |
Select-Object -First 1 |
git remote show |
Select-Object -ExpandProperty HeadBranch

$currentBranch = git branch | ? IsCurrentBranch


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

$groupedChangedSet = $commitList |
? { $_.CommitType } |
Group-Object { $_.CommitType } -NoElement

$mermaidDiagram = @(
"pie title Changes by Commit Type"
foreach ($changeSet in $groupedChangedSet) {
(' ' * 4),'"',$($changeSet.Name),'"',' : ',($changeSet.Count) -join ''
}
) -join [Environment]::NewLine

if ($env:GITHUB_STEP_SUMMARY) {
"
~~~mermaid
$mermaidDiagram
~~~
" |
Out-File -Append -FilePath $env:GITHUB_STEP_SUMMARY
}

0 comments on commit ce0e4fc

Please sign in to comment.