summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
Diffstat (limited to 'models')
-rw-r--r--models/issues/comment.go9
-rw-r--r--models/issues/comment_test.go7
2 files changed, 16 insertions, 0 deletions
diff --git a/models/issues/comment.go b/models/issues/comment.go
index 87e6b0a229..91dc128277 100644
--- a/models/issues/comment.go
+++ b/models/issues/comment.go
@@ -175,6 +175,15 @@ func (t CommentType) String() string {
return commentStrings[t]
}
+func AsCommentType(typeName string) CommentType {
+ for index, name := range commentStrings {
+ if typeName == name {
+ return CommentType(index)
+ }
+ }
+ return CommentTypeUnknown
+}
+
// RoleDescriptor defines comment tag type
type RoleDescriptor int
diff --git a/models/issues/comment_test.go b/models/issues/comment_test.go
index 0d0570ae34..f1232729f1 100644
--- a/models/issues/comment_test.go
+++ b/models/issues/comment_test.go
@@ -62,3 +62,10 @@ func TestFetchCodeComments(t *testing.T) {
assert.NoError(t, err)
assert.Len(t, res, 1)
}
+
+func TestAsCommentType(t *testing.T) {
+ assert.Equal(t, issues_model.CommentTypeUnknown, issues_model.AsCommentType(""))
+ assert.Equal(t, issues_model.CommentTypeUnknown, issues_model.AsCommentType("nonsense"))
+ assert.Equal(t, issues_model.CommentTypeComment, issues_model.AsCommentType("comment"))
+ assert.Equal(t, issues_model.CommentTypePRUnScheduledToAutoMerge, issues_model.AsCommentType("pull_cancel_scheduled_merge"))
+}