Skip to content

Commit 7553a17

Browse files
Copilotweinong
andcommitted
fix: exclude release PRs from changelog entries
Release PRs (e.g. "v0.2.14 release") are tagged as the release commit and must not appear in the next version's changelog. Add isReleasePR() using a regexp that matches titles starting with a semver version number (v0.x.y or 0.x.y). Apply the filter inside getMergedPRsSince so these PRs are silently dropped before categorization. Add TestIsReleasePR to verify the pattern matches release titles while leaving normal PRs untouched. Co-authored-by: weinong <4204090+weinong@users.noreply.github.com>
1 parent 941db72 commit 7553a17

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

hack/changelog-generator/main.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"log"
88
"os"
99
"os/exec"
10+
"regexp"
1011
"sort"
1112
"strings"
1213
"time"
@@ -152,6 +153,16 @@ func decodePRStream(data []byte) ([]GitHubPR, error) {
152153
return prs, nil
153154
}
154155

156+
// releasePRTitle matches PR titles that represent a version release
157+
// (e.g. "v0.2.14 release") so they can be excluded from the changelog.
158+
var releasePRTitle = regexp.MustCompile(`(?i)^v?\d+\.\d+\.\d+`)
159+
160+
// isReleasePR returns true when the PR title looks like a release commit
161+
// (e.g. "v0.2.14 release", "0.2.14 release").
162+
func isReleasePR(title string) bool {
163+
return releasePRTitle.MatchString(strings.TrimSpace(title))
164+
}
165+
155166
// getMergedPRsSince returns all merged PRs after the given time.
156167
func getMergedPRsSince(repo string, since time.Time) ([]GitHubPR, error) {
157168
out, err := ghAPI(
@@ -168,7 +179,7 @@ func getMergedPRsSince(repo string, since time.Time) ([]GitHubPR, error) {
168179
}
169180
var prs []GitHubPR
170181
for _, pr := range all {
171-
if !pr.MergedAt.IsZero() && pr.MergedAt.After(since) {
182+
if !pr.MergedAt.IsZero() && pr.MergedAt.After(since) && !isReleasePR(pr.Title) {
172183
prs = append(prs, pr)
173184
}
174185
}

hack/changelog-generator/main_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,27 @@ func TestGenerateChangelogEntry(t *testing.T) {
135135
}
136136
}
137137
}
138+
139+
func TestIsReleasePR(t *testing.T) {
140+
cases := []struct {
141+
title string
142+
expected bool
143+
}{
144+
{"v0.2.14 release", true},
145+
{"0.2.14 release", true},
146+
{"v1.0.0", true},
147+
{"v0.2.14", true},
148+
// Regular PRs — must NOT be filtered
149+
{"fix: nil pointer", false},
150+
{"feat: add new login flow", false},
151+
{"Bump Go to 1.24.11", false},
152+
{"docs: update readme", false},
153+
{"[Bug Fix] - PoP token crash", false},
154+
}
155+
for _, tc := range cases {
156+
got := isReleasePR(tc.title)
157+
if got != tc.expected {
158+
t.Errorf("isReleasePR(%q) = %v; want %v", tc.title, got, tc.expected)
159+
}
160+
}
161+
}

0 commit comments

Comments
 (0)