@@ -684,32 +684,47 @@ func EnableWorkflowFile(ctx *context_module.Context) {
684
684
}
685
685
686
686
func disableOrEnableWorkflowFile (ctx * context_module.Context , isEnable bool ) {
687
+ disableOrEnable (ctx , isEnable , false )
688
+ }
689
+
690
+ func disableOrEnable (ctx * context_module.Context , isEnable bool , isglobal bool ){
687
691
workflow := ctx .FormString ("workflow" )
688
692
if len (workflow ) == 0 {
689
693
ctx .ServerError ("workflow" , nil )
690
694
return
691
695
}
692
-
693
696
cfgUnit := ctx .Repo .Repository .MustGetUnit (ctx , unit .TypeActions )
694
697
cfg := cfgUnit .ActionsConfig ()
695
-
696
- if isEnable {
697
- cfg .EnableWorkflow (workflow )
698
- } else {
699
- cfg .DisableWorkflow (workflow )
700
- }
701
-
698
+ if isglobal {
699
+ if isEnable {
700
+ cfg .DisableGlobalWorkflow (workflow )
701
+ } else {
702
+ cfg .EnableGlobalWorkflow (workflow )
703
+ }
704
+ } else {
705
+ if isEnable {
706
+ cfg .EnableWorkflow (workflow )
707
+ } else {
708
+ cfg .DisableWorkflow (workflow )
709
+ }
710
+ }
702
711
if err := repo_model .UpdateRepoUnit (ctx , cfgUnit ); err != nil {
703
712
ctx .ServerError ("UpdateRepoUnit" , err )
704
713
return
705
714
}
706
-
707
- if isEnable {
708
- ctx .Flash .Success (ctx .Tr ("actions.workflow.enable_success" , workflow ))
709
- } else {
710
- ctx .Flash .Success (ctx .Tr ("actions.workflow.disable_success" , workflow ))
711
- }
712
-
715
+ if isglobal {
716
+ if isEnable {
717
+ ctx .Flash .Success (ctx .Tr ("actions.workflow.global_disable_success" , workflow ))
718
+ } else {
719
+ ctx .Flash .Success (ctx .Tr ("actions.workflow.global_enable_success" , workflow ))
720
+ }
721
+ } else {
722
+ if isEnable {
723
+ ctx .Flash .Success (ctx .Tr ("actions.workflow.enable_success" , workflow ))
724
+ } else {
725
+ ctx .Flash .Success (ctx .Tr ("actions.workflow.disable_success" , workflow ))
726
+ }
727
+ }
713
728
redirectURL := fmt .Sprintf ("%s/actions?workflow=%s&actor=%s&status=%s" , ctx .Repo .RepoLink , url .QueryEscape (workflow ),
714
729
url .QueryEscape (ctx .FormString ("actor" )), url .QueryEscape (ctx .FormString ("status" )))
715
730
ctx .JSONRedirect (redirectURL )
@@ -723,29 +738,6 @@ func EnableGlobalWorkflowFile(ctx *context_module.Context) {
723
738
disableOrEnableGlobalWorkflowFile (ctx , false )
724
739
}
725
740
726
- func disableOrEnableGlobalWorkflowFile (ctx * context_module.Context , isGlobalEnable bool ) {
727
- workflow := ctx .FormString ("workflow" )
728
- if len (workflow ) == 0 {
729
- ctx .ServerError ("workflow" , nil )
730
- return
731
- }
732
- cfgUnit := ctx .Repo .Repository .MustGetUnit (ctx , unit .TypeActions )
733
- cfg := cfgUnit .ActionsConfig ()
734
- if isGlobalEnable {
735
- cfg .DisableGlobalWorkflow (workflow )
736
- } else {
737
- cfg .EnableGlobalWorkflow (workflow )
738
- }
739
- if err := repo_model .UpdateRepoUnit (ctx , cfgUnit ); err != nil {
740
- ctx .ServerError ("UpdateRepoUnit" , err )
741
- return
742
- }
743
- if isGlobalEnable {
744
- ctx .Flash .Success (ctx .Tr ("actions.workflow.global_disable_success" , workflow ))
745
- } else {
746
- ctx .Flash .Success (ctx .Tr ("actions.workflow.global_enable_success" , workflow ))
747
- }
748
- redirectURL := fmt .Sprintf ("%s/actions?workflow=%s&actor=%s&status=%s" , ctx .Repo .RepoLink , url .QueryEscape (workflow ),
749
- url .QueryEscape (ctx .FormString ("actor" )), url .QueryEscape (ctx .FormString ("status" )))
750
- ctx .JSONRedirect (redirectURL )
741
+ func disableOrEnableGlobalWorkflowFile (ctx * context_module.Context , isEnable bool ) {
742
+ disableOrEnable (ctx , isEnable , true )
751
743
}
0 commit comments