Skip to content

Commit

Permalink
make task action can be disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
chengjoey committed Oct 21, 2021
1 parent 41adf89 commit 16f0862
Show file tree
Hide file tree
Showing 18 changed files with 165 additions and 63 deletions.
1 change: 1 addition & 0 deletions .erda/migrations/qa/20211015-auto-test-step-disable.sql
@@ -0,0 +1 @@
ALTER TABLE dice_autotest_scene_step ADD COLUMN `is_disabled` bool DEFAULT false COMMENT 'disable or enable execute';
7 changes: 4 additions & 3 deletions api/proto-go/core/pipeline/base/pb/base.validator.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 20 additions & 18 deletions apistructs/autotest_scene.go
Expand Up @@ -88,18 +88,19 @@ type AutoTestSceneOutput struct {

type AutoTestSceneStep struct {
AutoTestSceneParams
Type StepAPIType `json:"type"` // 类型
Method StepAPIMethod `json:"method"` // method
Value string `json:"value"` // 值
Name string `json:"name"` // 名称
PreID uint64 `json:"preID"` // 排序id
PreType PreType `json:"preType"` // 串行/并行类型
SceneID uint64 `json:"sceneID"` // 场景ID
SpaceID uint64 `json:"spaceID"` // 所属测试空间ID
CreatorID string `json:"creatorID"`
UpdaterID string `json:"updaterID"`
Children []AutoTestSceneStep // 并行子节点
APISpecID uint64 `json:"apiSpecID"` // api集市id
Type StepAPIType `json:"type"` // 类型
Method StepAPIMethod `json:"method"` // method
Value string `json:"value"` // 值
Name string `json:"name"` // 名称
PreID uint64 `json:"preID"` // 排序id
PreType PreType `json:"preType"` // 串行/并行类型
SceneID uint64 `json:"sceneID"` // 场景ID
SpaceID uint64 `json:"spaceID"` // 所属测试空间ID
IsDisabled bool `json:"isDisabled"` // disable or enable step execute
CreatorID string `json:"creatorID"`
UpdaterID string `json:"updaterID"`
Children []AutoTestSceneStep // 并行子节点
APISpecID uint64 `json:"apiSpecID"` // api集市id
}

type AutotestSceneRequest struct {
Expand All @@ -113,12 +114,13 @@ type AutotestSceneRequest struct {
APISpecID uint64 `json:"apiSpecID,omitempty"` // api集市id
RefSetID uint64 `json:"refSetID,omitempty"` // 引用场景集的ID

Type StepAPIType `json:"type,omitempty"`
Target int64 `json:"target,omitempty"` // 目标位置
GroupID int64 `json:"groupID,omitempty"` // 串行ID
PreType PreType `json:"preType,omitempty"` // 并行/并行
Position int64 `json:"position,omitempty"` // 插入位置 (-1为前/1为后)
IsGroup bool `json:"isGroup,omitempty"` // 是否整组移动
Type StepAPIType `json:"type,omitempty"`
Target int64 `json:"target,omitempty"` // 目标位置
GroupID int64 `json:"groupID,omitempty"` // 串行ID
PreType PreType `json:"preType,omitempty"` // 并行/并行
Position int64 `json:"position,omitempty"` // 插入位置 (-1为前/1为后)
IsGroup bool `json:"isGroup,omitempty"` // 是否整组移动
IsDisabled *bool `json:"isDisabled,omitempty"` // disable or enable step execute

PageNo uint64 `json:"pageNo"`
PageSize uint64 `json:"pageSize"`
Expand Down
1 change: 1 addition & 0 deletions apistructs/component_protocol.go
Expand Up @@ -167,6 +167,7 @@ const (
AutoTestSceneStepMoveGroupOperationKey OperationKey = "moveGroup"
AutoTestSceneStepDeleteOperationKey OperationKey = "deleteAPI"
AutoTestSceneStepSplitOperationKey OperationKey = "standalone"
AutoTestSceneStepSwitchOperationKey OperationKey = "switch"

//auto-test scene set
ListSceneSetOperationKey OperationKey = "ListSceneSet"
Expand Down
4 changes: 4 additions & 0 deletions apistructs/pipeline_status.go
Expand Up @@ -235,6 +235,10 @@ func (status PipelineStatus) IsAbnormalFailedStatus() bool {
}
}

func (status PipelineStatus) IsDisabledStatus() bool {
return status == PipelineStatusDisabled
}

func (status PipelineStatus) IsFailedStatus() bool {
return status.IsNormalFailedStatus() || status.IsAbnormalFailedStatus()
}
Expand Down
38 changes: 20 additions & 18 deletions modules/dop/dao/autotest_scene_step.go
Expand Up @@ -25,16 +25,17 @@ import (

type AutoTestSceneStep struct {
dbengine.BaseModel
Type apistructs.StepAPIType `gorm:"type"` // 类型
Value string `gorm:"value"` // 值
Name string `gorm:"name"` // 名称
PreID uint64 `gorm:"pre_id"` // 排序id
PreType apistructs.PreType `gorm:"pre_type"` // 串行/并行类型
SceneID uint64 `gorm:"scene_id"` // 场景ID
SpaceID uint64 `gorm:"space_id"` // 所属测试空间ID
APISpecID uint64 `gorm:"column:api_spec_id"` // api集市id
CreatorID string `gorm:"creator_id"`
UpdaterID string `gorm:"updater_id"`
Type apistructs.StepAPIType `gorm:"type"` // 类型
Value string `gorm:"value"` // 值
Name string `gorm:"name"` // 名称
PreID uint64 `gorm:"pre_id"` // 排序id
PreType apistructs.PreType `gorm:"pre_type"` // 串行/并行类型
SceneID uint64 `gorm:"scene_id"` // 场景ID
SpaceID uint64 `gorm:"space_id"` // 所属测试空间ID
APISpecID uint64 `gorm:"column:api_spec_id"` // api集市id
IsDisabled bool `gorm:"is_disabled"` // disable or enable step execute
CreatorID string `gorm:"creator_id"`
UpdaterID string `gorm:"updater_id"`
}

func (AutoTestSceneStep) TableName() string {
Expand All @@ -54,14 +55,15 @@ func (v *AutoTestSceneStep) Convert() *apistructs.AutoTestSceneStep {
CreatorID: v.CreatorID,
UpdaterID: v.UpdaterID,
},
Type: v.Type,
Name: v.Name,
Value: v.Value,
PreID: v.PreID,
PreType: v.PreType,
SceneID: v.SceneID,
SpaceID: v.SpaceID,
APISpecID: v.APISpecID,
Type: v.Type,
Name: v.Name,
Value: v.Value,
PreID: v.PreID,
PreType: v.PreType,
SceneID: v.SceneID,
SpaceID: v.SpaceID,
IsDisabled: v.IsDisabled,
APISpecID: v.APISpecID,
}
}

Expand Down
1 change: 1 addition & 0 deletions modules/dop/services/autotest_v2/scene.go
Expand Up @@ -759,6 +759,7 @@ func StepToAction(step apistructs.AutoTestSceneStep, req apistructs.SnippetConfi
action.Labels[apistructs.AutotestType] = apistructs.AutotestSceneStep
action.Alias = pipelineyml.ActionAlias(strconv.Itoa(int(step.ID)))
action.If = expression.LeftPlaceholder + " 1 == 1 " + expression.RightPlaceholder
action.Disable = step.IsDisabled

switch step.Type {
case apistructs.StepTypeCustomScript:
Expand Down
3 changes: 3 additions & 0 deletions modules/dop/services/autotest_v2/scene_step.go
Expand Up @@ -114,6 +114,9 @@ func (svc *Service) UpdateAutoTestSceneStep(req apistructs.AutotestSceneRequest)
step.Name = req.Name
step.UpdaterID = req.UserID
step.APISpecID = req.APISpecID
if req.IsDisabled != nil {
step.IsDisabled = *req.IsDisabled
}
if err := svc.db.UpdateAutotestSceneStep(step); err != nil {
return 0, err
}
Expand Down
Expand Up @@ -50,6 +50,7 @@ type PropColumn struct {
ValueKey string `json:"valueKey"`
RenderType string `json:"renderType"`
Operations map[apistructs.OperationKey]apistructs.Operation `json:"operations"`
Tips string `json:"tips"`
}

type State struct {
Expand Down Expand Up @@ -216,6 +217,7 @@ Label:
{
Label: "接口总数",
ValueKey: "autoTestNum",
Tips: "接口总数不包括禁用接口",
},
{
Label: "接口执行率",
Expand Down
Expand Up @@ -279,6 +279,9 @@ func getStatus(req apistructs.PipelineStatus) map[string]interface{} {
if req.IsBeforePressRunButton() {
res["status"] = "default"
}
if req.IsDisabledStatus() {
res["status"] = "default"
}
return res
}

Expand Down Expand Up @@ -311,15 +314,19 @@ func (a *ExecuteTaskTable) setData(pipeline *apistructs.PipelineDetailDTO) error
"renderType": "tableOperation",
"operations": map[string]interface{}{
"checkDetail": dataOperation{
Key: "checkDetail",
Text: "查看结果",
Reload: false,
Meta: task.Result,
Key: "checkDetail",
Text: "查看结果",
Reload: false,
DisabledTip: "禁用接口无法查看结果",
Disabled: task.Status.IsDisabledStatus(),
Meta: task.Result,
},
"checkLog": dataOperation{
Key: "checkLog",
Reload: false,
Text: "日志",
Key: "checkLog",
Reload: false,
Text: "日志",
DisabledTip: "禁用接口无法查看日志",
Disabled: task.Status.IsDisabledStatus(),
Meta: map[string]interface{}{
"logId": task.Extra.UUID,
"pipelineId": a.State.PipelineID,
Expand Down Expand Up @@ -379,15 +386,19 @@ func (a *ExecuteTaskTable) setData(pipeline *apistructs.PipelineDetailDTO) error
if res.Type == apistructs.StepTypeAPI || res.Type == apistructs.StepTypeWait || res.Type == apistructs.StepTypeCustomScript {
operations = map[string]interface{}{
"checkDetail": dataOperation{
Key: "checkDetail",
Text: "查看结果",
Reload: false,
Meta: task.Result,
Key: "checkDetail",
Text: "查看结果",
Reload: false,
Disabled: task.Status.IsDisabledStatus(),
DisabledTip: "禁用接口无法查看结果",
Meta: task.Result,
},
"checkLog": dataOperation{
Key: "checkLog",
Reload: false,
Text: "日志",
Key: "checkLog",
Reload: false,
Text: "日志",
Disabled: task.Status.IsDisabledStatus(),
DisabledTip: "禁用接口无法查看日志",
Meta: map[string]interface{}{
"logId": task.Extra.UUID,
"pipelineId": a.State.PipelineID,
Expand Down
Expand Up @@ -160,7 +160,6 @@ func (i *ComponentFileInfo) Render(ctx context.Context, c *apistructs.Component,
if err != nil {
return err
}
fmt.Println(res)
if res != nil && len(res.Reports) > 0 && res.Reports[0].Meta != nil {
value, err := json.Marshal(res.Reports[0].Meta)
if err != nil {
Expand Down
Expand Up @@ -312,10 +312,12 @@ func (a *ExecuteTaskTable) setData(pipeline *apistructs.PipelineDetailDTO) error
if task.Type != apistructs.ActionTypeSnippet {
operations = map[string]interface{}{
"checkDetail": dataOperation{
Key: "checkDetail",
Text: "查看结果",
Reload: false,
Meta: task.Result,
Key: "checkDetail",
Text: "查看结果",
Reload: false,
Meta: task.Result,
DisabledTip: "禁用接口无法查看结果",
Disabled: task.Status.IsDisabledStatus(),
},
"checkLog": dataOperation{
Key: "checkLog",
Expand All @@ -326,6 +328,8 @@ func (a *ExecuteTaskTable) setData(pipeline *apistructs.PipelineDetailDTO) error
"pipelineId": a.State.PipelineID,
"nodeId": task.ID,
},
DisabledTip: "禁用接口无法查看日志",
Disabled: task.Status.IsDisabledStatus(),
},
}
taskNum = "-"
Expand Down Expand Up @@ -386,10 +390,12 @@ func (a *ExecuteTaskTable) setData(pipeline *apistructs.PipelineDetailDTO) error
if res.Type == apistructs.StepTypeAPI || res.Type == apistructs.StepTypeWait || res.Type == apistructs.StepTypeCustomScript {
operations = map[string]interface{}{
"checkDetail": dataOperation{
Key: "checkDetail",
Text: "查看结果",
Reload: false,
Meta: task.Result,
Key: "checkDetail",
Text: "查看结果",
Reload: false,
Meta: task.Result,
DisabledTip: "禁用接口无法查看结果",
Disabled: task.Status.IsDisabledStatus(),
},
"checkLog": dataOperation{
Key: "checkLog",
Expand All @@ -400,6 +406,8 @@ func (a *ExecuteTaskTable) setData(pipeline *apistructs.PipelineDetailDTO) error
"pipelineId": a.State.PipelineID,
"nodeId": task.ID,
},
DisabledTip: "禁用接口无法查看日志",
Disabled: task.Status.IsDisabledStatus(),
},
}
}
Expand Down
Expand Up @@ -45,6 +45,7 @@ type StageData struct {
Title string `json:"title"`
ID uint64 `json:"id"`
GroupID int64 `json:"groupId"`
Disabled bool `json:"disabled"`
Operations map[string]interface{} `json:"operations"`
}

Expand Down Expand Up @@ -88,6 +89,7 @@ type OperationBaseInfo struct {
Reload bool `json:"reload"`
Disabled bool `json:"disabled"`
DisabledTip string `json:"disabledTip"`
SuccessMsg string `json:"successMsg"`
}

type OpMetaData struct {
Expand All @@ -97,6 +99,7 @@ type OpMetaData struct {
Name string `json:"name"` // 名称
APISpecID uint64 `json:"apiSpecID"` // api集市id
ID uint64 `json:"id"`
Disable bool `json:"disable"`
}

type OpMetaInfo struct {
Expand Down
Expand Up @@ -211,6 +211,15 @@ func (i *ComponentStageForm) Render(ctx context.Context, c *apistructs.Component
if err != nil {
return err
}
case apistructs.AutoTestSceneStepSwitchOperationKey:
err = i.RenderDisableStagesForm(event.OperationData)
if err != nil {
return err
}
err = i.RenderListStageForm()
if err != nil {
return err
}
case "clickItem":
data, err := GetOpsInfo(event.OperationData)
if err != nil {
Expand Down

0 comments on commit 16f0862

Please sign in to comment.