Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ type DeployHelmChart struct {
type DeployBasicInfo struct {
ServiceName string `bson:"service_name" yaml:"service_name" json:"service_name"`
Modules []*DeployModuleInfo `bson:"modules" yaml:"modules" json:"modules"`
Deployed bool `bson:"-" yaml:"deployed" json:"deployed"`
Deployed bool `bson:"deployed" yaml:"deployed" json:"deployed"`
AutoSync bool `bson:"-" yaml:"auto_sync" json:"auto_sync"`
UpdateConfig bool `bson:"update_config" yaml:"update_config" json:"update_config"`
Updatable bool `bson:"-" yaml:"updatable" json:"updatable"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ package service

import (
"fmt"
"github.com/koderover/zadig/v2/pkg/microservice/aslan/core/workflow/service/workflow/controller"
"time"

"github.com/pkg/errors"

"github.com/koderover/zadig/v2/pkg/microservice/aslan/config"
"github.com/koderover/zadig/v2/pkg/microservice/aslan/core/common/repository/models"
"github.com/koderover/zadig/v2/pkg/microservice/aslan/core/workflow/service/workflow"
"github.com/koderover/zadig/v2/pkg/microservice/aslan/core/workflow/service/workflow/controller"
"github.com/koderover/zadig/v2/pkg/shared/client/user"
"github.com/koderover/zadig/v2/pkg/tool/log"
)
Expand Down
36 changes: 29 additions & 7 deletions pkg/microservice/aslan/core/release_plan/service/release_plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -778,7 +778,7 @@ func SkipReleaseJob(c *handler.Context, planID string, args *SkipReleaseJobArgs,
return nil
}

func UpdateReleasePlanStatus(c *handler.Context, planID, status string, isSystemAdmin bool) error {
func UpdateReleasePlanStatus(c *handler.Context, planID, targetStatus string, isSystemAdmin bool) error {
approveLock := getLock(planID)
approveLock.Lock()
defer approveLock.Unlock()
Expand All @@ -790,12 +790,16 @@ func UpdateReleasePlanStatus(c *handler.Context, planID, status string, isSystem
return errors.Wrap(err, "get plan")
}

if plan.Status == config.ReleasePlanStatus(targetStatus) {
return fmt.Errorf("current status can not equal to target status %s", targetStatus)
}

if c.UserID != plan.ManagerID && !isSystemAdmin {
return errors.Errorf("only manager can update plan status")
}

if !lo.Contains(config.ReleasePlanStatusMap[plan.Status], config.ReleasePlanStatus(status)) {
return errors.Errorf("can't convert plan status %s to %s", plan.Status, status)
if !lo.Contains(config.ReleasePlanStatusMap[plan.Status], config.ReleasePlanStatus(targetStatus)) {
return errors.Errorf("can't convert plan status %s to %s", plan.Status, targetStatus)
}

userInfo, err := user.New().GetUserByID(c.UserID)
Expand All @@ -821,11 +825,20 @@ func UpdateReleasePlanStatus(c *handler.Context, planID, status string, isSystem
return errors.Errorf("plan must not have no jobs")
}
plan.PlanningTime = time.Now().Unix()
case config.ReleasePlanStatusWaitForApproveExternalCheck,
config.ReleasePlanStatusWaitForApproveExternalCheckFailed,
config.ReleasePlanStatusWaitForExecuteExternalCheck,
config.ReleasePlanStatusWaitForExecuteExternalCheckFailed,
config.ReleasePlanStatusWaitForAllDoneExternalCheck,
config.ReleasePlanStatusWaitForAllDoneExternalCheckFailed:
if config.ReleasePlanStatus(targetStatus) != config.ReleasePlanStatusPlanning {
return fmt.Errorf("can't update status, current status: %s", plan.Status)
}
}
plan.Status = config.ReleasePlanStatus(status)
plan.Status = config.ReleasePlanStatus(targetStatus)

// target status check and update
switch config.ReleasePlanStatus(status) {
switch config.ReleasePlanStatus(targetStatus) {
case config.ReleasePlanStatusPlanning:
for _, job := range plan.Jobs {
job.LastStatus = job.Status
Expand All @@ -836,6 +849,9 @@ func UpdateReleasePlanStatus(c *handler.Context, planID, status string, isSystem
plan.HookSettings = hookSetting.ToHookSettings()

plan.PlanningTime = time.Now().Unix()
plan.ApprovalTime = 0
plan.ExecutingTime = 0
plan.SuccessTime = 0
plan.WaitForApproveExternalCheckTime = 0
plan.WaitForExecuteExternalCheckTime = 0
plan.WaitForAllDoneExternalCheckTime = 0
Expand Down Expand Up @@ -899,7 +915,7 @@ func UpdateReleasePlanStatus(c *handler.Context, planID, status string, isSystem
TargetType: TargetTypeReleasePlanStatus,
Detail: detail,
Before: plan.Status,
After: status,
After: targetStatus,
CreatedAt: time.Now().Unix(),
}); err != nil {
log.Errorf("create release plan log error: %v", err)
Expand Down Expand Up @@ -1574,6 +1590,10 @@ func convertWorkflowV4ToOpenAPIWorkflowV4(workflow *commonmodels.WorkflowV4) (*w

hookSpec := interface{}(nil)
for _, job := range stage.Jobs {
if job.Skipped {
continue
}

switch job.JobType {
case config.JobZadigBuild:
spec := new(commonmodels.ZadigBuildJobSpec)
Expand Down Expand Up @@ -1909,7 +1929,9 @@ func convertWorkflowV4ToOpenAPIWorkflowV4(workflow *commonmodels.WorkflowV4) (*w
})
}

hookStages = append(hookStages, hookStage)
if len(hookStage.Jobs) != 0 {
hookStages = append(hookStages, hookStage)
}
}

return &webhooknotify.OpenAPIWorkflowV4{
Expand Down