Skip to content

Commit c473d27

Browse files
authored
Merge branch 'main' into main
2 parents 323bba0 + d8436cd commit c473d27

File tree

14 files changed

+669
-364
lines changed

14 files changed

+669
-364
lines changed

backend/plugins/testmo/impl/impl.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func (p Testmo) GetTablesInfo() []dal.Tabler {
6969
&models.TestmoProject{},
7070
&models.TestmoScopeConfig{},
7171
&models.TestmoAutomationRun{},
72-
&models.TestmoTest{},
72+
&models.TestmoRun{},
7373
&models.TestmoMilestone{},
7474
}
7575
}
@@ -90,10 +90,11 @@ func (p Testmo) SubTaskMetas() []plugin.SubTaskMeta {
9090
tasks.ExtractMilestonesMeta,
9191
tasks.CollectAutomationRunsMeta,
9292
tasks.ExtractAutomationRunsMeta,
93-
tasks.CollectTestsMeta,
94-
tasks.ExtractTestsMeta,
93+
tasks.CollectRunsMeta,
94+
tasks.ExtractRunsMeta,
95+
tasks.ConvertProjectsMeta,
9596
tasks.ConvertAutomationRunsMeta,
96-
tasks.ConvertTestsMeta,
97+
tasks.ConvertRunsMeta,
9798
}
9899
}
99100

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
Licensed to the Apache Software Foundation (ASF) under one or more
3+
contributor license agreements. See the NOTICE file distributed with
4+
this work for additional information regarding copyright ownership.
5+
The ASF licenses this file to You under the Apache License, Version 2.0
6+
(the "License"); you may not use this file except in compliance with
7+
the License. You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
18+
package migrationscripts
19+
20+
import (
21+
"github.com/apache/incubator-devlake/core/context"
22+
"github.com/apache/incubator-devlake/core/errors"
23+
"github.com/apache/incubator-devlake/core/plugin"
24+
"github.com/apache/incubator-devlake/helpers/migrationhelper"
25+
"github.com/apache/incubator-devlake/plugins/testmo/models/migrationscripts/archived"
26+
)
27+
28+
type replaceTestsWithRuns struct{}
29+
30+
func (*replaceTestsWithRuns) Up(basicRes context.BasicRes) errors.Error {
31+
db := basicRes.GetDal()
32+
33+
// Check if the old tool layer tests table exists and drop it if it does
34+
if db.HasTable("_tool_testmo_tests") {
35+
err := db.DropTables("_tool_testmo_tests")
36+
if err != nil {
37+
return err
38+
}
39+
}
40+
41+
// Check if the old raw tests table exists and drop it if it does
42+
if db.HasTable("_raw_testmo_tests") {
43+
err := db.DropTables("_raw_testmo_tests")
44+
if err != nil {
45+
return err
46+
}
47+
}
48+
49+
// Create the new runs table
50+
return migrationhelper.AutoMigrateTables(
51+
basicRes,
52+
&archived.TestmoRun{},
53+
)
54+
}
55+
56+
func (*replaceTestsWithRuns) Version() uint64 {
57+
return 20250808000001
58+
}
59+
60+
func (*replaceTestsWithRuns) Name() string {
61+
return "Replace testmo tests tables with runs table (both tool and raw layers)"
62+
}
63+
64+
var _ plugin.MigrationScript = (*replaceTestsWithRuns)(nil)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
Licensed to the Apache Software Foundation (ASF) under one or more
3+
contributor license agreements. See the NOTICE file distributed with
4+
this work for additional information regarding copyright ownership.
5+
The ASF licenses this file to You under the Apache License, Version 2.0
6+
(the "License"); you may not use this file except in compliance with
7+
the License. You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
18+
package archived
19+
20+
import (
21+
"time"
22+
)
23+
24+
type TestmoRun struct {
25+
ConnectionId uint64 `gorm:"primaryKey;type:BIGINT NOT NULL"`
26+
Id uint64 `gorm:"primaryKey;type:BIGINT NOT NULL;autoIncrement:false" json:"id"`
27+
ProjectId uint64 `gorm:"index;type:BIGINT NOT NULL" json:"project_id"`
28+
Name string `gorm:"type:varchar(500)" json:"name"`
29+
Status int32 `json:"status"`
30+
StatusName string `gorm:"type:varchar(100)" json:"status_name"`
31+
Elapsed *int64 `json:"elapsed"`
32+
Message string `gorm:"type:text" json:"message"`
33+
34+
// Run classification
35+
IsAcceptanceTest bool `gorm:"index" json:"is_acceptance_test"`
36+
IsSmokeTest bool `gorm:"index" json:"is_smoke_test"`
37+
Team string `gorm:"type:varchar(255);index" json:"team"`
38+
39+
// Timestamps
40+
TestmoCreatedAt *time.Time `json:"created_at"`
41+
TestmoUpdatedAt *time.Time `json:"updated_at"`
42+
43+
// Inline definition of NoPKModel
44+
CreatedAt time.Time `json:"createdAt"`
45+
UpdatedAt time.Time `json:"updatedAt"`
46+
}
47+
48+
func (TestmoRun) TableName() string {
49+
return "_tool_testmo_runs"
50+
}

backend/plugins/testmo/models/migrationscripts/register.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,6 @@ func All() []plugin.MigrationScript {
2323
return []plugin.MigrationScript{
2424
new(addInitTables),
2525
new(addScopeConfigIdToProjects),
26+
new(replaceTestsWithRuns),
2627
}
2728
}

backend/plugins/testmo/models/test.go renamed to backend/plugins/testmo/models/run.go

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,17 @@ import (
2323
"github.com/apache/incubator-devlake/core/models/common"
2424
)
2525

26-
type TestmoTest struct {
27-
ConnectionId uint64 `gorm:"primaryKey;type:BIGINT NOT NULL"`
28-
Id uint64 `gorm:"primaryKey;type:BIGINT NOT NULL;autoIncrement:false" json:"id"`
29-
ProjectId uint64 `gorm:"index;type:BIGINT NOT NULL" json:"project_id"`
30-
AutomationRunId uint64 `gorm:"index;type:BIGINT NOT NULL" json:"automation_run_id"`
31-
ThreadId uint64 `json:"thread_id"`
32-
Name string `gorm:"type:varchar(500)" json:"name"`
33-
Key string `gorm:"type:varchar(255)" json:"key"`
34-
Status int32 `json:"status"`
35-
StatusName string `gorm:"type:varchar(100)" json:"status_name"`
36-
Elapsed *int64 `json:"elapsed"`
37-
Message string `gorm:"type:text" json:"message"`
38-
39-
// Test classification
26+
type TestmoRun struct {
27+
ConnectionId uint64 `gorm:"primaryKey;type:BIGINT NOT NULL"`
28+
Id uint64 `gorm:"primaryKey;type:BIGINT NOT NULL;autoIncrement:false" json:"id"`
29+
ProjectId uint64 `gorm:"index;type:BIGINT NOT NULL" json:"project_id"`
30+
Name string `gorm:"type:varchar(500)" json:"name"`
31+
Status int32 `json:"status"`
32+
StatusName string `gorm:"type:varchar(100)" json:"status_name"`
33+
Elapsed *int64 `json:"elapsed"`
34+
Message string `gorm:"type:text" json:"message"`
35+
36+
// Run classification
4037
IsAcceptanceTest bool `gorm:"index" json:"is_acceptance_test"`
4138
IsSmokeTest bool `gorm:"index" json:"is_smoke_test"`
4239
Team string `gorm:"type:varchar(255);index" json:"team"`
@@ -48,6 +45,6 @@ type TestmoTest struct {
4845
common.NoPKModel
4946
}
5047

51-
func (TestmoTest) TableName() string {
52-
return "_tool_testmo_tests"
48+
func (TestmoRun) TableName() string {
49+
return "_tool_testmo_runs"
5350
}

backend/plugins/testmo/tasks/automation_run_converter.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@ import (
2222

2323
"github.com/apache/incubator-devlake/core/dal"
2424
"github.com/apache/incubator-devlake/core/errors"
25-
"github.com/apache/incubator-devlake/core/models/domainlayer"
26-
"github.com/apache/incubator-devlake/core/models/domainlayer/didgen"
27-
"github.com/apache/incubator-devlake/core/models/domainlayer/qa"
2825
"github.com/apache/incubator-devlake/core/plugin"
2926
helper "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
3027
testmoModels "github.com/apache/incubator-devlake/plugins/testmo/models"
@@ -60,17 +57,8 @@ func ConvertAutomationRuns(taskCtx plugin.SubTaskContext) errors.Error {
6057
InputRowType: reflect.TypeOf(testmoModels.TestmoAutomationRun{}),
6158
Input: cursor,
6259
Convert: func(inputRow interface{}) ([]interface{}, errors.Error) {
63-
run := inputRow.(*testmoModels.TestmoAutomationRun)
6460

65-
// Convert to domain layer QA project (representing test suite)
66-
qaProject := &qa.QaProject{
67-
DomainEntityExtended: domainlayer.DomainEntityExtended{
68-
Id: didgen.NewDomainIdGenerator(&testmoModels.TestmoAutomationRun{}).Generate(data.Options.ConnectionId, run.Id),
69-
},
70-
Name: run.Name,
71-
}
72-
73-
return []interface{}{qaProject}, nil
61+
return []interface{}{}, nil
7462
},
7563
})
7664

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
Licensed to the Apache Software Foundation (ASF) under one or more
3+
contributor license agreements. See the NOTICE file distributed with
4+
this work for additional information regarding copyright ownership.
5+
The ASF licenses this file to You under the Apache License, Version 2.0
6+
(the "License"); you may not use this file except in compliance with
7+
the License. You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
18+
package tasks
19+
20+
import (
21+
"fmt"
22+
"reflect"
23+
24+
"github.com/apache/incubator-devlake/core/dal"
25+
"github.com/apache/incubator-devlake/core/errors"
26+
"github.com/apache/incubator-devlake/core/models/domainlayer"
27+
"github.com/apache/incubator-devlake/core/models/domainlayer/didgen"
28+
"github.com/apache/incubator-devlake/core/models/domainlayer/qa"
29+
"github.com/apache/incubator-devlake/core/plugin"
30+
helper "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
31+
testmoModels "github.com/apache/incubator-devlake/plugins/testmo/models"
32+
)
33+
34+
var ConvertProjectsMeta = plugin.SubTaskMeta{
35+
Name: "convertProjects",
36+
EntryPoint: ConvertProjects,
37+
EnabledByDefault: true,
38+
Description: "Convert tool layer table testmo_projects into domain layer table qa_projects",
39+
DomainTypes: []string{plugin.DOMAIN_TYPE_CODE_QUALITY},
40+
}
41+
42+
func ConvertProjects(taskCtx plugin.SubTaskContext) errors.Error {
43+
data := taskCtx.GetData().(*TestmoTaskData)
44+
db := taskCtx.GetDal()
45+
46+
cursor, err := db.Cursor(dal.From(&testmoModels.TestmoProject{}), dal.Where("connection_id = ? AND id = ?", data.Options.ConnectionId, data.Options.ProjectId))
47+
if err != nil {
48+
return err
49+
}
50+
defer cursor.Close()
51+
52+
converter, err := helper.NewDataConverter(helper.DataConverterArgs{
53+
RawDataSubTaskArgs: helper.RawDataSubTaskArgs{
54+
Ctx: taskCtx,
55+
Params: TestmoApiParams{
56+
ConnectionId: data.Options.ConnectionId,
57+
ProjectId: data.Options.ProjectId,
58+
},
59+
Table: RAW_PROJECT_TABLE,
60+
},
61+
InputRowType: reflect.TypeOf(testmoModels.TestmoProject{}),
62+
Input: cursor,
63+
Convert: func(inputRow interface{}) ([]interface{}, errors.Error) {
64+
project := inputRow.(*testmoModels.TestmoProject)
65+
66+
// Convert to domain layer QA project
67+
projectName := project.Name
68+
if projectName == "" {
69+
projectName = fmt.Sprintf("Project %d", project.Id)
70+
}
71+
72+
qaProject := &qa.QaProject{
73+
DomainEntityExtended: domainlayer.DomainEntityExtended{
74+
Id: didgen.NewDomainIdGenerator(&testmoModels.TestmoProject{}).Generate(data.Options.ConnectionId, project.Id),
75+
},
76+
Name: projectName,
77+
}
78+
79+
return []interface{}{qaProject}, nil
80+
},
81+
})
82+
83+
if err != nil {
84+
return err
85+
}
86+
87+
return converter.Execute()
88+
}
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
Licensed to the Apache Software Foundation (ASF) under one or more
3+
contributor license agreements. See the NOTICE file distributed with
4+
this work for additional information regarding copyright ownership.
5+
The ASF licenses this file to You under the Apache License, Version 2.0
6+
(the "License"); you may not use this file except in compliance with
7+
the License. You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
*/
17+
18+
package tasks
19+
20+
import (
21+
"encoding/json"
22+
"fmt"
23+
"net/http"
24+
"net/url"
25+
26+
"github.com/apache/incubator-devlake/core/errors"
27+
"github.com/apache/incubator-devlake/core/plugin"
28+
helper "github.com/apache/incubator-devlake/helpers/pluginhelper/api"
29+
)
30+
31+
const RAW_RUN_TABLE = "testmo_runs"
32+
33+
var CollectRunsMeta = plugin.SubTaskMeta{
34+
Name: "collectRuns",
35+
EntryPoint: CollectRuns,
36+
EnabledByDefault: true,
37+
Description: "Collect runs data from Testmo api",
38+
DomainTypes: []string{plugin.DOMAIN_TYPE_CODE_QUALITY},
39+
}
40+
41+
func CollectRuns(taskCtx plugin.SubTaskContext) errors.Error {
42+
data := taskCtx.GetData().(*TestmoTaskData)
43+
logger := taskCtx.GetLogger()
44+
logger.Info("collecting runs")
45+
46+
collector, err := helper.NewApiCollector(helper.ApiCollectorArgs{
47+
RawDataSubTaskArgs: helper.RawDataSubTaskArgs{
48+
Ctx: taskCtx,
49+
Params: TestmoApiParams{
50+
ConnectionId: data.Options.ConnectionId,
51+
ProjectId: data.Options.ProjectId,
52+
},
53+
Table: RAW_RUN_TABLE,
54+
},
55+
ApiClient: data.ApiClient,
56+
PageSize: 100,
57+
Incremental: false,
58+
UrlTemplate: "projects/{{ .Params.ProjectId }}/runs",
59+
Query: func(reqData *helper.RequestData) (url.Values, errors.Error) {
60+
query := url.Values{}
61+
query.Set("page", fmt.Sprintf("%v", reqData.Pager.Page))
62+
query.Set("per_page", fmt.Sprintf("%v", reqData.Pager.Size))
63+
return query, nil
64+
},
65+
GetTotalPages: GetTotalPagesFromResponse,
66+
ResponseParser: func(res *http.Response) ([]json.RawMessage, errors.Error) {
67+
return GetRawMessageFromResponse(res)
68+
},
69+
})
70+
71+
if err != nil {
72+
return err
73+
}
74+
75+
return collector.Execute()
76+
}

0 commit comments

Comments
 (0)