Skip to content

Commit 0312d2f

Browse files
feat: expose workflow task release plan metadata (#4663)
Signed-off-by: huanghongbo <huanghongbo@koderover.com>
1 parent 7345e97 commit 0312d2f

5 files changed

Lines changed: 39 additions & 19 deletions

File tree

pkg/microservice/aslan/core/common/repository/models/wokflow_task_v4.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ type WorkflowTask struct {
6666
Hash string `bson:"hash" json:"hash"`
6767
ApprovalTicketID string `bson:"approval_ticket_id" json:"approval_ticket_id"`
6868
ApprovalID string `bson:"approval_id" json:"approval_id"`
69+
ReleasePlan *ReleasePlanRef `bson:"release_plan,omitempty" json:"release_plan,omitempty"`
6970

7071
LarkProjectKey string `bson:"lark_project_key" json:"lark_project_key"`
7172
LarkProjectSimpleName string `bson:"lark_project_simple_name" json:"lark_project_simple_name"`
@@ -160,6 +161,13 @@ type WorkflowTaskPreview struct {
160161
LarkWorkItemAPIName string `bson:"lark_workitem_api_name" json:"lark_workitem_api_name"`
161162
LarkWorkItemID string `bson:"lark_workitem_id" json:"lark_workitem_id"`
162163
Hash string `bson:"hash" json:"hash"`
164+
ReleasePlan *ReleasePlanRef `bson:"release_plan,omitempty" json:"release_plan,omitempty"`
165+
}
166+
167+
type ReleasePlanRef struct {
168+
ID string `bson:"id" json:"id"`
169+
Name string `bson:"name" json:"name"`
170+
Index int64 `bson:"index" json:"index"`
163171
}
164172

165173
type StagePreview struct {

pkg/microservice/aslan/core/common/repository/models/workflow_v4.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,6 +1749,7 @@ type CustomField struct {
17491749
Executor int `bson:"executor" json:"executor"`
17501750
Remark int `bson:"remark" json:"remark"`
17511751
Branch int `bson:"branch" json:"branch"`
1752+
ReleasePlan int `bson:"release_plan" json:"release_plan"`
17521753
LarkWorkItemLink int `bson:"lark_work_item_link" json:"lark_work_item_link"`
17531754
BuildServiceComponent map[string]int `bson:"build_service_component,omitempty" json:"build_service_component,omitempty"`
17541755
BuildCodeMsg map[string]int `bson:"build_code_msg,omitempty" json:"build_code_msg,omitempty"`

pkg/microservice/aslan/core/release_plan/service/execute.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,11 @@ func (e *WorkflowReleaseJobExecutor) Execute(plan *models.ReleasePlan) error {
157157
Name: ctx.UserName,
158158
Account: ctx.Account,
159159
UserID: ctx.UserID,
160+
ReleasePlan: &models.ReleasePlanRef{
161+
ID: plan.ID.Hex(),
162+
Name: plan.Name,
163+
Index: plan.Index,
164+
},
160165
}, workflowController.WorkflowV4, log.SugaredLogger().With("source", "release plan"))
161166
if err != nil {
162167
return errors.Wrapf(err, "failed to create workflow task %s", spec.Workflow.Name)

pkg/microservice/aslan/core/workflow/service/workflow/workflow_task_v4.go

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -83,25 +83,26 @@ type CreateTaskV4Resp struct {
8383
}
8484

8585
type WorkflowTaskPreview struct {
86-
TaskID int64 `bson:"task_id" json:"task_id"`
87-
WorkflowName string `bson:"workflow_name" json:"workflow_key"`
88-
WorkflowDisplayName string `bson:"workflow_display_name" json:"workflow_name"`
89-
Params []*commonmodels.Param `bson:"params" json:"params"`
90-
Status config.Status `bson:"status" json:"status,omitempty"`
91-
Reverted bool `bson:"reverted" json:"reverted"`
92-
Remark string `bson:"remark" json:"remark"`
93-
TaskCreator string `bson:"task_creator" json:"task_creator,omitempty"`
94-
TaskRevoker string `bson:"task_revoker,omitempty" json:"task_revoker,omitempty"`
95-
CreateTime int64 `bson:"create_time" json:"create_time,omitempty"`
96-
StartTime int64 `bson:"start_time" json:"start_time,omitempty"`
97-
EndTime int64 `bson:"end_time" json:"end_time,omitempty"`
98-
Stages []*StageTaskPreview `bson:"stages" json:"stages"`
99-
ProjectName string `bson:"project_name" json:"project_key"`
100-
Error string `bson:"error,omitempty" json:"error,omitempty"`
101-
IsRestart bool `bson:"is_restart" json:"is_restart"`
102-
Debug bool `bson:"debug" json:"debug"`
103-
ApprovalTicketID string `bson:"approval_ticket_id" json:"approval_ticket_id"`
104-
ApprovalID string `bson:"approval_id" json:"approval_id"`
86+
TaskID int64 `bson:"task_id" json:"task_id"`
87+
WorkflowName string `bson:"workflow_name" json:"workflow_key"`
88+
WorkflowDisplayName string `bson:"workflow_display_name" json:"workflow_name"`
89+
Params []*commonmodels.Param `bson:"params" json:"params"`
90+
Status config.Status `bson:"status" json:"status,omitempty"`
91+
Reverted bool `bson:"reverted" json:"reverted"`
92+
Remark string `bson:"remark" json:"remark"`
93+
TaskCreator string `bson:"task_creator" json:"task_creator,omitempty"`
94+
TaskRevoker string `bson:"task_revoker,omitempty" json:"task_revoker,omitempty"`
95+
CreateTime int64 `bson:"create_time" json:"create_time,omitempty"`
96+
StartTime int64 `bson:"start_time" json:"start_time,omitempty"`
97+
EndTime int64 `bson:"end_time" json:"end_time,omitempty"`
98+
Stages []*StageTaskPreview `bson:"stages" json:"stages"`
99+
ProjectName string `bson:"project_name" json:"project_key"`
100+
Error string `bson:"error,omitempty" json:"error,omitempty"`
101+
IsRestart bool `bson:"is_restart" json:"is_restart"`
102+
Debug bool `bson:"debug" json:"debug"`
103+
ApprovalTicketID string `bson:"approval_ticket_id" json:"approval_ticket_id"`
104+
ApprovalID string `bson:"approval_id" json:"approval_id"`
105+
ReleasePlan *commonmodels.ReleasePlanRef `bson:"release_plan,omitempty" json:"release_plan,omitempty"`
105106
}
106107

107108
type StageTaskPreview struct {
@@ -457,6 +458,7 @@ type CreateWorkflowTaskV4Args struct {
457458
LarkWorkItemTypeKey string
458459
LarkWorkItemAPIName string
459460
LarkWorkItemID string
461+
ReleasePlan *commonmodels.ReleasePlanRef
460462
}
461463

462464
func CreateWorkflowTaskV4ByBuildInTrigger(triggerName string, args *commonmodels.WorkflowV4, log *zap.SugaredLogger) (*CreateTaskV4Resp, error) {
@@ -614,6 +616,7 @@ func CreateWorkflowTaskV4(args *CreateWorkflowTaskV4Args, workflow *commonmodels
614616
workflowTask.LarkProjectKey = args.LarkProjectKey
615617
workflowTask.LarkProjectSimpleName = args.LarkProjectSimpleName
616618
workflowTask.LarkWorkItemAPIName = args.LarkWorkItemAPIName
619+
workflowTask.ReleasePlan = args.ReleasePlan
617620

618621
workflowCtrl := workflowController.CreateWorkflowController(workflow)
619622
if (args.Type == config.WorkflowTaskTypeWorkflow || args.Type == "") && !args.SkipWorkflowUpdate {
@@ -2183,6 +2186,7 @@ func ListWorkflowTaskV4ByFilter(filter *TaskHistoryFilter, filterList []string,
21832186
LarkWorkItemAPIName: task.LarkWorkItemAPIName,
21842187
LarkWorkItemID: task.LarkWorkItemID,
21852188
Hash: task.Hash,
2189+
ReleasePlan: task.ReleasePlan,
21862190
}
21872191

21882192
stagePreviews := make([]*commonmodels.StagePreview, 0)
@@ -2382,6 +2386,7 @@ func GetWorkflowTaskV4(workflowName string, taskID int64, logger *zap.SugaredLog
23822386
Debug: task.IsDebug,
23832387
ApprovalTicketID: task.ApprovalTicketID,
23842388
ApprovalID: task.ApprovalID,
2389+
ReleasePlan: task.ReleasePlan,
23852390
}
23862391
timeNow := time.Now().Unix()
23872392
for _, stage := range task.Stages {

pkg/microservice/aslan/core/workflow/service/workflow/workflow_v4.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ func GetWorkflowTasksCustomFields(projectName, workflowName string, logger *zap.
152152
Executor: 1,
153153
Remark: 0,
154154
Branch: 0,
155+
ReleasePlan: 0,
155156
BuildServiceComponent: make(map[string]int),
156157
BuildCodeMsg: make(map[string]int),
157158
DeployServiceComponent: make(map[string]int),

0 commit comments

Comments
 (0)