Skip to content

Commit

Permalink
Create constants
Browse files Browse the repository at this point in the history
  • Loading branch information
willie-yao committed Aug 30, 2023
1 parent dd22bd0 commit caad7a0
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 70 deletions.
42 changes: 42 additions & 0 deletions hack/tools/release/internal/constants.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
Copyright 2021 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

// release is the package for the release notes generator.

Check warning on line 17 in hack/tools/release/internal/constants.go

View workflow job for this annotation

GitHub Actions / lint (hack/tools)

package-comments: package comment should be of the form "Package release ..." (revive)
package release

// Common tags used by PRs
const (
// Features is the tag used for PRs that add new features.
Features = ":sparkles: New Features"

// Bugs is the tag used for PRs that fix bugs.
Bugs = ":bug: Bug Fixes"

// Documentation is the tag used for PRs that update documentation.
Documentation = ":book: Documentation"

// Proposals is the tag used for PRs that add new proposals.
Proposals = ":memo: Proposals"

// Warning is the tag used for PRs that add breaking changes.
Warning = ":warning: Breaking Changes"

// Other is the tag used for PRs that don't fit in any other category.
Other = ":seedling: Others"

// Unknown is the tag used for PRs that need to be sorted by hand.
Unknown = ":question: Sort these by hand"
)
64 changes: 28 additions & 36 deletions hack/tools/release/notes/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ import (
"strings"
"sync"
"time"

release "sigs.k8s.io/cluster-api/hack/tools/release/internal"
)

/*
Expand All @@ -42,25 +44,15 @@ This needs to be run *before* a tag is created.
Use these as the base of your release notes.
*/

const (
features = ":sparkles: New Features"
bugs = ":bug: Bug Fixes"
documentation = ":book: Documentation"
proposals = ":memo: Proposals"
warning = ":warning: Breaking Changes"
other = ":seedling: Others"
unknown = ":question: Sort these by hand"
)

var (
outputOrder = []string{
proposals,
warning,
features,
bugs,
other,
documentation,
unknown,
release.Proposals,
release.Warning,
release.Features,
release.Bugs,
release.Other,
release.Documentation,
release.Unknown,
}

repo = flag.String("repository", "kubernetes-sigs/cluster-api", "The repo to run the tool from.")
Expand Down Expand Up @@ -231,12 +223,12 @@ func run() int {
}

merges := map[string][]string{
features: {},
bugs: {},
documentation: {},
warning: {},
other: {},
unknown: {},
release.Features: {},
release.Bugs: {},
release.Documentation: {},
release.Warning: {},
release.Other: {},
release.Unknown: {},
}
out, err := cmd.CombinedOutput()
if err != nil {
Expand Down Expand Up @@ -300,7 +292,7 @@ func run() int {
continue
}

if result.prEntry.section == documentation {
if result.prEntry.section == release.Documentation {
merges[result.prEntry.section] = append(merges[result.prEntry.section], result.prEntry.prNumber)
} else {
merges[result.prEntry.section] = append(merges[result.prEntry.section], result.prEntry.title)
Expand All @@ -327,17 +319,17 @@ func run() int {
} else if count > 1 {
fmt.Printf("- %d new commits merged\n", count)
}
if count := len(merges[warning]); count == 1 {
if count := len(merges[release.Warning]); count == 1 {
fmt.Println("- 1 breaking change :warning:")
} else if count > 1 {
fmt.Printf("- %d breaking changes :warning:\n", count)
}
if count := len(merges[features]); count == 1 {
if count := len(merges[release.Features]); count == 1 {
fmt.Println("- 1 feature addition ✨")
} else if count > 1 {
fmt.Printf("- %d feature additions ✨\n", count)
}
if count := len(merges[bugs]); count == 1 {
if count := len(merges[release.Bugs]); count == 1 {
fmt.Println("- 1 bug fixed 🐛")
} else if count > 1 {
fmt.Printf("- %d bugs fixed 🐛\n", count)
Expand All @@ -351,7 +343,7 @@ func run() int {
}

switch key {
case documentation:
case release.Documentation:
sort.Strings(mergeslice)
if len(mergeslice) == 1 {
fmt.Printf(
Expand Down Expand Up @@ -480,33 +472,33 @@ func generateReleaseNoteEntry(c *commit) (*releaseNoteEntry, error) {

switch {
case strings.HasPrefix(entry.title, ":sparkles:"), strings.HasPrefix(entry.title, "✨"):
entry.section = features
entry.section = release.Features
entry.title = removePrefixes(entry.title, []string{":sparkles:", "✨"})
case strings.HasPrefix(entry.title, ":bug:"), strings.HasPrefix(entry.title, "🐛"):
entry.section = bugs
entry.section = release.Bugs
entry.title = removePrefixes(entry.title, []string{":bug:", "🐛"})
case strings.HasPrefix(entry.title, ":book:"), strings.HasPrefix(entry.title, "📖"):
entry.section = documentation
entry.section = release.Documentation
entry.title = removePrefixes(entry.title, []string{":book:", "📖"})
if strings.Contains(entry.title, "CAEP") || strings.Contains(entry.title, "proposal") {
entry.section = proposals
entry.section = release.Proposals
}
case strings.HasPrefix(entry.title, ":seedling:"), strings.HasPrefix(entry.title, "🌱"):
entry.section = other
entry.section = release.Other
entry.title = removePrefixes(entry.title, []string{":seedling:", "🌱"})
case strings.HasPrefix(entry.title, ":warning:"), strings.HasPrefix(entry.title, "⚠️"):
entry.section = warning
entry.section = release.Warning
entry.title = removePrefixes(entry.title, []string{":warning:", "⚠️"})
default:
entry.section = unknown
entry.section = release.Unknown
}

// If the area label indicates documentation, use documentation as the section
// no matter what was the emoji used. This takes into account that the area label
// tends to be more accurate than the emoji (data point observed by the release team).
// We handle this after the switch statement to make sure we remove all emoji prefixes.
if area == documentationAreaLabel {
entry.section = documentation
entry.section = release.Documentation
}

entry.title = strings.TrimSpace(entry.title)
Expand Down
60 changes: 26 additions & 34 deletions hack/tools/release/weekly/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ import (
"regexp"
"strings"
"time"

release "sigs.k8s.io/cluster-api/hack/tools/release/internal"
)

/*
Expand All @@ -37,25 +39,15 @@ This needs to be run *before* a tag is created.
Use these as the base of your release notes.
*/

const (
features = "Feature additions :sparkles:"
bugs = "Bug Fixes :bug: "
documentation = "Documentation :book: "
proposals = "Proposals :memo: "
warning = "Breaking Changes :warning: "
other = "Others :seedling: "
unknown = "Sort these by hand :question: "
)

var (
outputOrder = []string{
proposals,
warning,
features,
bugs,
other,
documentation,
unknown,
release.Proposals,
release.Warning,
release.Features,
release.Bugs,
release.Other,
release.Documentation,
release.Unknown,
}

from = flag.String("from", "", "Include commits starting from and including this date. Accepts format: YYYY-MM-DD")
Expand Down Expand Up @@ -101,12 +93,12 @@ func run() int {
cmd = exec.Command("git", "rev-list", "HEAD", "--since=\""+*from+" 00:00:01\"", "--until=\""+lastDay+" 23:59:59\"", "--merges", "--pretty=format:%B") //nolint:gosec

merges := map[string][]string{
features: {},
bugs: {},
documentation: {},
warning: {},
other: {},
unknown: {},
release.Features: {},
release.Bugs: {},
release.Documentation: {},
release.Warning: {},
release.Other: {},
release.Unknown: {},
}
out, err := cmd.CombinedOutput()
if err != nil {
Expand Down Expand Up @@ -138,30 +130,30 @@ func run() int {
var key, prNumber, fork string
switch {
case strings.HasPrefix(body, ":sparkles:"), strings.HasPrefix(body, "✨"):
key = features
key = release.Features
body = strings.TrimPrefix(body, ":sparkles:")
body = strings.TrimPrefix(body, "✨")
case strings.HasPrefix(body, ":bug:"), strings.HasPrefix(body, "🐛"):
key = bugs
key = release.Bugs
body = strings.TrimPrefix(body, ":bug:")
body = strings.TrimPrefix(body, "🐛")
case strings.HasPrefix(body, ":book:"), strings.HasPrefix(body, "📖"):
key = documentation
key = release.Documentation
body = strings.TrimPrefix(body, ":book:")
body = strings.TrimPrefix(body, "📖")
if strings.Contains(body, "CAEP") || strings.Contains(body, "proposal") {
key = proposals
key = release.Proposals
}
case strings.HasPrefix(body, ":seedling:"), strings.HasPrefix(body, "🌱"):
key = other
key = release.Other
body = strings.TrimPrefix(body, ":seedling:")
body = strings.TrimPrefix(body, "🌱")
case strings.HasPrefix(body, ":warning:"), strings.HasPrefix(body, "⚠️"):
key = warning
key = release.Warning
body = strings.TrimPrefix(body, ":warning:")
body = strings.TrimPrefix(body, "⚠️")
default:
key = unknown
key = release.Unknown
}

body = strings.TrimSpace(body)
Expand All @@ -170,7 +162,7 @@ func run() int {
}
body = fmt.Sprintf("\t - %s", body)
_, _ = fmt.Sscanf(c.merge, "Merge pull request %s from %s", &prNumber, &fork)
if key == documentation {
if key == release.Documentation {
merges[key] = append(merges[key], prNumber)
continue
}
Expand All @@ -188,10 +180,10 @@ func run() int {
}

switch key {
case documentation:
case release.Documentation:
fmt.Printf("- %d Documentation and book contributions :book: \n\n", len(mergeslice))
case other:
fmt.Printf("- %d Other changes :seedling:\n\n", len(merges[other]))
case release.Other:
fmt.Printf("- %d Other changes :seedling:\n\n", len(merges[release.Other]))
default:
fmt.Printf("- %d %s\n", len(merges[key]), key)
for _, merge := range mergeslice {
Expand Down

0 comments on commit caad7a0

Please sign in to comment.