Skip to content

Commit

Permalink
feat(framwork): add custom project service (#8041) (#8042)
Browse files Browse the repository at this point in the history
Co-authored-by: Lynwee <[email protected]>
  • Loading branch information
github-actions[bot] and d4x1 authored Sep 12, 2024
1 parent 8e9b6fc commit dbb29b3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
9 changes: 2 additions & 7 deletions backend/server/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 6 additions & 4 deletions backend/server/services/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
11 changes: 11 additions & 0 deletions backend/server/services/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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{},
Expand Down

0 comments on commit dbb29b3

Please sign in to comment.