From 02b36d0f73afb9cd8a666eaa6eefc0b5d5218e11 Mon Sep 17 00:00:00 2001 From: Marko Gacesa Date: Thu, 26 Oct 2023 07:57:52 +0000 Subject: [PATCH] return want&got for rule violations (#704) --- app/services/protection/rule_branch.go | 5 +++-- types/rule.go | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/app/services/protection/rule_branch.go b/app/services/protection/rule_branch.go index 99e1dd013..3095b03e9 100644 --- a/app/services/protection/rule_branch.go +++ b/app/services/protection/rule_branch.go @@ -101,8 +101,9 @@ func (v *Branch) CanMerge(_ context.Context, in CanMergeInput) (CanMergeOutput, if len(v.PullReq.Merge.StrategiesAllowed) > 0 { // Note: Empty allowed strategies list means all are allowed if !slices.Contains(v.PullReq.Merge.StrategiesAllowed, in.Method) { - violations.Add("pullreq.merge.strategies_allowed", - "The requested merge strategy is not allowed.") + violations.Addf("pullreq.merge.strategies_allowed", + "The requested merge strategy %q is not allowed. Allowed strategies are %v.", + in.Method, v.PullReq.Merge.StrategiesAllowed) } } diff --git a/types/rule.go b/types/rule.go index 5f6099107..45630edc1 100644 --- a/types/rule.go +++ b/types/rule.go @@ -57,6 +57,7 @@ type RuleFilter struct { type Violation struct { Code string `json:"code"` Message string `json:"message"` + Params []any `json:"params"` } // RuleViolations holds several violations of a rule. @@ -69,6 +70,7 @@ func (violations *RuleViolations) Add(code, message string) { violations.Violations = append(violations.Violations, Violation{ Code: code, Message: message, + Params: nil, }) } @@ -76,6 +78,7 @@ func (violations *RuleViolations) Addf(code, format string, params ...any) { violations.Violations = append(violations.Violations, Violation{ Code: code, Message: fmt.Sprintf(format, params...), + Params: params, }) }