diff --git a/backend/server/api/api.go b/backend/server/api/api.go index 95a485713b3..69ca8a37477 100644 --- a/backend/server/api/api.go +++ b/backend/server/api/api.go @@ -59,13 +59,8 @@ func Init() { basicRes = services.GetBasicRes() } -func InjectCustomService(pipelineNotifier services.PipelineNotificationService) errors.Error { - if pipelineNotifier != nil { - if err := services.InjectCustomService(pipelineNotifier); err != nil { - return err - } - } - return nil +func InjectCustomService(pipelineNotifier services.PipelineNotificationService, projectService services.ProjectService) errors.Error { + return services.InjectCustomService(pipelineNotifier, projectService) } // @title DevLake Swagger API diff --git a/backend/server/services/init.go b/backend/server/services/init.go index 894ffa09a86..7e794e68a68 100644 --- a/backend/server/services/init.go +++ b/backend/server/services/init.go @@ -125,11 +125,13 @@ func Init() { registerPluginsMigrationScripts() } -func InjectCustomService(pipelineNotifier PipelineNotificationService) errors.Error { - if pipelineNotifier == nil { - return errors.Default.New("pipeline notifier is nil") +func InjectCustomService(customPipelineNotifier PipelineNotificationService, customProjectService ProjectService) errors.Error { + if customPipelineNotifier != nil { + customPipelineNotificationService = customPipelineNotifier + } + if customProjectService != nil { + projectService = customProjectService } - customPipelineNotificationService = pipelineNotifier return nil } diff --git a/backend/server/services/project.go b/backend/server/services/project.go index 2d70fd4d7bb..8e9528d3832 100644 --- a/backend/server/services/project.go +++ b/backend/server/services/project.go @@ -30,6 +30,12 @@ import ( helper "github.com/apache/incubator-devlake/helpers/pluginhelper/api" ) +type ProjectService interface { + RenameProject(db dal.Transaction, oldProjectName, newProjectName string) errors.Error +} + +var projectService ProjectService + // ProjectQuery used to query projects as the api project input type ProjectQuery struct { Pagination @@ -268,6 +274,11 @@ func PatchProject(name string, body map[string]interface{}) (*models.ApiOutputPr if err != nil { return nil, err } + if projectService != nil { + if err := projectService.RenameProject(tx, name, project.Name); err != nil { + return nil, err + } + } // rename project err = tx.UpdateColumn( &models.Project{},