mirror of
https://github.com/c9s/bbgo.git
synced 2024-11-15 03:23:52 +00:00
slacknotifier: optimize object name for comparison summary
This commit is contained in:
parent
230d7e117e
commit
86ac4ee673
|
@ -521,7 +521,7 @@ func diffsToComment(obj any, diffs []dynamic.Diff) (text string) {
|
||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
text += fmt.Sprintf("%T updated\n", obj)
|
text += fmt.Sprintf("_%s_ updated\n", objectName(obj))
|
||||||
|
|
||||||
for _, diff := range diffs {
|
for _, diff := range diffs {
|
||||||
text += fmt.Sprintf("- %s: `%s` transited to `%s`\n", diff.Field, diff.Before, diff.After)
|
text += fmt.Sprintf("- %s: `%s` transited to `%s`\n", diff.Field, diff.Before, diff.After)
|
||||||
|
@ -529,3 +529,19 @@ func diffsToComment(obj any, diffs []dynamic.Diff) (text string) {
|
||||||
|
|
||||||
return text
|
return text
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var typeNamePrefixRE = regexp.MustCompile("^\\*?([a-zA-Z0-9_]+\\.)?")
|
||||||
|
|
||||||
|
func objectName(obj any) string {
|
||||||
|
type labelInf interface {
|
||||||
|
Label() string
|
||||||
|
}
|
||||||
|
|
||||||
|
if ll, ok := obj.(labelInf); ok {
|
||||||
|
return ll.Label()
|
||||||
|
}
|
||||||
|
|
||||||
|
typeName := fmt.Sprintf("%T", obj)
|
||||||
|
typeName = typeNamePrefixRE.ReplaceAllString(typeName, "")
|
||||||
|
return typeName
|
||||||
|
}
|
||||||
|
|
22
pkg/notifier/slacknotifier/slack_test.go
Normal file
22
pkg/notifier/slacknotifier/slack_test.go
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
package slacknotifier
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
|
||||||
|
"github.com/c9s/bbgo/pkg/types"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_objectName(t *testing.T) {
|
||||||
|
t.Run("deposit", func(t *testing.T) {
|
||||||
|
var deposit = &types.Deposit{}
|
||||||
|
assert.Equal(t, "Deposit", objectName(deposit))
|
||||||
|
})
|
||||||
|
|
||||||
|
t.Run("local type", func(t *testing.T) {
|
||||||
|
type A struct{}
|
||||||
|
var obj = &A{}
|
||||||
|
assert.Equal(t, "A", objectName(obj))
|
||||||
|
})
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user