From 16d1dd599df4afff799495f6759232678b863ead Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Thu, 12 Nov 2020 14:45:26 -0500 Subject: [PATCH] handle WIP prefixes in enhancement titles fixes #513 Signed-off-by: Doug Hellmann --- tools/enhancements/title.go | 12 ++++++++---- tools/enhancements/title_test.go | 20 ++++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/tools/enhancements/title.go b/tools/enhancements/title.go index a529fd6382..f64b21b448 100644 --- a/tools/enhancements/title.go +++ b/tools/enhancements/title.go @@ -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 } diff --git a/tools/enhancements/title_test.go b/tools/enhancements/title_test.go index 3316665756..2c00629048 100644 --- a/tools/enhancements/title_test.go +++ b/tools/enhancements/title_test.go @@ -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)