Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions backend/helpers/pluginhelper/api/ds_scope_api_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,13 @@ import (
"github.com/apache/incubator-devlake/core/errors"
"github.com/apache/incubator-devlake/core/models/common"
"github.com/apache/incubator-devlake/core/plugin"
serviceHelper "github.com/apache/incubator-devlake/helpers/pluginhelper/services"
"github.com/apache/incubator-devlake/helpers/srvhelper"
"github.com/apache/incubator-devlake/server/api/shared"
)

type ScopeRefDoc = serviceHelper.BlueprintProjectPairs

type PutScopesReqBody[T any] struct {
Data []*T `json:"data"`
}
Expand Down
1 change: 0 additions & 1 deletion backend/helpers/pluginhelper/api/scope_generic_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ type (
Blueprints []*models.Blueprint `mapstructure:"blueprints,omitempty" json:"blueprints"`
}
// Alias, for swagger purposes
ScopeRefDoc = serviceHelper.BlueprintProjectPairs
ScopeRes[Scope plugin.ToolLayerScope, ScopeConfig any] struct {
Scope Scope `mapstructure:"scope,omitempty" json:"scope,omitempty"`
ScopeConfig *ScopeConfig `mapstructure:"scopeConfig,omitempty" json:"scopeConfig,omitempty"`
Expand Down
1 change: 0 additions & 1 deletion backend/helpers/srvhelper/model_service_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ func (srv *ModelSrvHelper[M]) ValidateModel(model *M) errors.Error {

// Create validates given model and insert it into database if validation passed
func (srv *ModelSrvHelper[M]) Create(model *M) errors.Error {
println("create model")
err := srv.ValidateModel(model)
if err != nil {
return err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,16 @@ import (
"github.com/apache/incubator-devlake/plugins/bitbucket_server/models"
)

type ScopeRes struct {
models.BitbucketServerRepo
api.ScopeResDoc[models.BitbucketServerScopeConfig]
}

type ScopeReq api.ScopeReq[models.BitbucketServerRepo]
type PutScopesReqBody api.PutScopesReqBody[models.BitbucketServerRepo]
type ScopeDetail api.ScopeDetail[models.BitbucketServerRepo, models.BitbucketServerScopeConfig]

// PutScope create or update repo
// @Summary create or update repo
// @Description Create or update repo
// @Tags plugins/bitbucket_server
// @Accept application/json
// @Param connectionId path int true "connection ID"
// @Param scope body ScopeReq true "json"
// @Param scope body PutScopesReqBody true "json"
// @Success 200 {object} []models.BitbucketServerRepo
// @Failure 400 {object} shared.ApiBody "Bad Request"
// @Failure 500 {object} shared.ApiBody "Internal Error"
Expand Down Expand Up @@ -74,7 +70,7 @@ func UpdateScope(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, err
// @Param pageSize query int false "page size, default 50"
// @Param page query int false "page size, default 1"
// @Param blueprints query bool false "also return blueprints using these scopes as part of the payload"
// @Success 200 {object} []ScopeRes
// @Success 200 {object} []ScopeDetail
// @Failure 400 {object} shared.ApiBody "Bad Request"
// @Failure 500 {object} shared.ApiBody "Internal Error"
// @Router /plugins/bitbucket_server/connections/{connectionId}/scopes/ [GET]
Expand All @@ -97,7 +93,7 @@ func GetScopeDispatcher(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutp
// @Tags plugins/bitbucket_server
// @Param connectionId path int true "connection ID"
// @Param scopeId path string true "repo ID"
// @Success 200 {object} ScopeRes
// @Success 200 {object} ScopeDetail
// @Failure 400 {object} shared.ApiBody "Bad Request"
// @Failure 500 {object} shared.ApiBody "Internal Error"
// @Router /plugins/bitbucket_server/connections/{connectionId}/scopes/{scopeId} [GET]
Expand Down
6 changes: 3 additions & 3 deletions backend/plugins/circleci/tasks/task_data.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ import (
type CircleciOptions struct {
ConnectionId uint64 `json:"connectionId" mapstructure:"connectionId"`
ProjectSlug string `json:"projectSlug" mapstructure:"projectSlug"`
PageSize uint64 `mapstruct:"pageSize" mapstructure:"pageSize,omitempty"`
ScopeConfigId uint64 `json:"scopeConfigId" mapstructure:"scopeConfigId,omitempty"`
ScopeConfig *models.CircleciScopeConfig `json:"scopeConfig" mapstructure:"scopeConfig,omitempty"`
PageSize uint64 `json:"pageSize,omitempty" mapstructure:"pageSize,omitempty"`
ScopeConfigId uint64 `json:"scopeConfigId,omitempty" mapstructure:"scopeConfigId,omitempty"`
ScopeConfig *models.CircleciScopeConfig `json:"scopeConfig,omitempty" mapstructure:"scopeConfig,omitempty"`
}

type CircleciTaskData struct {
Expand Down
22 changes: 8 additions & 14 deletions backend/plugins/opsgenie/api/blueprint_v200.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,30 +35,23 @@ func MakeDataSourcePipelinePlanV200(
connectionId uint64,
bpScopes []*coreModels.BlueprintScope,
) (coreModels.PipelinePlan, []plugin.Scope, errors.Error) {
// get the connection info for url
connection := &models.OpsgenieConnection{}
err := connectionHelper.FirstById(connection, connectionId)
connection, err := dsHelper.ConnSrv.FindByPk(connectionId)
if err != nil {
return nil, nil, err
}
scopeDetails, err := dsHelper.ScopeSrv.MapScopeDetails(connectionId, bpScopes)
if err != nil {
return nil, nil, err
}

plan, err := makeDataSourcePipelinePlanV200(subtaskMetas, scopeDetails, connection)
plan, err := makePipelinePlanV200(subtaskMetas, scopeDetails, connection)
if err != nil {
return nil, nil, err
}
scopes, err := makeScopesV200(scopeDetails, connection)
if err != nil {
return nil, nil, err
}

return plan, scopes, nil
return plan, scopes, err
}

func makeDataSourcePipelinePlanV200(
func makePipelinePlanV200(
subtaskMetas []plugin.SubTaskMeta,
scopeDetails []*srvhelper.ScopeDetail[models.Service, models.OpsenieScopeConfig],
connection *models.OpsgenieConnection,
Expand All @@ -77,7 +70,7 @@ func makeDataSourcePipelinePlanV200(
subtaskMetas,
scopeConfig.Entities,
OpsgenieTaskOptions{
ConnectionId: scope.ConnectionId,
ConnectionId: connection.ID,
ServiceId: scope.Id,
ServiceName: scope.Name,
},
Expand All @@ -95,15 +88,16 @@ func makeDataSourcePipelinePlanV200(

func makeScopesV200(
scopeDetails []*srvhelper.ScopeDetail[models.Service, models.OpsenieScopeConfig],
connection *models.OpsgenieConnection) ([]plugin.Scope, errors.Error) {
connection *models.OpsgenieConnection,
) ([]plugin.Scope, errors.Error) {
scopes := make([]plugin.Scope, 0)
for _, scopeDetail := range scopeDetails {
opService, scopeConfig := scopeDetail.Scope, scopeDetail.ScopeConfig
// add service to scopes
if utils.StringsContains(scopeConfig.Entities, plugin.DOMAIN_TYPE_TICKET) {
domainBoard := &ticket.Board{
DomainEntity: domainlayer.DomainEntity{
Id: didgen.NewDomainIdGenerator(&models.Service{}).Generate(opService.ConnectionId, opService.Id),
Id: didgen.NewDomainIdGenerator(&models.Service{}).Generate(connection.ID, opService.Id),
},
Name: opService.Name,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@ func testOpsgenieConn(ctx context.Context, connection models.OpsgenieConn) (*plu
// @Failure 500 {string} errcode.Error "Internal Error"
// @Router /plugins/opsgenie/connections/{connectionId}/test [POST]
func TestExistingConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
connection := &models.OpsgenieConnection{}
err := connectionHelper.First(connection, input.Params)
connection, err := dsHelper.ConnApi.GetMergedConnection(input)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -114,12 +113,7 @@ func TestConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput,
// @Failure 500 {string} errcode.Error "Internal Error"
// @Router /plugins/opsgenie/connections [POST]
func PostConnections(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
connection := &models.OpsgenieConnection{}
err := connectionHelper.Create(connection, input)
if err != nil {
return nil, err
}
return &plugin.ApiResourceOutput{Body: connection.Sanitize(), Status: http.StatusOK}, nil
return dsHelper.ConnApi.Post(input)
}

// @Summary patch opsgenie connection
Expand All @@ -131,17 +125,7 @@ func PostConnections(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput,
// @Failure 500 {string} errcode.Error "Internal Error"
// @Router /plugins/opsgenie/connections/{connectionId} [PATCH]
func PatchConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
connection := &models.OpsgenieConnection{}
if err := connectionHelper.First(&connection, input.Params); err != nil {
return nil, err
}
if err := (&models.OpsgenieConnection{}).MergeFromRequest(connection, input.Body); err != nil {
return nil, errors.Convert(err)
}
if err := connectionHelper.SaveWithCreateOrUpdate(connection); err != nil {
return nil, err
}
return &plugin.ApiResourceOutput{Body: connection.Sanitize(), Status: http.StatusOK}, nil
return dsHelper.ConnApi.Patch(input)
}

// @Summary delete opsgenie connection
Expand All @@ -153,7 +137,7 @@ func PatchConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput,
// @Failure 500 {string} errcode.Error "Internal Error"
// @Router /plugins/opsgenie/connections/{connectionId} [DELETE]
func DeleteConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
return connectionHelper.Delete(&models.OpsgenieConnection{}, input)
return dsHelper.ConnApi.Delete(input)
}

// @Summary list opsgenie connections
Expand All @@ -164,15 +148,7 @@ func DeleteConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput
// @Failure 500 {string} errcode.Error "Internal Error"
// @Router /plugins/opsgenie/connections [GET]
func ListConnections(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
var connections []models.OpsgenieConnection
err := connectionHelper.List(&connections)
if err != nil {
return nil, err
}
for idx, c := range connections {
connections[idx] = c.Sanitize()
}
return &plugin.ApiResourceOutput{Body: connections}, nil
return dsHelper.ConnApi.GetAll(input)
}

// @Summary get opsgenie connection
Expand All @@ -183,10 +159,5 @@ func ListConnections(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput,
// @Failure 500 {string} errcode.Error "Internal Error"
// @Router /plugins/opsgenie/connections/{connectionId} [GET]
func GetConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
connection := &models.OpsgenieConnection{}
err := connectionHelper.First(connection, input.Params)
if err != nil {
return nil, err
}
return &plugin.ApiResourceOutput{Body: connection.Sanitize()}, nil
return dsHelper.ConnApi.GetDetail(input)
}
16 changes: 6 additions & 10 deletions backend/plugins/opsgenie/api/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,15 @@ import (
)

var vld *validator.Validate
var connectionHelper *api.ConnectionApiHelper
var dsHelper *api.DsHelper[models.OpsgenieConnection, models.Service, models.OpsenieScopeConfig]

var basicRes context.BasicRes
var dsHelper *api.DsHelper[models.OpsgenieConnection, models.Service, models.OpsenieScopeConfig]
var raProxy *api.DsRemoteApiProxyHelper[models.OpsgenieConnection]
var raScopeList *api.DsRemoteApiScopeListHelper[models.OpsgenieConnection, models.Service, OpsgenieRemotePagination]

func Init(br context.BasicRes, p plugin.PluginMeta) {

basicRes = br
vld = validator.New()
connectionHelper = api.NewConnectionHelper(
basicRes,
vld,
p.Name(),
)

dsHelper = api.NewDataSourceHelper[
models.OpsgenieConnection, models.Service, models.OpsenieScopeConfig,
](
Expand All @@ -52,5 +47,6 @@ func Init(br context.BasicRes, p plugin.PluginMeta) {
nil,
nil,
)

raProxy = api.NewDsRemoteApiProxyHelper[models.OpsgenieConnection](dsHelper.ConnApi.ModelApiHelper)
raScopeList = api.NewDsRemoteApiScopeListHelper[models.OpsgenieConnection, models.Service, OpsgenieRemotePagination](raProxy, listOpsgenieRemoteScopes)
}
Loading