Skip to content

Commit

Permalink
handle WIP prefixes in enhancement titles
Browse files Browse the repository at this point in the history
fixes openshift#513

Signed-off-by: Doug Hellmann <[email protected]>
  • Loading branch information
dhellmann committed Nov 12, 2020
1 parent 8016677 commit 16d1dd5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 4 deletions.
12 changes: 8 additions & 4 deletions tools/enhancements/title.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ package enhancements

import "strings"

var (
titlePrefixes = []string{"wip:", "[wip]", "enhancement:"}
)

func CleanTitle(title string) string {
// Sometimes we have a superfluous "enhancement:" prefix in
// the PR title
if strings.HasPrefix(strings.ToLower(title), "enhancement:") {
title = strings.TrimLeft(title[12:], " ")
for _, prefix := range titlePrefixes {
if strings.HasPrefix(strings.ToLower(title), prefix) {
title = strings.TrimLeft(title[len(prefix):], " ")
}
}
return title
}
20 changes: 20 additions & 0 deletions tools/enhancements/title_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,26 @@ func TestCleanTitle(t *testing.T) {
Input: "Enhancement: Remove the prefix",
Expected: "Remove the prefix",
},
{
Scenario: "WIP:",
Input: "WIP: Remove the prefix",
Expected: "Remove the prefix",
},
{
Scenario: "[wip]",
Input: "[WIP] Remove the prefix",
Expected: "Remove the prefix",
},
{
Scenario: "combo",
Input: "[WIP] enhancement: Remove the prefix",
Expected: "Remove the prefix",
},
{
Scenario: "combo-no-whitespace",
Input: "[WIP]enhancement:Remove the prefix",
Expected: "Remove the prefix",
},
} {
t.Run(tc.Scenario, func(t *testing.T) {
actual := CleanTitle(tc.Input)
Expand Down

0 comments on commit 16d1dd5

Please sign in to comment.