Skip to content

Commit ea3270d

Browse files
committed
👌 Add support for tags with no tagprefix
1 parent d5372e7 commit ea3270d

5 files changed

Lines changed: 189 additions & 29 deletions

File tree

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
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+
}

PSGitChangeLog/Public/Get-GitHistory.Tools.ps1

Lines changed: 34 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,22 +20,30 @@
2020
param(
2121
$Level
2222
,
23+
[string]
2324
$WorkDir
2425
,
26+
[int]
2527
$RequiredCommitMessageLength = 5
2628
,
29+
[string]
2730
$ProjectName
2831
,
32+
[string]
2933
$TagPrefix
3034
,
3135
[string]
3236
$RemoteName = 'origin'
3337
,
34-
[switch] $asJson
38+
[string]
39+
$OutputAs
3540
,
3641
[String]
3742
$Latest = ''
3843
# Specify to retrieve the latest Major, Minor, Build
44+
,
45+
[switch]
46+
$toChangelog
3947
)
4048
# Settings
4149
Begin {
@@ -98,11 +106,9 @@
98106
# Normalizing log entries
99107
$logs = @()
100108

101-
$TagValue = ''
109+
$TagValue = 'Unreleased'
102110

103111
$logs = ForEach ($Commit in $gitHist) {
104-
#$commit = $gitHist | select-object -first 1
105-
106112
#Set the current Version/Tag in the history
107113
$tag = $Releases | Where-Object { $_.Commit -eq $Commit.commitid } | Select-Object -last 1
108114
if ($tag) {
@@ -123,7 +129,7 @@
123129
Write-Host "Commit message: $message is considered too short ($RequiredCommitMessageLength). Ommitting from changelog..."
124130
Continue
125131
}
126-
$IssueKey = Test-JiraIssueKey($Commit.Subject)
132+
$IssueKey = Test-IssueKey($Commit.Subject)
127133
$log = [pscustomobject]@{
128134
Project = $ProjectName
129135
Release = $TagValue
@@ -141,7 +147,7 @@
141147
Write-Output $log
142148
} #ForEach
143149

144-
If (!$asJSON) { return $logs }
150+
If ($OutputAs -eq 'psobject') { return $logs }
145151

146152
$Releasedata = @()
147153

@@ -160,6 +166,16 @@
160166
$Releases = $Releases | Where-Object { $_.Major -eq $Major -and $_.Minor -eq $Minor }
161167
}
162168
}
169+
If ($logs | Where-Object { $_.Release -eq 'Unreleased' } ) {
170+
$Releasedata += [ordered]@{
171+
Release = 'Unreleased'
172+
ReleaseDate = ''
173+
Component = ''
174+
Version = ''
175+
ReleaseCommit = ''
176+
Commits = $logs | Where-Object { $_.Release -eq 'Unreleased'} | SOrt-Object -Property Order | Select-Object -Property * -ExcludeProperty Project, Release, Order
177+
}
178+
}
163179
Write-Host $Releases.Count Releases
164180
$Releasedata += ForEach ($Release in $Releases) {
165181
[ordered]@{
@@ -172,14 +188,21 @@
172188
}
173189
}
174190

175-
$Json = @{
191+
$Data = @{
176192
Project = $ProjectName
177193
Releases = $Releasedata
178194
}
179195

180-
$output = $Json | ConvertTo-Json -depth 4
181-
182-
Return $output
183-
196+
$Json = $Data | ConvertTo-Json -depth 4
197+
198+
If ($OutputAs -eq 'json') { Return $json }
199+
200+
If ($OutputAs -eq 'md'){
201+
$Changelog = ConvertTo-Changelog($Json) -FormatAs md
202+
Return $Changelog
203+
} elseif ($OutputAs -eq 'html') {
204+
$Changelog = ConvertTo-Changelog($Json) -FormatAs html
205+
Return $Changelog
206+
}
184207
}
185208
}

PSGitChangeLog/Public/Get-GitTagList.Tools.ps1

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,16 @@ Function Get-GitTagList {
3939
$tagDate = [datetime]::ParseExact($date.Substring(0, 19), 'yyyy-MM-dd HH:mm:ss', $null)
4040

4141
Try {
42-
$Tag = if ($TagPrefix) { "$TagPrefix-$SemVerId" } Else { "$TagValue" }
42+
if ($TagPrefix) {
43+
$tag = "$TagPrefix-$SemVerId"
44+
$component = $TagPrefix
45+
} Else {
46+
$tag = "$TagValue"
47+
$Component = If ($tagParts.count -gt 1) {$tagParts | Select-Object -First 1} Else {''}
48+
}
4349
$taglist += [pscustomobject]@{
4450
Tag = $Tag
45-
Component = $Tag -split '-' | Select-Object -first 1
51+
Component = $Component
4652
Commit = $commit
4753
Date = $tagDate
4854
SemVerId = $SemVerId
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Function Test-IssueKey {
2+
<#
3+
.SYNOPSIS
4+
Parses a string to detect (JIRA) issue keys and returns the key
5+
.EXAMPLE
6+
Test-IssueLinkKey('safdsf BISS-123 asdfasdf')
7+
Test-IssueLinkKey('safdsf BISS123 asdfasdf')
8+
#>
9+
Param (
10+
$String
11+
)
12+
$regex = '((?<!([A-Za-z]{1,10})-?)[A-Z]+-\d+)'
13+
If ($string -match $regex) {
14+
Return $matches.GetEnumerator() | Select-Object -ExpandProperty Value -Unique
15+
}
16+
}

PSGitChangeLog/Public/Test-JiraIssueKey.Tools.ps1

Lines changed: 0 additions & 16 deletions
This file was deleted.

0 commit comments

Comments
 (0)