@@ -803,7 +803,7 @@ func SkipReleaseJob(c *handler.Context, planID string, args *SkipReleaseJobArgs,
803803 return nil
804804}
805805
806- func UpdateReleasePlanStatus (c * handler.Context , planID , status string , isSystemAdmin bool ) error {
806+ func UpdateReleasePlanStatus (c * handler.Context , planID , targetStatus string , isSystemAdmin bool ) error {
807807 approveLock := getLock (planID )
808808 approveLock .Lock ()
809809 defer approveLock .Unlock ()
@@ -815,12 +815,16 @@ func UpdateReleasePlanStatus(c *handler.Context, planID, status string, isSystem
815815 return errors .Wrap (err , "get plan" )
816816 }
817817
818+ if plan .Status == config .ReleasePlanStatus (targetStatus ) {
819+ return fmt .Errorf ("current status can not equal to target status %s" , targetStatus )
820+ }
821+
818822 if c .UserID != plan .ManagerID && ! isSystemAdmin {
819823 return errors .Errorf ("only manager can update plan status" )
820824 }
821825
822- if ! lo .Contains (config .ReleasePlanStatusMap [plan .Status ], config .ReleasePlanStatus (status )) {
823- return errors .Errorf ("can't convert plan status %s to %s" , plan .Status , status )
826+ if ! lo .Contains (config .ReleasePlanStatusMap [plan .Status ], config .ReleasePlanStatus (targetStatus )) {
827+ return errors .Errorf ("can't convert plan status %s to %s" , plan .Status , targetStatus )
824828 }
825829
826830 userInfo , err := user .New ().GetUserByID (c .UserID )
@@ -846,11 +850,20 @@ func UpdateReleasePlanStatus(c *handler.Context, planID, status string, isSystem
846850 return errors .Errorf ("plan must not have no jobs" )
847851 }
848852 plan .PlanningTime = time .Now ().Unix ()
853+ case config .ReleasePlanStatusWaitForApproveExternalCheck ,
854+ config .ReleasePlanStatusWaitForApproveExternalCheckFailed ,
855+ config .ReleasePlanStatusWaitForExecuteExternalCheck ,
856+ config .ReleasePlanStatusWaitForExecuteExternalCheckFailed ,
857+ config .ReleasePlanStatusWaitForAllDoneExternalCheck ,
858+ config .ReleasePlanStatusWaitForAllDoneExternalCheckFailed :
859+ if config .ReleasePlanStatus (targetStatus ) != config .ReleasePlanStatusPlanning && config .ReleasePlanStatus (targetStatus ) != config .ReleasePlanStatusCancel {
860+ return fmt .Errorf ("can't update status, current status: %s" , plan .Status )
861+ }
849862 }
850- plan .Status = config .ReleasePlanStatus (status )
863+ plan .Status = config .ReleasePlanStatus (targetStatus )
851864
852865 // target status check and update
853- switch config .ReleasePlanStatus (status ) {
866+ switch config .ReleasePlanStatus (targetStatus ) {
854867 case config .ReleasePlanStatusPlanning :
855868 for _ , job := range plan .Jobs {
856869 job .LastStatus = job .Status
@@ -861,6 +874,9 @@ func UpdateReleasePlanStatus(c *handler.Context, planID, status string, isSystem
861874 plan .HookSettings = hookSetting .ToHookSettings ()
862875
863876 plan .PlanningTime = time .Now ().Unix ()
877+ plan .ApprovalTime = 0
878+ plan .ExecutingTime = 0
879+ plan .SuccessTime = 0
864880 plan .WaitForApproveExternalCheckTime = 0
865881 plan .WaitForExecuteExternalCheckTime = 0
866882 plan .WaitForAllDoneExternalCheckTime = 0
@@ -924,7 +940,7 @@ func UpdateReleasePlanStatus(c *handler.Context, planID, status string, isSystem
924940 TargetType : TargetTypeReleasePlanStatus ,
925941 Detail : detail ,
926942 Before : plan .Status ,
927- After : status ,
943+ After : targetStatus ,
928944 CreatedAt : time .Now ().Unix (),
929945 }); err != nil {
930946 log .Errorf ("create release plan log error: %v" , err )
@@ -1599,6 +1615,10 @@ func convertWorkflowV4ToOpenAPIWorkflowV4(workflow *commonmodels.WorkflowV4) (*w
15991615
16001616 hookSpec := interface {}(nil )
16011617 for _ , job := range stage .Jobs {
1618+ if job .Skipped {
1619+ continue
1620+ }
1621+
16021622 switch job .JobType {
16031623 case config .JobZadigBuild :
16041624 spec := new (commonmodels.ZadigBuildJobSpec )
@@ -1934,7 +1954,9 @@ func convertWorkflowV4ToOpenAPIWorkflowV4(workflow *commonmodels.WorkflowV4) (*w
19341954 })
19351955 }
19361956
1937- hookStages = append (hookStages , hookStage )
1957+ if len (hookStage .Jobs ) != 0 {
1958+ hookStages = append (hookStages , hookStage )
1959+ }
19381960 }
19391961
19401962 return & webhooknotify.OpenAPIWorkflowV4 {
0 commit comments