likyh commented on code in PR #3838: URL: https://github.com/apache/incubator-devlake/pull/3838#discussion_r1037097527
########## plugins/jenkins/models/migrationscripts/20221131_add_fullName_for_builds.go: ########## @@ -0,0 +1,117 @@ +/* +Licensed to the Apache Software Foundation (ASF) under one or more +contributor license agreements. See the NOTICE file distributed with +this work for additional information regarding copyright ownership. +The ASF licenses this file to You under the Apache License, Version 2.0 +(the "License"); you may not use this file except in compliance with +the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package migrationscripts + +import ( + "fmt" + "github.com/apache/incubator-devlake/errors" + "github.com/apache/incubator-devlake/helpers/migrationhelper" + "github.com/apache/incubator-devlake/models/migrationscripts/archived" + "github.com/apache/incubator-devlake/plugins/core" + "time" +) + +type addFullNameForBuilds struct{} + +type jenkinsBuild20221131 struct { + FullName string `gorm:"primaryKey;type:varchar(255)"` // "path/job name#7" PREPARE TO ADD THIS +} + +func (jenkinsBuild20221131) TableName() string { + return "_tool_jenkins_builds" +} + +type jenkinsBuild20221131Before struct { + archived.NoPKModel + // collected fields + ConnectionId uint64 `gorm:"primaryKey"` + JobName string `gorm:"index;type:varchar(255)"` + JobPath string `gorm:"index;type:varchar(255)"` + Duration float64 // build time + FullName string `gorm:"primaryKey;type:varchar(255)"` // "path/job name#7" PREPARE TO ADD THIS + FullDisplayName string `gorm:"primaryKey;type:varchar(255)"` // "path » job name #7" + EstimatedDuration float64 // EstimatedDuration + Number int64 `gorm:"index"` + Result string // Result + Timestamp int64 // start time + StartTime time.Time // convered by timestamp + Type string `gorm:"index;type:varchar(255)"` + Class string `gorm:"index;type:varchar(255)" ` + TriggeredBy string `gorm:"type:varchar(255)"` + Building bool + HasStages bool +} + +func (jenkinsBuild20221131Before) TableName() string { + return "_tool_jenkins_builds" +} + +type jenkinsBuild20221131After struct { + archived.NoPKModel + // collected fields + ConnectionId uint64 `gorm:"primaryKey"` + JobName string `gorm:"index;type:varchar(255)"` + JobPath string `gorm:"index;type:varchar(255)"` + Duration float64 // build time + FullName string `gorm:"primaryKey;type:varchar(255)"` // "path/job name#7" ADD THIS + FullDisplayName string `gorm:"type:varchar(255)"` // "path » job name #7" + EstimatedDuration float64 // EstimatedDuration + Number int64 `gorm:"index"` + Result string // Result + Timestamp int64 // start time + StartTime time.Time // convered by timestamp + Type string `gorm:"index;type:varchar(255)"` + Class string `gorm:"index;type:varchar(255)" ` + TriggeredBy string `gorm:"type:varchar(255)"` + Building bool + HasStages bool +} + +func (jenkinsBuild20221131After) TableName() string { + return "_tool_jenkins_builds" +} + +func (script *addFullNameForBuilds) Up(basicRes core.BasicRes) errors.Error { + err := migrationhelper.AutoMigrateTables(basicRes, &jenkinsBuild20221131{}) + if err != nil { + return err + } + return migrationhelper.TransformTable( + basicRes, + script, + "_tool_jenkins_builds", + func(s *jenkinsBuild20221131Before) (*jenkinsBuild20221131After, errors.Error) { + // copy data + dst := jenkinsBuild20221131After(*s) + if s.JobPath != "" { + dst.FullName = fmt.Sprintf("%s/%s#%d", s.JobPath, s.JobName, s.Number) Review Comment: Actually, it is wrong. But it will be fixed after one sync. JobPath is `job/../job/..` and FullName doesn't needs `job/` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@devlake.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org