You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@answer.apache.org by li...@apache.org on 2025/04/23 02:42:37 UTC
(answer-plugins) 01/02: feat(reviewer-basic): add post review option selection
This is an automated email from the ASF dual-hosted git repository.
linkinstar pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/answer-plugins.git
commit 8c14d6a1ebb5f1585e16832cab542bccb59fc4ed
Author: LinkinStars <li...@foxmail.com>
AuthorDate: Wed Apr 23 10:42:10 2025 +0800
feat(reviewer-basic): add post review option selection
---
reviewer-basic/basic.go | 58 +++++++++++++++++++++++++++++++++++---
reviewer-basic/i18n/en_US.yaml | 4 ++-
reviewer-basic/i18n/translation.go | 1 +
reviewer-basic/i18n/zh_CN.yaml | 2 ++
reviewer-basic/info.yaml | 2 +-
5 files changed, 61 insertions(+), 6 deletions(-)
diff --git a/reviewer-basic/basic.go b/reviewer-basic/basic.go
index e3f47e9..db37445 100644
--- a/reviewer-basic/basic.go
+++ b/reviewer-basic/basic.go
@@ -38,9 +38,16 @@ type Reviewer struct {
Config *ReviewerConfig
}
+const (
+ OptionNone = "none"
+ OptionAll = "all"
+ OptionFirst = "first"
+)
+
type ReviewerConfig struct {
PostAllNeedReview bool `json:"review_post_all"`
PostNeedReview bool `json:"review_post"`
+ PostReviewOption string `json:"review_post_option"`
PostReviewKeywords string `json:"review_post_keywords"`
PostDisallowedKeywords string `json:"disallowed_keywords"`
}
@@ -73,8 +80,7 @@ func (r *Reviewer) Review(content *plugin.ReviewContent) (result *plugin.ReviewR
return result
}
- // all post need review
- if r.Config.PostAllNeedReview {
+ if r.Config.PostReviewOption == OptionAll || (r.Config.PostReviewOption == "" && r.Config.PostAllNeedReview) {
result = &plugin.ReviewResult{
Approved: false,
ReviewStatus: plugin.ReviewStatusNeedReview,
@@ -83,8 +89,7 @@ func (r *Reviewer) Review(content *plugin.ReviewContent) (result *plugin.ReviewR
return result
}
- // this switch is true and have any other approved post, return directly
- if r.Config.PostNeedReview && content.Author.ApprovedQuestionAmount+content.Author.ApprovedAnswerAmount == 0 {
+ if (r.Config.PostReviewOption == OptionFirst || (r.Config.PostReviewOption == "" && r.Config.PostNeedReview)) && content.Author.ApprovedQuestionAmount+content.Author.ApprovedAnswerAmount == 0 {
result = &plugin.ReviewResult{
Approved: false,
ReviewStatus: plugin.ReviewStatusNeedReview,
@@ -140,7 +145,40 @@ func (r *Reviewer) Review(content *plugin.ReviewContent) (result *plugin.ReviewR
}
func (r *Reviewer) ConfigFields() []plugin.ConfigField {
+ defaultOption := OptionNone
+ if r.Config.PostReviewOption == "" {
+ if r.Config.PostAllNeedReview {
+ defaultOption = OptionAll
+ } else if r.Config.PostNeedReview {
+ defaultOption = OptionFirst
+ }
+ } else {
+ defaultOption = r.Config.PostReviewOption
+ }
+
return []plugin.ConfigField{
+ {
+ Name: "review_post_option",
+ Type: plugin.ConfigTypeSelect,
+ Title: plugin.MakeTranslator(i18n.ConfigReviewPostTitle),
+ Required: false,
+ UIOptions: plugin.ConfigFieldUIOptions{},
+ Value: defaultOption,
+ Options: []plugin.ConfigFieldOption{
+ {
+ Value: OptionNone,
+ Label: plugin.MakeTranslator(i18n.ConfigSelectOption),
+ },
+ {
+ Value: OptionAll,
+ Label: plugin.MakeTranslator(i18n.ConfigReviewPostLabelAll),
+ },
+ {
+ Value: OptionFirst,
+ Label: plugin.MakeTranslator(i18n.ConfigReviewPostLabelFirst),
+ },
+ },
+ },
{
Name: "review_post_all",
Type: plugin.ConfigTypeSwitch,
@@ -180,6 +218,18 @@ func (r *Reviewer) ConfigFields() []plugin.ConfigField {
func (r *Reviewer) ConfigReceiver(config []byte) error {
c := &ReviewerConfig{}
_ = json.Unmarshal(config, c)
+
+ if c.PostReviewOption == OptionAll {
+ c.PostAllNeedReview = true
+ c.PostNeedReview = false
+ } else if c.PostReviewOption == OptionFirst {
+ c.PostAllNeedReview = false
+ c.PostNeedReview = true
+ } else if c.PostReviewOption == OptionNone {
+ c.PostAllNeedReview = false
+ c.PostNeedReview = false
+ }
+
r.Config = c
return nil
}
diff --git a/reviewer-basic/i18n/en_US.yaml b/reviewer-basic/i18n/en_US.yaml
index 2971d62..917a372 100644
--- a/reviewer-basic/i18n/en_US.yaml
+++ b/reviewer-basic/i18n/en_US.yaml
@@ -28,11 +28,13 @@ plugin:
title:
other: Before a post appears
label_all:
- other: Post must be manually approved
+ other: All new posts must be manually approved
label_first:
other: Post author must have a previously approved post
description:
other: Questions or answers will be held in the review queue and will not be visible until they are approved.
+ select_option:
+ other: Select...
review_post_keywords:
title:
other: Review post keywords
diff --git a/reviewer-basic/i18n/translation.go b/reviewer-basic/i18n/translation.go
index 1289fbc..408dcde 100644
--- a/reviewer-basic/i18n/translation.go
+++ b/reviewer-basic/i18n/translation.go
@@ -26,6 +26,7 @@ const (
ConfigReviewPostLabelFirst = "plugin.basic_reviewer.backend.config.review_post.label_first"
ConfigReviewPostTitle = "plugin.basic_reviewer.backend.config.review_post.title"
ConfigReviewPostDescription = "plugin.basic_reviewer.backend.config.review_post.description"
+ ConfigSelectOption = "plugin.basic_reviewer.backend.config.review_post.select_option"
ConfigReviewPostKeywordsTitle = "plugin.basic_reviewer.backend.config.review_post_keywords.title"
ConfigReviewPostKeywordsDescription = "plugin.basic_reviewer.backend.config.review_post_keywords.description"
ConfigDisallowedKeywordsTitle = "plugin.basic_reviewer.backend.config.disallowed_post_keywords.title"
diff --git a/reviewer-basic/i18n/zh_CN.yaml b/reviewer-basic/i18n/zh_CN.yaml
index 4d047a7..048e603 100644
--- a/reviewer-basic/i18n/zh_CN.yaml
+++ b/reviewer-basic/i18n/zh_CN.yaml
@@ -33,6 +33,8 @@ plugin:
other: 内容发布者必须要有通过审核的帖子
description:
other: 问题或答案将保存在审查队列中,在获得批准之前不可见。
+ select_option:
+ other: 请选择...
review_post_keywords:
title:
other: 审核帖子关键词
diff --git a/reviewer-basic/info.yaml b/reviewer-basic/info.yaml
index da9f3e4..dbc8903 100644
--- a/reviewer-basic/info.yaml
+++ b/reviewer-basic/info.yaml
@@ -17,6 +17,6 @@
slug_name: basic_reviewer
type: reviewer
-version: 1.0.6
+version: 1.0.7
author: answerdev
link: https://github.com/apache/answer-plugins/tree/main/reviewer-basic