This is an automated email from the ASF dual-hosted git repository.
lynwee pushed a commit to branch dev-9
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git
The following commit(s) were added to refs/heads/dev-9 by this push:
new 2ecf9b2a8 feat(framwork): add custom project service
2ecf9b2a8 is described below
commit 2ecf9b2a88133789dbe371c2dd11e0d8492a7167
Author: d4x1 <[email protected]>
AuthorDate: Thu Sep 12 14:54:38 2024 +0800
feat(framwork): add custom project service
---
backend/server/api/api.go | 9 ++-------
backend/server/services/init.go | 10 ++++++----
backend/server/services/project.go | 11 +++++++++++
3 files changed, 19 insertions(+), 11 deletions(-)
diff --git a/backend/server/api/api.go b/backend/server/api/api.go
index 95a485713..69ca8a374 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 894ffa09a..7e794e68a 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 2d70fd4d7..8e9528d38 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{},