You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@devlake.apache.org by ly...@apache.org on 2024/09/12 07:03:28 UTC

(incubator-devlake) branch release-v1.0 updated: feat(framwork): add custom project service (#8041) (#8042)

This is an automated email from the ASF dual-hosted git repository.

lynwee pushed a commit to branch release-v1.0
in repository https://gitbox.apache.org/repos/asf/incubator-devlake.git


The following commit(s) were added to refs/heads/release-v1.0 by this push:
     new dbb29b34c feat(framwork): add custom project service (#8041) (#8042)
dbb29b34c is described below

commit dbb29b34cee4b380caaac6f778b5f4bb77c90359
Author: github-actions[bot] <41...@users.noreply.github.com>
AuthorDate: Thu Sep 12 15:03:25 2024 +0800

    feat(framwork): add custom project service (#8041) (#8042)
    
    Co-authored-by: Lynwee <15...@qq.com>
---
 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{},