From 708922eaff66b8fe4298881fc5aade5be59ac356 Mon Sep 17 00:00:00 2001 From: xwzQmxx <1499273991@qq.com> Date: Sat, 20 Feb 2021 16:05:12 +0800 Subject: [PATCH] fix cant add label --- go.mod | 2 +- go.sum | 10 ++-------- pkg/cibot/label.go | 13 +++++++------ pkg/cibot/utils.go | 12 ++++++++++++ 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/go.mod b/go.mod index d610ceb..6a13597 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module gitee.com/openeuler/ci-bot go 1.13 require ( - gitee.com/openeuler/go-gitee v0.0.0-20201111035308-c4384bf8d333 + gitee.com/openeuler/go-gitee v0.0.0-20210201095646-fd9179920723 github.com/antihax/optional v1.0.0 github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b github.com/golang/protobuf v1.3.2 // indirect diff --git a/go.sum b/go.sum index dd5af71..b395e78 100644 --- a/go.sum +++ b/go.sum @@ -2,14 +2,8 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMT cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.37.4 h1:glPeL3BQJsbF6aIIYfZizMwc5LTYz250bDMjttbBGAU= cloud.google.com/go v0.37.4/go.mod h1:NHPJ89PdicEuT9hdPXMROBD91xc5uRDxsMtSB16k7hw= -gitee.com/openeuler/go-gitee v0.0.0-20200424023021-ced5a4d67179 h1:7bHzennVUJlv27Gljny95CyXknEBrfmHL6KdHCuHumM= -gitee.com/openeuler/go-gitee v0.0.0-20200424023021-ced5a4d67179/go.mod h1:TQrS/LP/DFXLqM+lVrZd4nL2pbTrqiXABGT9PJepVTA= -gitee.com/openeuler/go-gitee v0.0.0-20201109090511-81a247e275be h1:eh0eMiF5PNuD196nW8DcVNsGNchbeyKk+nlVgKtnBzg= -gitee.com/openeuler/go-gitee v0.0.0-20201109090511-81a247e275be/go.mod h1:TQrS/LP/DFXLqM+lVrZd4nL2pbTrqiXABGT9PJepVTA= -gitee.com/openeuler/go-gitee v0.0.0-20201110031012-c7f697cc7b12 h1:rgQdF72XcPKOVyM3nmf0Lyp7Mh3mDqxD/uMvY7sixOE= -gitee.com/openeuler/go-gitee v0.0.0-20201110031012-c7f697cc7b12/go.mod h1:TQrS/LP/DFXLqM+lVrZd4nL2pbTrqiXABGT9PJepVTA= -gitee.com/openeuler/go-gitee v0.0.0-20201111035308-c4384bf8d333 h1:Uk05BpyrV24VNVFPd47lEOg0OmUMgnIgd50gnyWqC8s= -gitee.com/openeuler/go-gitee v0.0.0-20201111035308-c4384bf8d333/go.mod h1:TQrS/LP/DFXLqM+lVrZd4nL2pbTrqiXABGT9PJepVTA= +gitee.com/openeuler/go-gitee v0.0.0-20210201095646-fd9179920723 h1:awXn0FlbiQ9Ohj96FrWM1r16tB//D+eTyC2wainPX80= +gitee.com/openeuler/go-gitee v0.0.0-20210201095646-fd9179920723/go.mod h1:TQrS/LP/DFXLqM+lVrZd4nL2pbTrqiXABGT9PJepVTA= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo= github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI= diff --git a/pkg/cibot/label.go b/pkg/cibot/label.go index 2f44030..ddfce27 100644 --- a/pkg/cibot/label.go +++ b/pkg/cibot/label.go @@ -50,27 +50,27 @@ func GetChangeLabels(confDelLabels []string, prLabels []gitee.Label) (delLabels, continue } if cdl == "openeuler-cla" { - if strings.HasPrefix(pl.Name,cdl){ + if strings.HasPrefix(pl.Name, cdl) { delLabels = append(delLabels, pl.Name) isUpdate = false } continue } - if cdl == "sig"{ - if strings.HasPrefix(pl.Name,cdl){ + if cdl == "sig" { + if strings.HasPrefix(pl.Name, cdl) { delLabels = append(delLabels, pl.Name) isUpdate = false } continue } - if cdl == "kind"{ - if strings.HasPrefix(pl.Name,cdl){ + if cdl == "kind" { + if strings.HasPrefix(pl.Name, cdl) { delLabels = append(delLabels, pl.Name) isUpdate = false } continue } - if cdl == pl.Name { + if cdl == pl.Name { delLabels = append(delLabels, pl.Name) isUpdate = false continue @@ -587,6 +587,7 @@ func (s *Server) patchRepoLabels(labels []string, owner, repo string, createNew // AddSpecifyLabelInPulRequest adds specify labels in pull request func (s *Server) AddSpecifyLabelsInPulRequest(event *gitee.NoteEvent, newLabels []string, createNew bool) error { + newLabels = truncateLabel(newLabels) // get basic information comment := event.Comment.Body owner := event.Repository.Namespace diff --git a/pkg/cibot/utils.go b/pkg/cibot/utils.go index 6436957..0a99e3f 100644 --- a/pkg/cibot/utils.go +++ b/pkg/cibot/utils.go @@ -133,3 +133,15 @@ func canCommentPrIncludingSigDirectory(server *Server, owner string, repo string } return 1, nil } + +//truncateLabel on gitee the length of the label cannot exceed 20 characters. +//If it exceeds, the label will be truncated and replaced. +func truncateLabel(labels []string) []string { + for i := range labels { + rs := []rune(labels[i]) + if len(rs) > 20 { + labels[i] = string(rs[:20]) + } + } + return labels +} -- Gitee