Skip to content

Commit 30d814a

Browse files
committed
feat: add includeLabels option to release-notes
1 parent b08b08d commit 30d814a

File tree

6 files changed

+54
-13
lines changed

6 files changed

+54
-13
lines changed

cmd/krel/cmd/release_notes.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ type releaseNotesOptions struct {
138138
githubOrg string
139139
draftRepo string
140140
mapProviders []string
141+
includeLabels []string
141142
}
142143

143144
type releaseNotesResult struct {
@@ -241,6 +242,14 @@ func init() {
241242
"update the cloned repository to fetch any upstream change (default: true)",
242243
)
243244

245+
releaseNotesCmd.PersistentFlags().StringSliceVarP(
246+
&releaseNotesOpts.includeLabels,
247+
"include-labels",
248+
"l",
249+
[]string{},
250+
"specify one or more PR labels to include in release notes",
251+
)
252+
244253
rootCmd.AddCommand(releaseNotesCmd)
245254
}
246255

@@ -909,6 +918,7 @@ func releaseNotesJSON(repoPath, tag string) (jsonString string, err error) {
909918
notesOptions.Debug = logrus.StandardLogger().Level >= logrus.DebugLevel
910919
notesOptions.MapProviderStrings = releaseNotesOpts.mapProviders
911920
notesOptions.AddMarkdownLinks = true
921+
notesOptions.IncludeLabels = releaseNotesOpts.includeLabels
912922

913923
// If the release for the tag we are using has a mapping directory,
914924
// add it to the mapProviders array to read the edits from the release team:
@@ -964,6 +974,7 @@ func gatherNotesFrom(repoPath, startTag string) (*notes.ReleaseNotes, error) {
964974
notesOptions.MapProviderStrings = releaseNotesOpts.mapProviders
965975
notesOptions.ListReleaseNotesV2 = releaseNotesOpts.listReleaseNotesV2
966976
notesOptions.AddMarkdownLinks = true
977+
notesOptions.IncludeLabels = releaseNotesOpts.includeLabels
967978

968979
if err := notesOptions.ValidateAndFinish(); err != nil {
969980
return nil, err

cmd/release-notes/generate.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -249,6 +249,14 @@ func addGenerateFlags(subcommand *cobra.Command) {
249249
false,
250250
"enable experimental implementation to list commits (ListReleaseNotesV2)",
251251
)
252+
253+
subcommand.PersistentFlags().StringSliceVarP(
254+
&opts.IncludeLabels,
255+
"include-labels",
256+
"l",
257+
[]string{},
258+
"specify one or more PR labels to include in release notes",
259+
)
252260
}
253261

254262
// addGenerate adds the generate subcomand to the main release notes cobra cmd.

pkg/changelog/changelog.go

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,19 +37,20 @@ import (
3737

3838
// Options are the main settings for generating the changelog.
3939
type Options struct {
40-
RepoPath string
41-
Tag string
42-
Branch string
43-
Bucket string
44-
Tars string
45-
Images string
46-
HTMLFile string
47-
JSONFile string
48-
RecordDir string
49-
ReplayDir string
50-
CVEDataDir string
51-
CloneCVEMaps bool
52-
Dependencies bool
40+
RepoPath string
41+
Tag string
42+
Branch string
43+
Bucket string
44+
Tars string
45+
Images string
46+
HTMLFile string
47+
JSONFile string
48+
RecordDir string
49+
ReplayDir string
50+
CVEDataDir string
51+
CloneCVEMaps bool
52+
Dependencies bool
53+
IncludeLabels []string
5354
}
5455

5556
// Changelog can be used to generate the changelog for a release.
@@ -278,6 +279,7 @@ func (c *Changelog) generateReleaseNotes(
278279
notesOptions.ReplayDir = c.options.ReplayDir
279280
notesOptions.Pull = false
280281
notesOptions.AddMarkdownLinks = true
282+
notesOptions.IncludeLabels = c.options.IncludeLabels
281283

282284
if c.options.CVEDataDir != "" {
283285
notesOptions.MapProviderStrings = append(

pkg/notes/notes.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -681,6 +681,18 @@ func MatchesExcludeFilter(msg string) bool {
681681
return matchesFilter(msg, noteExclusionFilters)
682682
}
683683

684+
// matchesLabelFilter returns true if any of PR labels match the includeLabels
685+
func matchesLabelFilter(prLabels []*gogithub.Label, includeLabels []string) bool {
686+
for _, include := range includeLabels {
687+
for _, label := range prLabels {
688+
if label.GetName() == include {
689+
return true
690+
}
691+
}
692+
}
693+
return false
694+
}
695+
684696
func matchesFilter(msg string, filters []*regexp.Regexp) bool {
685697
for _, filter := range filters {
686698
if filter.MatchString(msg) {

pkg/notes/notes_v2.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,10 @@ func (g *Gatherer) buildReleaseNote(pair *commitPrPair) (*ReleaseNote, error) {
157157
return nil, nil
158158
}
159159

160+
if len(g.options.IncludeLabels) > 0 && !matchesLabelFilter(pr.Labels, g.options.IncludeLabels) {
161+
return nil, nil
162+
}
163+
160164
text, err := noteTextFromString(prBody)
161165
if err != nil {
162166
logrus.WithFields(logrus.Fields{

pkg/notes/options/options.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ type Options struct {
133133
// This is useful when the release notes are outputted to a file. When using the GitHub release page to publish release notes,
134134
// this option should be set to false to take advantage of Github's autolinked references.
135135
AddMarkdownLinks bool
136+
137+
// IncludeLabels enables including only PRs that have one or more specific labels.
138+
IncludeLabels []string
136139
}
137140

138141
type RevisionDiscoveryMode string
@@ -167,6 +170,7 @@ func New() *Options {
167170
gitCloneFn: git.CloneOrOpenGitHubRepo,
168171
MapProviderStrings: []string{},
169172
AddMarkdownLinks: false,
173+
IncludeLabels: []string{},
170174
}
171175
}
172176

0 commit comments

Comments
 (0)