Skip to content

Commit 1bc6f67

Browse files
joestringeraanm
authored andcommitted
changelog: Add --exclude-labels flag
This will be useful to exclude certain PRs from changelogs when they are unrelated to the target release. Signed-off-by: Joe Stringer <[email protected]>
1 parent 64ad4a4 commit 1bc6f67

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

cmd/changelog/changelog.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ type ChangeLogConfig struct {
2323
StateFile string
2424
LabelFilters []string
2525
ReleaseLabels []string
26+
ExcludeLabels []string
2627
ExcludePRReferences bool
2728
SkipHeader bool
2829
}
@@ -69,6 +70,7 @@ func Command(ctx context.Context, logger *log.Logger) *cobra.Command {
6970
cmd.Flags().StringVar(&cfg.RepoName, "repo", "cilium/cilium", "GitHub organization and repository names separated by a slash")
7071
cmd.Flags().StringArrayVar(&cfg.LabelFilters, "label-filter", []string{}, "Filter pull requests by labels.")
7172
cmd.Flags().StringArrayVar(&cfg.ReleaseLabels, "release-labels", []string{}, "Specify release labels to consider when generating the changelog. This also defines the order of the release notes.")
73+
cmd.Flags().StringArrayVar(&cfg.ExcludeLabels, "exclude-labels", []string{}, "Exclude pull requests with the specified labels.")
7274
cmd.Flags().BoolVar(&cfg.ExcludePRReferences, "exclude-pr-references", false, "If true, do not include references to the PR or PR author")
7375
cmd.Flags().BoolVar(&cfg.SkipHeader, "skip-header", false, "If true, do not print 'Summary of Changes' header")
7476

cmd/changelog/generate.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,28 +164,34 @@ func (cl *ChangeLog) PrintReleaseNotesForWriter(w io.Writer) {
164164
prsWithUpstream = make(types.BackportPRs)
165165
)
166166

167-
// Filter the PRs by --label-filter
167+
// Filter the PRs by --label-filter and --exclude-labels
168168
for id, pr := range cl.listOfPrs.DeepCopy() {
169169
if !filterByLabels(pr.Labels, cl.LabelFilters) {
170170
continue
171171
}
172+
if len(cl.ExcludeLabels) > 0 && filterByLabels(pr.Labels, cl.ExcludeLabels) {
173+
continue
174+
}
172175
listOfPRs[id] = pr
173176
}
174177

175-
// Filter the Backport PRs by --label-filter
178+
// Filter the Backport PRs by --label-filter and --exclude-labels
176179
for prNumber, upstreamedPRs := range cl.prsWithUpstream.DeepCopy() {
177180
for upstreamPRNumber, upstreamPR := range upstreamedPRs {
178181
if !filterByLabels(upstreamPR.Labels, cl.LabelFilters) {
179182
continue
180183
}
184+
if len(cl.ExcludeLabels) > 0 && filterByLabels(upstreamPR.Labels, cl.ExcludeLabels) {
185+
continue
186+
}
181187
if prsWithUpstream[prNumber] == nil {
182188
prsWithUpstream[prNumber] = make(types.PullRequests)
183189
}
184190
prsWithUpstream[prNumber][upstreamPRNumber] = upstreamPR
185191
}
186192
}
187193

188-
cl.Logger.Printf("Found %d PRs and %d backport PRs in %s based on --label-filter\n\n", len(listOfPRs), len(prsWithUpstream), cl.StateFile)
194+
cl.Logger.Printf("Found %d PRs and %d backport PRs in %s\n\n", len(listOfPRs), len(prsWithUpstream), cl.StateFile)
189195

190196
if !cl.SkipHeader {
191197
fmt.Fprintln(w, "Summary of Changes")

cmd/release/git.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,11 +244,13 @@ func (pc *PrepareCommit) generateChangeLog(ctx context.Context, ghClient *GHClie
244244
io2.Fprintf(3, os.Stdout, "✍️ Generating CHANGELOG.md from %s to %s\n", previousPatchVersion, commitSha)
245245
io2.Fprintf(4, os.Stdout, "Previous and current version are from different branches, using last stable %q for release notes\n", lastStable)
246246
clCfg := changelog.ChangeLogConfig{
247-
CommonConfig: pc.cfg.CommonConfig,
248-
Base: previousPatchVersion,
249-
Head: commitSha,
250-
StateFile: pc.cfg.StateFile,
251-
LastStable: lastStable,
247+
CommonConfig: pc.cfg.CommonConfig,
248+
Base: previousPatchVersion,
249+
Head: commitSha,
250+
StateFile: pc.cfg.StateFile,
251+
LastStable: lastStable,
252+
LabelFilters: pc.cfg.IncludeLabels,
253+
ExcludeLabels: pc.cfg.ExcludeLabels,
252254
}
253255
err = clCfg.Sanitize()
254256
if err != nil {

cmd/release/start.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ type ReleaseConfig struct {
4141
StateFile string
4242
Steps []string
4343
DefaultBranch string
44+
45+
IncludeLabels []string
46+
ExcludeLabels []string
4447
}
4548

4649
func (cfg *ReleaseConfig) Sanitize() error {
@@ -312,6 +315,8 @@ To start, run
312315
cmd.Flags().StringSliceVar(&cfg.Steps, "steps", []string{"1"},
313316
fmt.Sprintf("Specify which steps should be executed for the release. Steps numbers are also allowed, e.g. '1,2'. Accepted values: %s", strings.Join(allGroupStepsNames, ", ")),
314317
)
318+
cmd.Flags().StringArrayVar(&cfg.IncludeLabels, "include-labels", []string{}, "Include pull requests with these labels in generated changelogs")
319+
cmd.Flags().StringArrayVar(&cfg.ExcludeLabels, "exclude-labels", []string{}, "Exclude pull requests with these labels from generated changelogs")
315320

316321
for _, flag := range []string{"target-version", "template"} {
317322
cobra.MarkFlagRequired(cmd.Flags(), flag)

0 commit comments

Comments
 (0)