@@ -684,32 +684,47 @@ func EnableWorkflowFile(ctx *context_module.Context) {
684684}
685685
686686func 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 ){
687691 workflow := ctx .FormString ("workflow" )
688692 if len (workflow ) == 0 {
689693 ctx .ServerError ("workflow" , nil )
690694 return
691695 }
692-
693696 cfgUnit := ctx .Repo .Repository .MustGetUnit (ctx , unit .TypeActions )
694697 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+ }
702711 if err := repo_model .UpdateRepoUnit (ctx , cfgUnit ); err != nil {
703712 ctx .ServerError ("UpdateRepoUnit" , err )
704713 return
705714 }
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+ }
713728 redirectURL := fmt .Sprintf ("%s/actions?workflow=%s&actor=%s&status=%s" , ctx .Repo .RepoLink , url .QueryEscape (workflow ),
714729 url .QueryEscape (ctx .FormString ("actor" )), url .QueryEscape (ctx .FormString ("status" )))
715730 ctx .JSONRedirect (redirectURL )
@@ -723,29 +738,6 @@ func EnableGlobalWorkflowFile(ctx *context_module.Context) {
723738 disableOrEnableGlobalWorkflowFile (ctx , false )
724739}
725740
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 )
751743}
0 commit comments