@@ -38,9 +38,16 @@ type Reviewer struct {
3838 Config * ReviewerConfig
3939}
4040
41+ const (
42+ OptionNone = "none"
43+ OptionAll = "all"
44+ OptionFirst = "first"
45+ )
46+
4147type ReviewerConfig struct {
4248 PostAllNeedReview bool `json:"review_post_all"`
4349 PostNeedReview bool `json:"review_post"`
50+ PostReviewOption string `json:"review_post_option"`
4451 PostReviewKeywords string `json:"review_post_keywords"`
4552 PostDisallowedKeywords string `json:"disallowed_keywords"`
4653}
@@ -73,8 +80,7 @@ func (r *Reviewer) Review(content *plugin.ReviewContent) (result *plugin.ReviewR
7380 return result
7481 }
7582
76- // all post need review
77- if r .Config .PostAllNeedReview {
83+ if r .Config .PostReviewOption == OptionAll || (r .Config .PostReviewOption == "" && r .Config .PostAllNeedReview ) {
7884 result = & plugin.ReviewResult {
7985 Approved : false ,
8086 ReviewStatus : plugin .ReviewStatusNeedReview ,
@@ -83,8 +89,7 @@ func (r *Reviewer) Review(content *plugin.ReviewContent) (result *plugin.ReviewR
8389 return result
8490 }
8591
86- // this switch is true and have any other approved post, return directly
87- if r .Config .PostNeedReview && content .Author .ApprovedQuestionAmount + content .Author .ApprovedAnswerAmount == 0 {
92+ if (r .Config .PostReviewOption == OptionFirst || (r .Config .PostReviewOption == "" && r .Config .PostNeedReview )) && content .Author .ApprovedQuestionAmount + content .Author .ApprovedAnswerAmount == 0 {
8893 result = & plugin.ReviewResult {
8994 Approved : false ,
9095 ReviewStatus : plugin .ReviewStatusNeedReview ,
@@ -140,7 +145,40 @@ func (r *Reviewer) Review(content *plugin.ReviewContent) (result *plugin.ReviewR
140145}
141146
142147func (r * Reviewer ) ConfigFields () []plugin.ConfigField {
148+ defaultOption := OptionNone
149+ if r .Config .PostReviewOption == "" {
150+ if r .Config .PostAllNeedReview {
151+ defaultOption = OptionAll
152+ } else if r .Config .PostNeedReview {
153+ defaultOption = OptionFirst
154+ }
155+ } else {
156+ defaultOption = r .Config .PostReviewOption
157+ }
158+
143159 return []plugin.ConfigField {
160+ {
161+ Name : "review_post_option" ,
162+ Type : plugin .ConfigTypeSelect ,
163+ Title : plugin .MakeTranslator (i18n .ConfigReviewPostTitle ),
164+ Required : false ,
165+ UIOptions : plugin.ConfigFieldUIOptions {},
166+ Value : defaultOption ,
167+ Options : []plugin.ConfigFieldOption {
168+ {
169+ Value : OptionNone ,
170+ Label : plugin .MakeTranslator (i18n .ConfigSelectOption ),
171+ },
172+ {
173+ Value : OptionAll ,
174+ Label : plugin .MakeTranslator (i18n .ConfigReviewPostLabelAll ),
175+ },
176+ {
177+ Value : OptionFirst ,
178+ Label : plugin .MakeTranslator (i18n .ConfigReviewPostLabelFirst ),
179+ },
180+ },
181+ },
144182 {
145183 Name : "review_post_all" ,
146184 Type : plugin .ConfigTypeSwitch ,
@@ -180,6 +218,18 @@ func (r *Reviewer) ConfigFields() []plugin.ConfigField {
180218func (r * Reviewer ) ConfigReceiver (config []byte ) error {
181219 c := & ReviewerConfig {}
182220 _ = json .Unmarshal (config , c )
221+
222+ if c .PostReviewOption == OptionAll {
223+ c .PostAllNeedReview = true
224+ c .PostNeedReview = false
225+ } else if c .PostReviewOption == OptionFirst {
226+ c .PostAllNeedReview = false
227+ c .PostNeedReview = true
228+ } else if c .PostReviewOption == OptionNone {
229+ c .PostAllNeedReview = false
230+ c .PostNeedReview = false
231+ }
232+
183233 r .Config = c
184234 return nil
185235}
0 commit comments