1+ Function ConvertTo-ChangeLog {
2+ <#
3+ . SYNOPSIS
4+ Converts a GitHistory's output to a readable Changelog
5+ Supported formats: .MD (default), .html
6+ . EXAMPLE
7+ $json = Get-GitHistory -asJson -Latest Major -tagprefix WebApp
8+ Convert-ChangeLog ($json) -FormatAs md
9+ Convert-ChangeLog ($json) -FormatAs html | Set-Clipboard
10+
11+ #>
12+ Param (
13+ [Parameter (ValueFromPipeline = $true )]
14+ $InputObject = $json
15+ ,
16+ #
17+ [ValidateSet (" md" , " html" )]
18+ [String ]
19+ $FormatAs = ' md'
20+ ,
21+ [string ]
22+ $TargetAudience
23+ ,
24+ [string ] $PackageUrl
25+ ,
26+ [string ] $ProjectName
27+
28+ )
29+ Begin {
30+ $Data = $InputObject | ConvertFrom-Json
31+ $Releases = $Data.Releases
32+ # $UPackageUri = "https://dev.azure.com/rdcinmotiv/imb-Operations/_packaging?_a=package&feed=WebdivPackages&package=frontplateprocessor&version=1.2.2&protocolType=UPack"
33+ $CommitBaseUri = " https://bitbucket.org/inmotivbelgium/$ProjectName /commits"
34+ $JiraIssueUri = " https://rdcgroup.atlassian.net/browse"
35+ $Components = $Releases.Component | Select-Object - Unique
36+ Write-Host " Documenting $ ( $Releases.Release -join ' , ' ) "
37+ }
38+ Process {
39+
40+ $Content = Switch ($formatAs ) {
41+ ' md' {
42+ " # Changelog (Updated on $ ( (Get-Date ).ToString(" yyyy-MM-dd" )) )"
43+ } ' html' {
44+ " <h1>Changelog (Updated on $ ( (Get-Date ).ToString(" yyyy-MM-dd" )) ) </h1>"
45+ }
46+ }
47+ ForEach ($Component in $Components ) {
48+ $content += Switch ($formatAs ) {
49+ ' md' { Write-Output " `n # $Component " }
50+ ' html' { Write-Output " `n <h1>$Component </h1>" }
51+ }
52+ $Content += ForEach ($Release in $Releases | Where-Object { $_.Component -eq $Component }) {
53+ $ReleaseName = $Release.Release
54+ $ReleaseDate = $Release.ReleaseDate
55+ $VersionId = [version ]$Release.Version
56+ If ($Minor -ne " $ ( $VersionId.Major ) .$ ( $VersionId.Minor ) " ) {
57+ $Minor = " $ ( $VersionId.Major ) .$ ( $VersionId.Minor ) "
58+ Switch ($formatAs ) {
59+ ' md' { Write-Output " `n ## $minor " }
60+ ' html' { Write-Output " `n <hr /><h2>$minor </h2>" }
61+ }
62+
63+ }
64+ If ($PackageUrl ) {
65+ $DownloadLink = " $PackageUrl " + " $VersionId "
66+ }
67+ $ReleaseCommits = ($Data.Releases | Where-Object { $_.Release -eq $Release.Release }).Commits
68+ Switch ($formatAs ) {
69+ ' md' {
70+ If ($PackageUrl ) { $DownloadLink = " [📥]($DownloadLink )" }
71+ $ReleaseTitle = " `n ### $ReleaseName [👨💻]($CommitBaseUri /$ ( $Release.ReleaseCommit ) ) $DownloadLink $ReleaseDate "
72+
73+ }' html' {
74+ If ($PackageUrl ) { $DownloadLink += " <a href=`" $DownloadLink `" >📥</a><" }
75+ $ReleaseTitle = " `n <h3>$ReleaseName </h3><p><a href=`" $CommitBaseUri /$ ( $Release.ReleaseCommit ) `" >👩💻</a>$DownloadLink -<i>$ReleaseDate </i></p>"
76+
77+ }
78+ }
79+ Write-Output $ReleaseTitle
80+ If ($ReleaseCommits -in $null , ' ' ) {
81+ Switch ($formatAs ) {
82+ ' md' { Write-Output " `n #### Re-build " }
83+ ' html' { Write-Output " `n <h4 style=`" margin-left: 30.0px;`" >Re-build 💫</h4>" }
84+ }
85+ Continue
86+ }
87+
88+ $Intents = $ReleaseCommits | Select-Object - ExpandProperty Intent - unique
89+ ForEach ($Intent in $Intents ) {
90+
91+ $messages = $ReleaseCommits | Where-Object { $_.Intent -eq $Intent -and $_.message -ne ' ' } |
92+ Foreach-object {
93+ If ($_.message -eq $currentmessage ) { return }
94+ $currentmessage = $_.message
95+ $Log = $_
96+ $CommitSHA = $_.CommitId.Substring (0 , 8 )
97+ $CommitLink = " $CommitBaseUri /$CommitId "
98+ $Output = Switch ($formatAs ) {
99+
100+ ' md' { Write-Output " - $ ( $Log.Message ) - @[$CommitSHA ]($CommitLink )" }
101+ ' html' { " $ ( $Log.Message ) - @<a href=`" $CommitLink `" >$CommitSHA </a>" }
102+ }
103+ If ($Log.IssueKey -notin $null , ' ' ) {
104+ $IssueKey = $Log.IssueKey
105+ # Place the issue key at the end
106+ $Output = $Output.Replace ($IssueKey , " " )
107+ $Output = Switch ($formatAs ) {
108+ ' md' { " $Output #[$IssueKey ]($JiraIssueUri /$IssueKey )" }
109+ ' html' { " $Output #<a href=`" $JiraIssueUri /$IssueKey `" >$IssueKey </a>" }
110+ }
111+ }
112+ Write-Output " $Output `n "
113+ }
114+ If ($messages ) {
115+ Write-debug ($messages | Out-String )
116+ Switch ($formatAs ) {
117+ ' md' {
118+ Write-Output " `n #### $Intent `n "
119+ Write-Output $messages
120+ }' html' {
121+ Write-Output " <h4 style=`" margin-left: 30.0px;`" >$Intent </h4>`n "
122+ Write-Output $messages | ForEach-Object { " <p style=`" margin-left: 60.0px;`" >$_ </p>" }
123+ }
124+ }
125+ }
126+ } # ForEach Intent
127+ } # ForEach Release
128+ } # ForEach Component
129+ Write-Output $Content
130+ } # Process
131+ }
0 commit comments