Skip to content

Commit 1068f37

Browse files
authored
fix: preserve changelog bullet point (#20)
1 parent ee77c80 commit 1068f37

File tree

4 files changed

+21
-15
lines changed

4 files changed

+21
-15
lines changed

scripts/update-changelog.ps1

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ for ($i = 0; $i -lt $lines.Count; $i++)
4949
break
5050
}
5151

52-
# Make sure that there's a the requested section header
52+
# Make sure that there's the requested section header
5353
:outer for ($i = 0; $i -lt $lines.Count; $i++)
5454
{
5555
$line = $lines[$i]
@@ -115,9 +115,9 @@ $PullRequestMD = "[#$($PR | Split-Path -Leaf)]($PR)"
115115
$updated = $false
116116
for ($i = 0; $i -lt $sectionEnd; $i++)
117117
{
118-
if (($lines[$i] -match "^- Bump $Name.*to") -and `
119-
($lines[$i + 1] -match "^ - \[changelog\]\($RepoUrl") -and `
120-
($lines[$i + 2] -match "^ - \[diff\]\($RepoUrl"))
118+
if (($lines[$i] -match "^[-*] Bump $Name.*to") -and `
119+
($lines[$i + 1] -match "^ [-*] \[changelog\]\($RepoUrl") -and `
120+
($lines[$i + 2] -match "^ [-*] \[diff\]\($RepoUrl"))
121121
{
122122
Write-Host "Found an existing changelog entry at $($i):"
123123
Write-Host " ", $lines[$i]
@@ -126,7 +126,7 @@ for ($i = 0; $i -lt $sectionEnd; $i++)
126126

127127
$lines[$i] = $lines[$i] -replace "(Bump $Name.*)to .* \(", "`$1to $newTagNice ("
128128
$lines[$i] = $lines[$i] -replace "\)$", ", $PullRequestMD)"
129-
$lines[$i + 1] = " - [changelog]($RepoUrl/blob/$MainBranch/CHANGELOG.md#$tagAnchor)"
129+
$lines[$i + 1] = $lines[$i + 1] -replace "#.*\)", "#$tagAnchor)"
130130
$lines[$i + 2] = $lines[$i + 2] -replace "\.\.\..*\)$", "...$NewTag)"
131131

132132
Write-Host "Updating the entry to: "
@@ -140,9 +140,13 @@ for ($i = 0; $i -lt $sectionEnd; $i++)
140140

141141
if (!$updated)
142142
{
143-
$entry = @("- Bump $Name from $oldTagNice to $newTagNice ($PullRequestMD)",
144-
" - [changelog]($RepoUrl/blob/$MainBranch/CHANGELOG.md#$tagAnchor)",
145-
" - [diff]($RepoUrl/compare/$OldTag...$NewTag)")
143+
# Find what character is used as a bullet-point separator - look for the first bullet-point object that wasn't created by this script.
144+
$bulletPoint = $lines | Where-Object { ($_ -match "^ *[-*] ") -and -not ($_ -match "(Bump .* to|\[changelog\]|\[diff\])") } | Select-Object -First 1
145+
$bulletPoint = "$bulletPoint-"[0]
146+
147+
$entry = @("$bulletPoint Bump $Name from $oldTagNice to $newTagNice ($PullRequestMD)",
148+
" $bulletPoint [changelog]($RepoUrl/blob/$MainBranch/CHANGELOG.md#$tagAnchor)",
149+
" $bulletPoint [diff]($RepoUrl/compare/$OldTag...$NewTag)")
146150

147151
Write-Host "Adding a changelog entry at line $($sectionEnd):"
148152
foreach ($line in $entry)

tests/testdata/changelog/new-second-section/CHANGELOG.md.expected

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@
1111

1212
- Capture `Debug.LogError()` and `Debug.LogException()` also on background threads ([#673](https://github.com/getsentry/sentry-unity/pull/673))
1313
- Adding override for Sentry CLI URL ([#666](https://github.com/getsentry/sentry-unity/pull/666))
14-
- Bump Dependency from v7.16.0 to v7.17.0 ([#123](https://github.com/getsentry/dependant/pulls/123))
15-
- [changelog](https://github.com/getsentry/dependency/blob/main/CHANGELOG.md#7170)
16-
- [diff](https://github.com/getsentry/dependency/compare/7.16.0...7.17.0)
14+
* Bump Dependency from v7.16.0 to v7.17.0 ([#123](https://github.com/getsentry/dependant/pulls/123))
15+
* [changelog](https://github.com/getsentry/dependency/blob/main/CHANGELOG.md#7170)
16+
* [diff](https://github.com/getsentry/dependency/compare/7.16.0...7.17.0)
1717

1818
### Notes
1919

tests/testdata/changelog/update/CHANGELOG.md.expected

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
### Dependencies
66

7-
- Bump Dependency to v7.17.0 ([#100](https://github.com/getsentry/dependant/pulls/100), [#123](https://github.com/getsentry/dependant/pulls/123))
8-
- [changelog](https://github.com/getsentry/dependency/blob/main/CHANGELOG.md#7170)
7+
- Following items preserve their bullet points as-is even through an update
8+
* Bump Dependency to v7.17.0 ([#100](https://github.com/getsentry/dependant/pulls/100), [#123](https://github.com/getsentry/dependant/pulls/123))
9+
* [changelog](https://github.com/getsentry/dependency/blob/main/CHANGELOG.md#7170)
910
- [diff](https://github.com/getsentry/dependency/compare/5.0.0...7.17.0)
1011

1112
## 0.14.0

tests/testdata/changelog/update/CHANGELOG.md.original

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44

55
### Dependencies
66

7-
- Bump Dependency to v6.0.0 ([#100](https://github.com/getsentry/dependant/pulls/100))
8-
- [changelog](https://github.com/getsentry/dependency/blob/main/CHANGELOG.md#600)
7+
- Following items preserve their bullet points as-is even through an update
8+
* Bump Dependency to v6.0.0 ([#100](https://github.com/getsentry/dependant/pulls/100))
9+
* [changelog](https://github.com/getsentry/dependency/blob/main/CHANGELOG.md#600)
910
- [diff](https://github.com/getsentry/dependency/compare/5.0.0...6.0.0)
1011

1112
## 0.14.0

0 commit comments

Comments
 (0)