From 6ba3e9bd06b4e39b7d2ebe662458514c8ad53d34 Mon Sep 17 00:00:00 2001 From: Hueter Date: Fri, 28 Jun 2024 19:08:19 +0900 Subject: [PATCH 1/2] =?UTF-8?q?Tag=E3=81=AE=E8=A1=A8=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- go.mod | 6 ++++-- go.sum | 8 ++++++++ service/webhook.go | 29 +++++++++++++---------------- 3 files changed, 25 insertions(+), 18 deletions(-) diff --git a/go.mod b/go.mod index 9b44eb4a..640e5cfb 100644 --- a/go.mod +++ b/go.mod @@ -32,15 +32,17 @@ require ( github.com/mattn/go-isatty v0.0.20 // indirect github.com/mitchellh/go-wordwrap v1.0.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect + github.com/samber/lo v1.42.0 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect github.com/valyala/fasttemplate v1.2.2 // indirect github.com/zclconf/go-cty v1.11.0 // indirect go.uber.org/multierr v1.10.0 // indirect golang.org/x/crypto v0.22.0 // indirect - golang.org/x/mod v0.15.0 // indirect + golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 // indirect + golang.org/x/mod v0.17.0 // indirect golang.org/x/net v0.24.0 // indirect golang.org/x/sys v0.19.0 // indirect - golang.org/x/text v0.14.0 // indirect + golang.org/x/text v0.16.0 // indirect golang.org/x/time v0.5.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/go.sum b/go.sum index 87c6233a..a93073bd 100644 --- a/go.sum +++ b/go.sum @@ -61,6 +61,8 @@ github.com/ncw/swift v1.0.53 h1:luHjjTNtekIEvHg5KdAFIBaH7bWfNkefwFnpDffSIks= github.com/ncw/swift v1.0.53/go.mod h1:23YIA4yWVnGwv2dQlN4bB7egfYX6YLn0Yo/S6zZO/ZM= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/samber/lo v1.42.0 h1:cuVp/4oZcTxK0w8vyj/MSEws9yTUjuTgZi7noEXMlZs= +github.com/samber/lo v1.42.0/go.mod h1:w7R6fO7h2lrnx/s0bWcZ55vXJI89p5UPM6+kyDL373E= github.com/sergi/go-diff v1.0.0 h1:Kpca3qRNrduNnOQeazBd0ysaKrUJiIuISHxogkT9RPQ= github.com/sergi/go-diff v1.0.0/go.mod h1:0CfEIISq7TuYL3j771MWULgwwjU+GofnZX9QAmXWZgo= github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= @@ -82,9 +84,13 @@ golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACk golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= +golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17 h1:3MTrJm4PyNL9NBqvYDSj3DHl46qQakyfqfWo4jgfaEM= +golang.org/x/exp v0.0.0-20220303212507-bbda1eaf7a17/go.mod h1:lgLbSvA5ygNOMpwM/9anMpWVlVJ7Z+cHWq/eFuinpGE= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.15.0 h1:SernR4v+D55NyBH2QiEQrlBAnj1ECL6AGrA5+dPaMY8= golang.org/x/mod v0.15.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= +golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= +golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= @@ -106,6 +112,8 @@ golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= +golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= +golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= diff --git a/service/webhook.go b/service/webhook.go index 2cce3d9b..685e06ba 100644 --- a/service/webhook.go +++ b/service/webhook.go @@ -17,6 +17,8 @@ import ( "github.com/google/uuid" "github.com/labstack/echo/v4" + + "github.com/samber/lo" ) type RequestApplication struct { @@ -116,12 +118,12 @@ func WebhookEventHandler(c echo.Context, reqBody, resBody []byte) { message += fmt.Sprintf("- 請求先グループ: %s", resApp.Group.Name) + "\n" } - if resApp.Tags != nil { - message += "- タグ: " - for _, tag := range resApp.Tags { - message += tag.Name + ", " - } - message = message[:len(message)-len(", ")] + if resApp.Tags != nil && len(resApp.Tags) == 0 { + + tags := lo.Map(resApp.Tags, func(tag *Tag, index int) string { + return tag.Name + }) + message += fmt.Sprintf("- タグ: %s", strings.Join(tags, ", ")) } message += "\n" + "\n" message += resApp.Content + "\n" @@ -159,16 +161,11 @@ func WebhookEventHandler(c echo.Context, reqBody, resBody []byte) { if resApp.Group != nil { message += fmt.Sprintf("- 関連するグループ: %s\n", resApp.Group.Name) } - if resApp.Tags != nil { - tags := make([]string, len(resApp.Tags)) - for i, tag := range resApp.Tags { - tags[i] = fmt.Sprintf(`%s`, tag.Name) - } - if len(resApp.Tags) == 0 { - message += fmt.Sprintf("") - } else { - message += fmt.Sprintf("- タグ: %s", strings.Join(tags, " ")) - } + if resApp.Tags != nil && len(resApp.Tags) == 0 { + tags := lo.Map(resApp.Tags, func(tag *Tag, index int) string { + return tag.Name + }) + message += fmt.Sprintf("- タグ: %s", strings.Join(tags, ", ")) } } From 28fe9ee8e104db504fd133eec359028cc5f052b6 Mon Sep 17 00:00:00 2001 From: Hueter Date: Fri, 28 Jun 2024 19:19:52 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=E6=9D=A1=E4=BB=B6=E4=BF=AE=E6=AD=A3?= =?UTF-8?q?=E3=83=BB=E7=A9=BA=E8=A1=8C=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- service/webhook.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/service/webhook.go b/service/webhook.go index 685e06ba..6e0232eb 100644 --- a/service/webhook.go +++ b/service/webhook.go @@ -17,7 +17,6 @@ import ( "github.com/google/uuid" "github.com/labstack/echo/v4" - "github.com/samber/lo" ) @@ -118,7 +117,7 @@ func WebhookEventHandler(c echo.Context, reqBody, resBody []byte) { message += fmt.Sprintf("- 請求先グループ: %s", resApp.Group.Name) + "\n" } - if resApp.Tags != nil && len(resApp.Tags) == 0 { + if resApp.Tags != nil && len(resApp.Tags) != 0 { tags := lo.Map(resApp.Tags, func(tag *Tag, index int) string { return tag.Name @@ -161,7 +160,7 @@ func WebhookEventHandler(c echo.Context, reqBody, resBody []byte) { if resApp.Group != nil { message += fmt.Sprintf("- 関連するグループ: %s\n", resApp.Group.Name) } - if resApp.Tags != nil && len(resApp.Tags) == 0 { + if resApp.Tags != nil && len(resApp.Tags) != 0 { tags := lo.Map(resApp.Tags, func(tag *Tag, index int) string { return tag.Name })