summaryrefslogtreecommitdiffstats
path: root/modules
diff options
context:
space:
mode:
authorLanre Adelowo <adelowomailbox@gmail.com>2018-08-07 18:15:41 +0100
committerLauris BH <lauris@nix.lv>2018-08-07 20:15:41 +0300
commit0df7cab4fb0c84444ceb4c9b5f28f410a38025f5 (patch)
tree4f5de68f3881caf4646e1a0d187a6ba7b2cebcf7 /modules
parent59b10e66f757441e8c74532f30740bf4a96e9ac1 (diff)
downloadgitea-0df7cab4fb0c84444ceb4c9b5f28f410a38025f5.tar.gz
gitea-0df7cab4fb0c84444ceb4c9b5f28f410a38025f5.zip
prevent empty review comment (#4632)
* prevent empty review comment This would only require a comment for rejection and comment * add tests * add comment
Diffstat (limited to 'modules')
-rw-r--r--modules/auth/repo_form.go8
-rw-r--r--modules/auth/repo_form_test.go41
2 files changed, 49 insertions, 0 deletions
diff --git a/modules/auth/repo_form.go b/modules/auth/repo_form.go
index d205a6fd53..3c7940afce 100644
--- a/modules/auth/repo_form.go
+++ b/modules/auth/repo_form.go
@@ -402,6 +402,14 @@ func (f SubmitReviewForm) ReviewType() models.ReviewType {
}
}
+// HasEmptyContent checks if the content of the review form is empty.
+func (f SubmitReviewForm) HasEmptyContent() bool {
+ reviewType := f.ReviewType()
+
+ return (reviewType == models.ReviewTypeComment || reviewType == models.ReviewTypeReject) &&
+ len(strings.TrimSpace(f.Content)) == 0
+}
+
// __________ .__
// \______ \ ____ | | ____ _____ ______ ____
// | _// __ \| | _/ __ \\__ \ / ___// __ \
diff --git a/modules/auth/repo_form_test.go b/modules/auth/repo_form_test.go
new file mode 100644
index 0000000000..f6223d6c8a
--- /dev/null
+++ b/modules/auth/repo_form_test.go
@@ -0,0 +1,41 @@
+// Copyright 2018 The Gitea Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package auth
+
+import (
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+)
+
+func TestSubmitReviewForm_IsEmpty(t *testing.T) {
+
+ cases := []struct {
+ form SubmitReviewForm
+ expected bool
+ }{
+ // Approved PR with a comment shouldn't count as empty
+ {SubmitReviewForm{Type: "approve", Content: "Awesome"}, false},
+
+ // Approved PR without a comment shouldn't count as empty
+ {SubmitReviewForm{Type: "approve", Content: ""}, false},
+
+ // Rejected PR without a comment should count as empty
+ {SubmitReviewForm{Type: "reject", Content: ""}, true},
+
+ // Rejected PR with a comment shouldn't count as empty
+ {SubmitReviewForm{Type: "reject", Content: "Awesome"}, false},
+
+ // Comment review on a PR with a comment shouldn't count as empty
+ {SubmitReviewForm{Type: "comment", Content: "Awesome"}, false},
+
+ // Comment review on a PR without a comment should count as empty
+ {SubmitReviewForm{Type: "comment", Content: ""}, true},
+ }
+
+ for _, v := range cases {
+ assert.Equal(t, v.expected, v.form.HasEmptyContent())
+ }
+}