Skip to content

Commit 382a47e

Browse files
Robert Holtrjmholt
Robert Holt
authored andcommitted
Current
1 parent 49fca7e commit 382a47e

File tree

3 files changed

+128
-27
lines changed

3 files changed

+128
-27
lines changed

tools/ChangelogTools.psm1

Lines changed: 89 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55

66
using module .\GitHubTools.psm1
77

8+
class IgnoreConfiguration
9+
{
10+
[string[]]$User
11+
[string[]]$IssueLabel
12+
[string[]]$PRLabel
13+
[string[]]$CommitLabel
14+
}
15+
816
class ChangeInfo
917
{
1018
[GitHubCommitInfo]$Commit
@@ -180,26 +188,48 @@ filter Skip-IgnoredChanges
180188

181189
[Parameter()]
182190
[string[]]
183-
$IgnoreUser,
191+
$User,
184192

185193
[Parameter()]
186194
[string[]]
187-
$IgnoreCommitLabel
195+
$CommitLabel,
196+
197+
[Parameter()]
198+
[string[]]
199+
$IssueLabel,
200+
201+
[Parameter()]
202+
[string[]]
203+
$PRLabel
188204
)
189205

190-
if ($Change.ContributingUser -in $IgnoreUser)
206+
if ($Change.ContributingUser -in $User)
191207
{
192208
return
193209
}
194210

195-
foreach ($commitLabel in $Change.Commit.CommitLabels)
211+
foreach ($changeCommitLabel in $Change.Commit.CommitLabels)
196212
{
197-
if ($commitLabel -in $IgnoreCommitLabel)
213+
if ($changeCommitLabel -in $CommitLabel)
198214
{
199215
return
200216
}
201217
}
202218

219+
foreach ($changeIssueLabel in $Change.Commit.IssueLabels)
220+
{
221+
if ($changeIssueLabel -in $IssueLabel)
222+
{
223+
return
224+
}
225+
}
226+
227+
foreach ($changePRLabel in $Change.Commit.PRLabels)
228+
{
229+
if ()
230+
}
231+
232+
203233
return $Change
204234
}
205235

@@ -288,19 +318,40 @@ function New-ChangeLogSection
288318

289319
foreach ($item in $category.Value)
290320
{
291-
$project= $item.Change.Commit.Repository
292-
$issueNumber = if ($item.Change.IssueNumber -ge 0) { $item.Change.IssueNumber } else { $null }
321+
# Set up the pieces needed for a changelog entry
322+
$project = $item.Change.Commit.Repository
293323
$link = if ($item.PRLink) { $item.PRLink } else { $org = $item.Change.Commit.Organization; "https://github.com/$org/$project" }
294324
$thanks = $item.Thanks
295325

296-
[void]$sb.Append("- [$project")
326+
$issueNumber = if ($item.Change.IssueNumber -ge 0)
327+
{
328+
$item.Change.IssueNumber
329+
}
330+
elseif ($item.Change.PRNumber -ge 0)
331+
{
332+
$item.Change.PRNumber
333+
}
334+
else
335+
{
336+
$null
337+
}
338+
339+
# Add the list bullet
340+
[void]$sb.Append('- ')
341+
342+
# Start with the tags
343+
if ($item.Tags)
344+
{
345+
[void]$sb.Append(($item.Tags -join ' ')).Append(' ')
346+
}
347+
348+
# Create a header for the change if there is an issue number
297349
if ($issueNumber)
298350
{
299-
[void]$sb.Append(" #$issueNumber")
351+
[void]$sb.AppendLine("[$project #$issueNumber]($link) -").Append($Indent)
300352
}
301-
[void]$sb.AppendLine("]($link) -")
302353

303-
[void]$sb.Append($Indent).Append($item.Subject)
354+
[void]$sb.Append($item.Subject)
304355
if ($thanks)
305356
{
306357
[void]$sb.Append(" (Thanks @$thanks!)")
@@ -311,12 +362,38 @@ function New-ChangeLogSection
311362

312363
if ($Postamble)
313364
{
314-
[void]$sb.AppendLine($Postamble).AppendLine()
365+
[void]$sb.AppendLine().AppendLine($Postamble)
315366
}
316367

368+
[void]$sb.AppendLine()
369+
317370
return $sb.ToString()
318371
}
319372
}
320373

374+
function New-ChangelogRelease
375+
{
376+
param(
377+
[Parameter(Mandatory)]
378+
[string]
379+
$GitHubToken,
380+
381+
[Parameter(Mandatory)]
382+
[string]
383+
$RepositoryPath,
384+
385+
[Parameter(Mandatory)]
386+
[string]
387+
$SinceRef,
388+
389+
[Parameter()]
390+
[string]
391+
$UntilRef = 'HEAD',
392+
393+
[Parameter()]
394+
[IgnoreConfiguration]
395+
$Ignore
396+
)
397+
}
321398

322399
Export-ModuleMember -Function Get-ChangeInfoFromCommit,New-ChangelogEntry,Skip-IgnoredChanges,New-ChangeLogSection

tools/GitHubTools.psm1

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -295,18 +295,21 @@ function Copy-GitRepository
295295
{
296296
Exec { git config core.autocrlf true }
297297

298-
foreach ($remote in $Remotes.get_Keys())
298+
if ($Remotes)
299299
{
300-
Exec { git remote add $remote $Remotes[$remote] }
301-
}
302-
303-
if ($PullUpstream -and $remote['upstream'])
304-
{
305-
Exec { git pull upstream $CloneBranch }
300+
foreach ($remote in $Remotes.get_Keys())
301+
{
302+
Exec { git remote add $remote $Remotes[$remote] }
303+
}
306304

307-
if ($UpdateOrigin)
305+
if ($PullUpstream -and $Remotes['upstream'])
308306
{
309-
Exec { git push origin "+$CloneBranch"}
307+
Exec { git pull upstream $CloneBranch }
308+
309+
if ($UpdateOrigin)
310+
{
311+
Exec { git push origin "+$CloneBranch"}
312+
}
310313
}
311314
}
312315

tools/changelog/updateChangelog.ps1

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ param(
3737

3838
[Parameter()]
3939
[string]
40-
$FromForm = 'rjmholt',
40+
$FromFork = 'rjmholt',
41+
42+
[Parameter()]
43+
[string]
44+
$ChangelogName = 'CHANGELOG.md',
4145

4246
[Parameter()]
4347
[string]
@@ -96,8 +100,8 @@ $clEntryParams = @{
96100
Issue = $categories[$defaultCategory].Issue
97101
}
98102
TagLabels = @{
99-
'Issue-Enhancement' = 'Feature'
100-
'Issue-Bug' = 'BugFix'
103+
'Issue-Enhancement' = ''
104+
'Issue-Bug' = '🐛'
101105
}
102106
NoThanks = @(
103107
'rjmholt'
@@ -108,6 +112,23 @@ $clEntryParams = @{
108112
)
109113
}
110114

115+
function UpdateChangelogFile
116+
{
117+
param(
118+
[Parameter(Mandatory)]
119+
[string]
120+
$NewSection,
121+
122+
[Parameter(Mandatory)]
123+
[string]
124+
$Path
125+
)
126+
127+
$changelogLines = Get-Content -Path $Path
128+
$newContent = ($changelogLines[0..1] -join "`n`n") + $NewSection + ($changelogLines[2..$changelogLines.Length] -join "`n")
129+
Set-Content -Encoding utf8NoBOM -Value $newContent -Path $Path
130+
}
131+
111132
$clSectionParams = @{
112133
Categories = $categories.Keys
113134
DefaultCategory = $defaultCategory
@@ -134,16 +155,16 @@ $cloneParams = @{
134155
}
135156
Copy-GitRepository @cloneParams
136157

137-
#UpdateGalleryFile -ExtensionVersion $ExtensionVersion -GalleryFilePath "$repoLocation/$GalleryFileName"
158+
UpdateChangelogFile -NewSection $newChangelogSection -Path "$repoLocation/$ChangelogName"
138159

139-
Submit-GitChanges -RepositoryLocation $repoLocation -File $GalleryFileName -Branch $branchName -Message "Update PS extension to v$ExtensionVersion"
160+
Submit-GitChanges -RepositoryLocation $repoLocation -File $GalleryFileName -Branch $branchName -Message "Update CHANGELOG for $ReleaseName"
140161

141162
$prParams = @{
142163
Organization = $TargetFork
143164
Repository = $Repository
144165
Branch = $branchName
145166
Title = "Update CHANGELOG for $ReleaseName"
146167
GitHubToken = $GitHubToken
147-
FromOrg = 'rjmholt'
168+
FromOrg = $FromFork
148169
}
149170
New-GitHubPR @prParams

0 commit comments

Comments
 (0)