Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: gitlab adopts ds_helper #6173

Merged
merged 10 commits into from
Oct 8, 2023
2 changes: 1 addition & 1 deletion backend/core/models/common/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func NewNoPKModel() NoPKModel {
}

type Scope struct {
NoPKModel `json:"-" mapstructure:"-"`
NoPKModel
ConnectionId uint64 `json:"connectionId" gorm:"primaryKey" validate:"required" mapstructure:"connectionId,omitempty"`
ScopeConfigId uint64 `json:"scopeConfigId,omitempty" mapstructure:"scopeConfigId,omitempty"`
}
Expand Down
15 changes: 14 additions & 1 deletion backend/core/plugin/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ package plugin

import (
"fmt"
"github.com/apache/incubator-devlake/core/errors"
"strings"

"github.com/apache/incubator-devlake/core/context"
"github.com/apache/incubator-devlake/core/errors"
)

// Allowing plugin to know each other
Expand Down Expand Up @@ -69,3 +71,14 @@ func FindPluginNameBySubPkgPath(subPkgPath string) (string, errors.Error) {
}
return "", errors.Default.New(fmt.Sprintf("Unable to find plugin for subPkgPath %s", subPkgPath))
}

func InitPlugins(basicRes context.BasicRes) {
for pluginName, pluginMeta := range plugins {
if pluginEntry, ok := pluginMeta.(PluginInit); ok {
err := pluginEntry.Init(basicRes)
if err != nil {
panic(fmt.Errorf("failed to initialize plugin %v due to %w", pluginName, err))
}
}
}
}
6 changes: 0 additions & 6 deletions backend/core/runner/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,6 @@ func LoadGoPlugins(basicRes context.BasicRes) errors.Error {
if !ok {
return errors.Default.New(fmt.Sprintf("%s PluginEntry must implement PluginMeta interface", pluginName))
}
if pluginEntry, ok := symPluginEntry.(plugin.PluginInit); ok {
err = pluginEntry.Init(basicRes)
if err != nil {
return err
}
}
err = plugin.RegisterPlugin(pluginName, pluginMeta)
if err != nil {
return err
Expand Down
33 changes: 23 additions & 10 deletions backend/helpers/pluginhelper/api/ds_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,40 @@ import (
"github.com/apache/incubator-devlake/helpers/srvhelper"
)

func NewDataSourceHelpers[
type DsHelper[
C plugin.ToolLayerConnection,
S plugin.ToolLayerScope,
SC plugin.ToolLayerScopeConfig,
] struct {
ConnSrv *srvhelper.ConnectionSrvHelper[C, S, SC]
ConnApi *DsConnectionApiHelper[C, S, SC]
ScopeSrv *srvhelper.ScopeSrvHelper[C, S, SC]
ScopeApi *DsScopeApiHelper[C, S, SC]
ScopeConfigSrv *srvhelper.ScopeConfigSrvHelper[C, S, SC]
ScopeConfigApi *DsScopeConfigApiHelper[C, S, SC]
}

func NewDataSourceHelper[
C plugin.ToolLayerConnection,
S plugin.ToolLayerScope,
SC plugin.ToolLayerScopeConfig,
](
basicRes context.BasicRes,
pluginName string,
scopeSearchColumns []string,
) (
*srvhelper.ConnectionSrvHelper[C, S, SC],
*DsConnectionApiHelper[C, S, SC],
*srvhelper.ScopeSrvHelper[C, S, SC],
*DsScopeApiHelper[C, S, SC],
*srvhelper.ScopeConfigSrvHelper[C, S, SC],
*DsScopeConfigApiHelper[C, S, SC],
) {
) *DsHelper[C, S, SC] {
connSrv := srvhelper.NewConnectionSrvHelper[C, S, SC](basicRes, pluginName)
connApi := NewDsConnectionApiHelper[C, S, SC](basicRes, connSrv)
scopeSrv := srvhelper.NewScopeSrvHelper[C, S, SC](basicRes, pluginName, scopeSearchColumns)
scopeApi := NewDsScopeApiHelper[C, S, SC](basicRes, scopeSrv)
scSrv := srvhelper.NewScopeConfigSrvHelper[C, S, SC](basicRes)
scApi := NewDsScopeConfigApiHelper[C, S, SC](basicRes, scSrv)
return connSrv, connApi, scopeSrv, scopeApi, scSrv, scApi
return &DsHelper[C, S, SC]{
ConnSrv: connSrv,
ConnApi: connApi,
ScopeSrv: scopeSrv,
ScopeApi: scopeApi,
ScopeConfigSrv: scSrv,
ScopeConfigApi: scApi,
}
}
16 changes: 16 additions & 0 deletions backend/helpers/srvhelper/scope_service_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,22 @@ func (scopeSrv *ScopeSrvHelper[C, S, SC]) GetScopeDetail(includeBlueprints bool,
return scopeDetail, nil
}

// MapScopeDetails returns scope details (scope and scopeConfig) for the given blueprint scopes
func (scopeSrv *ScopeSrvHelper[C, S, SC]) MapScopeDetails(connectionId uint64, bpScopes []*models.BlueprintScope) ([]*ScopeDetail[S, SC], errors.Error) {
var err errors.Error
scopeDetails := make([]*ScopeDetail[S, SC], len(bpScopes))
for i, bpScope := range bpScopes {
scopeDetails[i], err = scopeSrv.GetScopeDetail(false, connectionId, bpScope.ScopeId)
if err != nil {
return nil, err
}
if scopeDetails[i].ScopeConfig == nil {
scopeDetails[i].ScopeConfig = new(SC)
}
}
return scopeDetails, nil
}

func (scopeSrv *ScopeSrvHelper[C, S, SC]) GetScopesPage(pagination *ScopePagination) ([]*ScopeDetail[S, SC], int64, errors.Error) {
if pagination.ConnectionId < 1 {
return nil, 0, errors.BadInput.New("connectionId is required")
Expand Down
194 changes: 0 additions & 194 deletions backend/plugins/github/api/blueprint_V200_test.go

This file was deleted.

Loading