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
2 changes: 2 additions & 0 deletions backend/plugins/table_info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ import (
starrocks "github.com/apache/incubator-devlake/plugins/starrocks/impl"
tapd "github.com/apache/incubator-devlake/plugins/tapd/impl"
teambition "github.com/apache/incubator-devlake/plugins/teambition/impl"
testmo "github.com/apache/incubator-devlake/plugins/testmo/impl"
trello "github.com/apache/incubator-devlake/plugins/trello/impl"
webhook "github.com/apache/incubator-devlake/plugins/webhook/impl"
zentao "github.com/apache/incubator-devlake/plugins/zentao/impl"
Expand Down Expand Up @@ -86,6 +87,7 @@ func Test_GetPluginTablesInfo(t *testing.T) {
checker.FeedIn("starrocks", starrocks.StarRocks{}.GetTablesInfo)
checker.FeedIn("tapd/models", tapd.Tapd{}.GetTablesInfo)
checker.FeedIn("teambition/models", teambition.Teambition{}.GetTablesInfo)
checker.FeedIn("testmo/models", testmo.Testmo{}.GetTablesInfo)
checker.FeedIn("trello/models", trello.Trello{}.GetTablesInfo)
checker.FeedIn("webhook/models", webhook.Webhook{}.GetTablesInfo)
checker.FeedIn("zentao/models", zentao.Zentao{}.GetTablesInfo)
Expand Down
22 changes: 22 additions & 0 deletions backend/plugins/testmo/api/blueprint.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package api

// Blueprint functionality is temporarily disabled due to outdated plugin types
// This file contains blueprint functionality which appears to use outdated plugin types.
// TODO: Update to newer blueprint patterns once available
98 changes: 98 additions & 0 deletions backend/plugins/testmo/api/blueprint_v200.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package api

import (
"github.com/apache/incubator-devlake/core/errors"
coreModels "github.com/apache/incubator-devlake/core/models"
"github.com/apache/incubator-devlake/core/plugin"
"github.com/apache/incubator-devlake/helpers/pluginhelper/api"
"github.com/apache/incubator-devlake/helpers/srvhelper"
"github.com/apache/incubator-devlake/plugins/testmo/models"
"github.com/apache/incubator-devlake/plugins/testmo/tasks"
)

func MakeDataSourcePipelinePlanV200(
subtaskMetas []plugin.SubTaskMeta,
connectionId uint64,
bpScopes []*coreModels.BlueprintScope,
) (coreModels.PipelinePlan, []plugin.Scope, errors.Error) {
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 := makePipelinePlanV200(subtaskMetas, scopeDetails, connection)
if err != nil {
return nil, nil, err
}
scopes, err := makeScopesV200(scopeDetails, connection)
return plan, scopes, err
}

func makePipelinePlanV200(
subtaskMetas []plugin.SubTaskMeta,
scopeDetails []*srvhelper.ScopeDetail[models.TestmoProject, models.TestmoScopeConfig],
connection *models.TestmoConnection,
) (coreModels.PipelinePlan, errors.Error) {
plan := make(coreModels.PipelinePlan, len(scopeDetails))
for i, scopeDetail := range scopeDetails {
stage := plan[i]
if stage == nil {
stage = coreModels.PipelineStage{}
}

scope, scopeConfig := scopeDetail.Scope, scopeDetail.ScopeConfig
// construct task options for testmo
task, err := api.MakePipelinePlanTask(
"testmo",
subtaskMetas,
scopeConfig.Entities,
tasks.TestmoOptions{
ConnectionId: connection.ID,
ProjectId: scope.Id,
ScopeConfig: scopeConfig,
},
)
if err != nil {
return nil, err
}
stage = append(stage, task)
plan[i] = stage
}

return plan, nil
}

func makeScopesV200(
scopeDetails []*srvhelper.ScopeDetail[models.TestmoProject, models.TestmoScopeConfig],
connection *models.TestmoConnection,
) ([]plugin.Scope, errors.Error) {
scopes := make([]plugin.Scope, 0, len(scopeDetails))

for _, scopeDetail := range scopeDetails {
scope := scopeDetail.Scope
// Return the TestmoProject itself as it implements plugin.Scope
scopes = append(scopes, scope)
}

return scopes, nil
}
109 changes: 109 additions & 0 deletions backend/plugins/testmo/api/connection.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
/*
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package api

import (
"context"
"net/http"

"github.com/apache/incubator-devlake/core/errors"
"github.com/apache/incubator-devlake/core/plugin"
helper "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
"github.com/apache/incubator-devlake/plugins/testmo/models"
)

func testConnection(ctx context.Context, connection models.TestmoConn) (*plugin.ApiResourceOutput, errors.Error) {
if vld != nil {
if err := vld.Struct(connection); err != nil {
return nil, errors.Default.Wrap(err, "error validating target")
}
}
apiClient, err := helper.NewApiClientFromConnection(ctx, basicRes, &connection)
if err != nil {
return nil, err
}
response, err := apiClient.Get("projects", nil, nil)
if err != nil {
return nil, err
}
if response.StatusCode == http.StatusUnauthorized {
return nil, errors.HttpStatus(http.StatusBadRequest).New("StatusUnauthorized error while testing connection")
}
if response.StatusCode == http.StatusOK {
return &plugin.ApiResourceOutput{Body: nil, Status: http.StatusOK}, nil
}
return &plugin.ApiResourceOutput{Body: nil, Status: response.StatusCode}, errors.HttpStatus(response.StatusCode).Wrap(err, "could not validate connection")
}

func TestConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
var connection models.TestmoConn
err := helper.Decode(input.Body, &connection, vld)
if err != nil {
return nil, err
}
testConnectionResult, testConnectionErr := testConnection(context.TODO(), connection)
if testConnectionErr != nil {
return nil, plugin.WrapTestConnectionErrResp(basicRes, testConnectionErr)
}
return testConnectionResult, nil
}

// TestExistingConnection test testmo connection
// @Summary test testmo connection
// @Description Test Testmo Connection
// @Tags plugins/testmo
// @Param connectionId path int true "connection ID"
// @Success 200 {object} shared.ApiBody "Success"
// @Failure 400 {string} errcode.Error "Bad Request"
// @Failure 500 {string} errcode.Error "Internal Error"
// @Router /plugins/testmo/connections/{connectionId}/test [POST]
func TestExistingConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
connection, err := dsHelper.ConnApi.GetMergedConnection(input)
if err != nil {
return nil, errors.BadInput.Wrap(err, "find connection from db")
}
if err := helper.DecodeMapStruct(input.Body, connection, false); err != nil {
return nil, err
}
testConnectionResult, testConnectionErr := testConnection(context.TODO(), connection.TestmoConn)
if testConnectionErr != nil {
return nil, plugin.WrapTestConnectionErrResp(basicRes, testConnectionErr)
}
return testConnectionResult, nil
}

// Connection CRUD operations
func PostConnections(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
return dsHelper.ConnApi.Post(input)
}

func PatchConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
return dsHelper.ConnApi.Patch(input)
}

func DeleteConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
return dsHelper.ConnApi.Delete(input)
}

func ListConnections(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
return dsHelper.ConnApi.GetAll(input)
}

func GetConnection(input *plugin.ApiResourceInput) (*plugin.ApiResourceOutput, errors.Error) {
return dsHelper.ConnApi.GetDetail(input)
}
54 changes: 54 additions & 0 deletions backend/plugins/testmo/api/init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package api

import (
"github.com/apache/incubator-devlake/core/context"
"github.com/apache/incubator-devlake/core/plugin"
"github.com/apache/incubator-devlake/helpers/pluginhelper/api"
"github.com/apache/incubator-devlake/plugins/testmo/models"
"github.com/go-playground/validator/v10"
)

var vld *validator.Validate
var basicRes context.BasicRes

var dsHelper *api.DsHelper[models.TestmoConnection, models.TestmoProject, models.TestmoScopeConfig]
var raProxy *api.DsRemoteApiProxyHelper[models.TestmoConnection]
var raScopeList *api.DsRemoteApiScopeListHelper[models.TestmoConnection, models.TestmoProject, TestmoRemotePagination]
var raScopeSearch *api.DsRemoteApiScopeSearchHelper[models.TestmoConnection, models.TestmoProject]

func Init(br context.BasicRes, p plugin.PluginMeta) {
vld = validator.New()
basicRes = br
dsHelper = api.NewDataSourceHelper[
models.TestmoConnection, models.TestmoProject, models.TestmoScopeConfig,
](
br,
p.Name(),
[]string{"name"},
func(c models.TestmoConnection) models.TestmoConnection {
return c.Sanitize()
},
nil,
nil,
)
raProxy = api.NewDsRemoteApiProxyHelper[models.TestmoConnection](dsHelper.ConnApi.ModelApiHelper)
raScopeList = api.NewDsRemoteApiScopeListHelper[models.TestmoConnection, models.TestmoProject, TestmoRemotePagination](raProxy, listTestmoRemoteScopes)
raScopeSearch = api.NewDsRemoteApiScopeSearchHelper[models.TestmoConnection, models.TestmoProject](raProxy, searchTestmoRemoteScopes)
}
Loading
Loading