From ee3a5c225d05d9e66b7ed48fa6164311d3b2a681 Mon Sep 17 00:00:00 2001 From: Adrian Orive Date: Tue, 2 Feb 2021 15:01:32 +0100 Subject: [PATCH 1/2] Measure descriptiveness by characters (80) instead of lines (2) Signed-off-by: Adrian Orive --- verify/descriptiveness.go | 13 ++----------- verify/main.go | 2 +- 2 files changed, 3 insertions(+), 12 deletions(-) diff --git a/verify/descriptiveness.go b/verify/descriptiveness.go index 6e13900..bf20ffd 100644 --- a/verify/descriptiveness.go +++ b/verify/descriptiveness.go @@ -17,8 +17,6 @@ limitations under the License. package main import ( - "strings" - "github.com/google/go-github/v32/github" "sigs.k8s.io/kubebuilder-release-tools/verify/pkg/action" @@ -36,16 +34,9 @@ Someone reading the PR description without clicking any issue links should be ab } // checkPRDescriptiveness -func checkPRDescriptiveness(requiredLines int) action.ValidateFunc { +func checkPRDescriptiveness(requiredCharacters int) action.ValidateFunc { return func(pr *github.PullRequest) (string, string, error) { - lineCnt := 0 - for _, line := range strings.Split(pr.GetBody(), "\n") { - if strings.TrimSpace(line) == "" { - continue - } - lineCnt++ - } - if lineCnt < requiredLines { + if len(pr.GetBody()) < requiredCharacters { return "", "", &prDescriptivenessError{} } return "Your PR looks descriptive enough!", "", nil diff --git a/verify/main.go b/verify/main.go index 7bf283d..3f5f2e2 100644 --- a/verify/main.go +++ b/verify/main.go @@ -35,7 +35,7 @@ func main() { action.NewPlugin( "PR Desc", "Basic PR Descriptiveness Check", - checkPRDescriptiveness(2), + checkPRDescriptiveness(80), ), ).Run() } From 3d74348d947cd74a1527712c6b54979282276e5c Mon Sep 17 00:00:00 2001 From: Adrian Orive Date: Tue, 2 Feb 2021 15:02:11 +0100 Subject: [PATCH 2/2] Skip descriptiveness check if the "skip-descriptiveness-check" flag is set. Signed-off-by: Adrian Orive --- verify/descriptiveness.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/verify/descriptiveness.go b/verify/descriptiveness.go index bf20ffd..5c04ce5 100644 --- a/verify/descriptiveness.go +++ b/verify/descriptiveness.go @@ -17,11 +17,15 @@ limitations under the License. package main import ( + "strings" + "github.com/google/go-github/v32/github" "sigs.k8s.io/kubebuilder-release-tools/verify/pkg/action" ) +const skipDescriptivenessCheckLabel = "skip-descriptiveness-check" + type prDescriptivenessError struct{} func (e prDescriptivenessError) Error() string { @@ -36,7 +40,13 @@ Someone reading the PR description without clicking any issue links should be ab // checkPRDescriptiveness func checkPRDescriptiveness(requiredCharacters int) action.ValidateFunc { return func(pr *github.PullRequest) (string, string, error) { - if len(pr.GetBody()) < requiredCharacters { + for _, label := range pr.Labels { + if label.Name != nil && *label.Name == skipDescriptivenessCheckLabel { + return "Skipping descriptiveness check!", "", nil + } + } + + if len(strings.TrimSpace(pr.GetBody())) < requiredCharacters { return "", "", &prDescriptivenessError{} } return "Your PR looks descriptive enough!", "", nil