Skip to content

Commit 4f2566d

Browse files
authored
Merge pull request #14 from mercari/status-check-description-prefix-2
Separate prefix for each state
2 parents 1b2b28b + 989eb3f commit 4f2566d

File tree

2 files changed

+28
-3
lines changed

2 files changed

+28
-3
lines changed

server/handler/eval_context.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,23 @@ func (ec *EvalContext) PostStatus(ctx context.Context, state, message string) {
190190
context = ec.Options.StatusCheckContext
191191
}
192192

193+
var prefix string
194+
switch state {
195+
case "success":
196+
prefix = ec.Options.StatusCheckDescriptionPrefix.Success
197+
case "pending":
198+
prefix = ec.Options.StatusCheckDescriptionPrefix.Pending
199+
case "failure":
200+
prefix = ec.Options.StatusCheckDescriptionPrefix.Failure
201+
case "error":
202+
prefix = ec.Options.StatusCheckDescriptionPrefix.Error
203+
default:
204+
logger.Warn().Ctx(ctx).Msgf("Unknown status state: %s, using empty prefix", state)
205+
}
206+
193207
var description string
194-
if ec.Options.StatusCheckDescriptionPrefix != "" {
195-
description = fmt.Sprintf("%s %s", ec.Options.StatusCheckDescriptionPrefix, message)
208+
if prefix != "" {
209+
description = fmt.Sprintf("%s %s", prefix, message)
196210
} else {
197211
description = message
198212
}

server/handler/eval_options.go

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ const (
2626
DefaultStatusCheckContext = "policy-bot"
2727
)
2828

29+
type DescriptionPrefix struct {
30+
// Approved
31+
Success string `yaml:"success"`
32+
// Pending
33+
Pending string `yaml:"pending"`
34+
// Disapproved
35+
Failure string `yaml:"failure"`
36+
// Skipped / Error
37+
Error string `yaml:"error"`
38+
}
39+
2940
type PullEvaluationOptions struct {
3041
PolicyPath string `yaml:"policy_path"`
3142

@@ -44,7 +55,7 @@ type PullEvaluationOptions struct {
4455
StatusCheckContextIgnoreBase bool `yaml:"status_check_context_ignore_base"`
4556

4657
// StatusCheckDescriptionPrefix will be used to prefix the status check description, with a space inserted.
47-
StatusCheckDescriptionPrefix string `yaml:"status_check_description_prefix"`
58+
StatusCheckDescriptionPrefix DescriptionPrefix `yaml:"status_check_description_prefix"`
4859

4960
// ExpandRequiredReviewers enables a UI feature where the details page
5061
// shows a list of the users who can approve each rule. Enabling this

0 commit comments

Comments
 (0)