Skip to content

Commit 13193d2

Browse files
vaindclaude
andauthored
fix: Handle null bullet point detection in update-changelog script (#125)
* fix: Handle null bullet point detection in update-changelog script The script was failing when trying to detect bullet point characters in changelogs that contained no existing bullet points. This occurred because the Where-Object filter returned null, and calling .Trim() on null caused a "You cannot call a method on a null-valued expression" error. Fixed by wrapping the variable in quotes to convert null to empty string before calling .Trim(), which effectively defaults to using "-" as the bullet point character. Added test case for this scenario to prevent regression. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * docs: Add changelog entry for null bullet point fix --------- Co-authored-by: Claude <[email protected]>
1 parent 67d5a87 commit 13193d2

File tree

5 files changed

+42
-1
lines changed

5 files changed

+42
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@
7171

7272
### Fixes
7373

74+
- Updater - Fix null reference error when changelog has no existing bullet points ([#125](https://github.com/getsentry/github-workflows/pull/125))
7475
- Updater - Fix bullet-point resolution when plain text precedes bullet points ([#123](https://github.com/getsentry/github-workflows/pull/123))
7576
- Improve changelog generation for non-tagged commits and edge cases ([#115](https://github.com/getsentry/github-workflows/pull/115))
7677

updater/scripts/update-changelog.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ if (!$updated)
180180
{
181181
# Find what character is used as a bullet-point separator - look for the first bullet-point object that wasn't created by this script.
182182
$bulletPoint = $lines | Where-Object { ($_ -match '^ *[-*] ') -and -not ($_ -match '(Bump .* to|\[changelog\]|\[diff\])') } | Select-Object -First 1
183-
$bulletPoint = "$($bulletPoint.Trim())-"[0]
183+
$bulletPoint = "$("$bulletPoint".Trim())-"[0]
184184
$entry = @("$bulletPoint Bump $Name from $oldTagNice to $newTagNice ($PullRequestMD)",
185185
" $bulletPoint [changelog]($RepoUrl/blob/$MainBranch/CHANGELOG.md#$tagAnchor)",
186186
" $bulletPoint [diff]($RepoUrl/compare/$OldTag...$NewTag)")
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Changelog
2+
3+
## Unreleased
4+
5+
### Dependencies
6+
7+
- Bump Dependency from v7.16.0 to v7.17.0 ([#123](https://github.com/getsentry/dependant/pulls/123))
8+
- [changelog](https://github.com/getsentry/dependency/blob/main/CHANGELOG.md#7170)
9+
- [diff](https://github.com/getsentry/dependency/compare/7.16.0...7.17.0)
10+
11+
## 0.14.0
12+
13+
### Dependencies
14+
15+
This section contains only plain text with no bullet points.
16+
The update-changelog script should handle this case gracefully.
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Changelog
2+
3+
## 0.14.0
4+
5+
### Dependencies
6+
7+
This section contains only plain text with no bullet points.
8+
The update-changelog script should handle this case gracefully.

updater/tests/update-changelog.Tests.ps1

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,20 @@ Describe 'update-changelog' {
3232
# verify the full output matches expected
3333
Get-Content "$testCasePath/CHANGELOG.md" | Should -Be (Get-Content "$testCasePath/CHANGELOG.md.expected")
3434
}
35+
36+
It 'should handle changelogs with no bullet points by defaulting to dash' {
37+
$testCasePath = "$PSScriptRoot/testdata/changelog/no-bullet-points"
38+
Copy-Item "$testCasePath/CHANGELOG.md.original" "$testCasePath/CHANGELOG.md"
39+
40+
pwsh -WorkingDirectory $testCasePath -File "$PSScriptRoot/../scripts/update-changelog.ps1" `
41+
-Name 'Dependency' `
42+
-PR 'https://github.com/getsentry/dependant/pulls/123' `
43+
-RepoUrl 'https://github.com/getsentry/dependency' `
44+
-MainBranch 'main' `
45+
-OldTag '7.16.0' `
46+
-NewTag '7.17.0' `
47+
-Section 'Dependencies'
48+
49+
Get-Content "$testCasePath/CHANGELOG.md" | Should -Be (Get-Content "$testCasePath/CHANGELOG.md.expected")
50+
}
3551
}

0 commit comments

Comments
 (0)