Skip to content

Commit 49fca7e

Browse files
committed
Add skeleton
1 parent fb00c39 commit 49fca7e

File tree

3 files changed

+450
-212
lines changed

3 files changed

+450
-212
lines changed

tools/ChangelogTools.psm1

Lines changed: 264 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,47 @@
33

44
#requires -Version 6.0
55

6-
using module ./GitHubTools.psm1
6+
using module .\GitHubTools.psm1
77

8-
class ChangelogItem
8+
class ChangeInfo
99
{
1010
[GitHubCommitInfo]$Commit
1111
[GitHubPR]$PR
1212
[GitHubIssue[]]$ClosedIssues
1313
[int]$IssueNumber = -1
1414
[int]$PRNumber = -1
1515
[string]$ContributingUser
16+
[string]$BodyText
17+
[string]$Subject
1618
}
1719

18-
filter Get-ChangelogItemFromCommit
20+
class ChangelogEntry
21+
{
22+
[uri]$IssueLink
23+
[uri]$PRLink
24+
[string]$Category
25+
[string[]]$Tags
26+
[string]$BodyText
27+
[string]$Subject
28+
[string]$Thanks
29+
[string]$RepositoryName
30+
[ChangeInfo]$Change
31+
}
32+
33+
class ChangeLog
34+
{
35+
ChangeLog()
36+
{
37+
$this.Sections = [System.Collections.Generic.Dictionary[string, ChangelogEntry]]::new()
38+
}
39+
40+
[string]$ReleaseName
41+
[datetime]$Date
42+
[string]$Preamble
43+
[System.Collections.Generic.Dictionary[string, ChangelogEntry]]$Sections
44+
}
45+
46+
filter Get-ChangeInfoFromCommit
1947
{
2048
param(
2149
[Parameter(Mandatory, ValueFromPipeline, Position=0)]
@@ -29,10 +57,10 @@ filter Get-ChangelogItemFromCommit
2957

3058
foreach ($singleCommit in $Commit)
3159
{
32-
$changelogItem = [ChangelogItem]@{
60+
$changelogItem = [ChangeInfo]@{
3361
Commit = $singleCommit
3462
BodyText = $singleCommit.Body
35-
ChangeLabels = $singleCommit.CommitLabels
63+
Subject = $singleCommit.Subject
3664
ContributingUser = $singleCommit.GitHubCommitData.author.login
3765
}
3866

@@ -54,12 +82,241 @@ filter Get-ChangelogItemFromCommit
5482
{
5583
$changelogItem.ClosedIssues = $closedIssueInfos | Get-GitHubIssue
5684
$changelogItem.IssueNumber = $closedIssueInfos[0].Number
57-
$changelogItem.Labels += ($closedIssueInfos | ForEach-Object { $_.Labels })
5885
}
5986
}
6087

6188
$changelogItem
6289
}
6390
}
6491

65-
Export-ModuleMember -Function Get-ChangelogItemFromCommit
92+
filter New-ChangelogEntry
93+
{
94+
param(
95+
[Parameter(Mandatory, ValueFromPipeline)]
96+
[ChangeInfo]
97+
$Change,
98+
99+
[Parameter(Mandatory)]
100+
[System.Collections.Specialized.OrderedDictionary]
101+
$EntryCategories,
102+
103+
[Parameter(Mandatory)]
104+
[hashtable]
105+
$DefaultCategory,
106+
107+
[Parameter(Mandatory)]
108+
[hashtable]
109+
$TagLabels,
110+
111+
[Parameter()]
112+
[string[]]
113+
$NoThanks = @(),
114+
115+
[Parameter()]
116+
[string]
117+
$Organization = 'PowerShell',
118+
119+
[Parameter()]
120+
[string]
121+
$Repository = 'vscode-powershell'
122+
)
123+
124+
[string[]]$tags = @()
125+
:labelLoop foreach ($issueLabel in $Change.ClosedIssues.Labels)
126+
{
127+
if (-not $entryCategory)
128+
{
129+
foreach ($category in $EntryCategories.GetEnumerator())
130+
{
131+
if ($issueLabel -in $category.Value.Issue)
132+
{
133+
$entryCategory = $category.Key
134+
continue :labelLoop
135+
}
136+
}
137+
}
138+
139+
$tag = $TagLabels[$issueLabel]
140+
if ($tag)
141+
{
142+
$tags += $tag
143+
}
144+
}
145+
146+
if (-not $entryCategory)
147+
{
148+
$entryCategory = $DefaultCategory.Name
149+
}
150+
151+
$issueLink = if ($Change.IssueNumber -ge 0) { "https://github.com/$Organization/$Repository/issues/$($Change.IssueNumber)" } else { $null }
152+
$prLink = if ($Change.PRNumber -ge 0) { "https://github.com/$Organization/$Repository/$($Change.PRNumber)" } else { $null }
153+
$thanks = if ($Change.ContributingUser -notin $NoThanks) { $Change.ContributingUser } else { $null }
154+
155+
$subject = $Change.Subject
156+
if ($subject -match '(.*)\(#\d+\)$')
157+
{
158+
$subject = $Matches[1]
159+
}
160+
161+
return [ChangelogEntry]@{
162+
IssueLink = $issueLink
163+
PRLink = $prLink
164+
Thanks = $thanks
165+
Category = $entryCategory
166+
Tags = $tags
167+
Change = $Change
168+
RepositoryName = "$Organization/$Repository"
169+
BodyText = $Change.BodyText
170+
Subject = $subject
171+
}
172+
}
173+
174+
filter Skip-IgnoredChanges
175+
{
176+
param(
177+
[Parameter(Mandatory, ValueFromPipeline)]
178+
[ChangeInfo]
179+
$Change,
180+
181+
[Parameter()]
182+
[string[]]
183+
$IgnoreUser,
184+
185+
[Parameter()]
186+
[string[]]
187+
$IgnoreCommitLabel
188+
)
189+
190+
if ($Change.ContributingUser -in $IgnoreUser)
191+
{
192+
return
193+
}
194+
195+
foreach ($commitLabel in $Change.Commit.CommitLabels)
196+
{
197+
if ($commitLabel -in $IgnoreCommitLabel)
198+
{
199+
return
200+
}
201+
}
202+
203+
return $Change
204+
}
205+
206+
function New-ChangeLogSection
207+
{
208+
param(
209+
[Parameter(Mandatory, ValueFromPipeline)]
210+
[ChangelogEntry[]]
211+
$ChangelogEntry,
212+
213+
[Parameter(Mandatory)]
214+
[string]
215+
$ReleaseName,
216+
217+
[Parameter(Mandatory)]
218+
[string[]]
219+
$Categories,
220+
221+
[Parameter(Mandatory)]
222+
[string]
223+
$DefaultCategory,
224+
225+
[Parameter()]
226+
[string]
227+
$Preamble,
228+
229+
[Parameter()]
230+
[string]
231+
$Postamble,
232+
233+
[Parameter()]
234+
[datetime]
235+
$Date = [datetime]::Now,
236+
237+
[Parameter()]
238+
[ValidateNotNullOrEmpty()]
239+
[string]
240+
$DateFormat = 'dddd, dd MM yyyy',
241+
242+
[Parameter()]
243+
[string]
244+
$Indent = ' '
245+
)
246+
247+
begin
248+
{
249+
$entries = [ordered]@{}
250+
251+
foreach ($category in $Categories)
252+
{
253+
$entries[$category] = [System.Collections.Generic.List[ChangelogEntry]]::new()
254+
}
255+
}
256+
257+
process
258+
{
259+
foreach ($entry in $ChangelogEntry)
260+
{
261+
$entries[$entry.Category].Add($entry)
262+
}
263+
}
264+
265+
end
266+
{
267+
$dateStr = $Date.ToString($DateFormat)
268+
$sb = [System.Text.StringBuilder]::new().AppendLine("## $ReleaseName").AppendLine("### $dateStr")
269+
270+
if ($Preamble)
271+
{
272+
[void]$sb.AppendLine($Preamble)
273+
}
274+
275+
[void]$sb.AppendLine()
276+
277+
foreach ($category in $entries.GetEnumerator())
278+
{
279+
if (-not $category.Value)
280+
{
281+
continue
282+
}
283+
284+
if ($category.Key -ne $DefaultCategory)
285+
{
286+
[void]$sb.AppendLine("$($category.Key):")
287+
}
288+
289+
foreach ($item in $category.Value)
290+
{
291+
$project= $item.Change.Commit.Repository
292+
$issueNumber = if ($item.Change.IssueNumber -ge 0) { $item.Change.IssueNumber } else { $null }
293+
$link = if ($item.PRLink) { $item.PRLink } else { $org = $item.Change.Commit.Organization; "https://github.com/$org/$project" }
294+
$thanks = $item.Thanks
295+
296+
[void]$sb.Append("- [$project")
297+
if ($issueNumber)
298+
{
299+
[void]$sb.Append(" #$issueNumber")
300+
}
301+
[void]$sb.AppendLine("]($link) -")
302+
303+
[void]$sb.Append($Indent).Append($item.Subject)
304+
if ($thanks)
305+
{
306+
[void]$sb.Append(" (Thanks @$thanks!)")
307+
}
308+
[void]$sb.AppendLine()
309+
}
310+
}
311+
312+
if ($Postamble)
313+
{
314+
[void]$sb.AppendLine($Postamble).AppendLine()
315+
}
316+
317+
return $sb.ToString()
318+
}
319+
}
320+
321+
322+
Export-ModuleMember -Function Get-ChangeInfoFromCommit,New-ChangelogEntry,Skip-IgnoredChanges,New-ChangeLogSection

0 commit comments

Comments
 (0)