@@ -78,11 +78,11 @@ func List(ctx *context.Context) {
7878		return 
7979	}
8080
81- 	workflows  :=  prepareWorkflowTemplate (ctx , commit )
81+ 	workflows ,  curWorkflowID  :=  prepareWorkflowTemplate (ctx , commit )
8282	if  ctx .Written () {
8383		return 
8484	}
85- 	prepareWorkflowDispatchTemplate (ctx , workflows )
85+ 	prepareWorkflowDispatchTemplate (ctx , workflows ,  curWorkflowID )
8686	if  ctx .Written () {
8787		return 
8888	}
@@ -117,25 +117,24 @@ func WorkflowDispatchInputs(ctx *context.Context) {
117117		ctx .ServerError ("GetTagCommit/GetBranchCommit" , err )
118118		return 
119119	}
120- 	workflows  :=  prepareWorkflowTemplate (ctx , commit )
120+ 	workflows ,  curWorkflowID  :=  prepareWorkflowTemplate (ctx , commit )
121121	if  ctx .Written () {
122122		return 
123123	}
124- 	prepareWorkflowDispatchTemplate (ctx , workflows )
124+ 	prepareWorkflowDispatchTemplate (ctx , workflows ,  curWorkflowID )
125125	if  ctx .Written () {
126126		return 
127127	}
128128	ctx .HTML (http .StatusOK , tplDispatchInputsActions )
129129}
130130
131- func  prepareWorkflowTemplate (ctx  * context.Context , commit  * git.Commit ) (workflows  []WorkflowInfo ) {
132- 	workflowID  :=  ctx .FormString ("workflow" )
133- 	ctx .Data ["CurWorkflow" ] =  workflowID 
131+ func  prepareWorkflowTemplate (ctx  * context.Context , commit  * git.Commit ) (workflows  []WorkflowInfo , curWorkflowID  string ) {
132+ 	curWorkflowID  =  ctx .FormString ("workflow" )
134133
135134	_ , entries , err  :=  actions .ListWorkflows (commit )
136135	if  err  !=  nil  {
137136		ctx .ServerError ("ListWorkflows" , err )
138- 		return  nil 
137+ 		return  nil ,  "" 
139138	}
140139
141140	workflows  =  make ([]WorkflowInfo , 0 , len (entries ))
@@ -144,7 +143,7 @@ func prepareWorkflowTemplate(ctx *context.Context, commit *git.Commit) (workflow
144143		content , err  :=  actions .GetContentFromEntry (entry )
145144		if  err  !=  nil  {
146145			ctx .ServerError ("GetContentFromEntry" , err )
147- 			return  nil 
146+ 			return  nil ,  "" 
148147		}
149148		wf , err  :=  act_model .ReadWorkflow (bytes .NewReader (content ))
150149		if  err  !=  nil  {
@@ -180,31 +179,26 @@ func prepareWorkflowTemplate(ctx *context.Context, commit *git.Commit) (workflow
180179	ctx .Data ["AllowDisableOrEnableWorkflow" ] =  ctx .Repo .IsAdmin ()
181180	actionsConfig  :=  ctx .Repo .Repository .MustGetUnit (ctx , unit .TypeActions ).ActionsConfig ()
182181	ctx .Data ["ActionsConfig" ] =  actionsConfig 
182+ 	ctx .Data ["CurWorkflow" ] =  curWorkflowID 
183+ 	ctx .Data ["CurWorkflowDisabled" ] =  actionsConfig .IsWorkflowDisabled (curWorkflowID )
183184
184- 	if  len (workflowID ) >  0  {
185- 		ctx .Data ["CurWorkflowDisabled" ] =  actionsConfig .IsWorkflowDisabled (workflowID )
186- 	}
187- 
188- 	return  workflows 
185+ 	return  workflows , curWorkflowID 
189186}
190187
191- func  prepareWorkflowDispatchTemplate (ctx  * context.Context , workflowInfos  []WorkflowInfo ) {
192- 	workflowID  :=  ctx .FormString ("workflow" )
188+ func  prepareWorkflowDispatchTemplate (ctx  * context.Context , workflowInfos  []WorkflowInfo , curWorkflowID  string ) {
193189	actionsConfig  :=  ctx .Repo .Repository .MustGetUnit (ctx , unit .TypeActions ).ActionsConfig ()
194- 	if  len ( workflowID )  ==  0  ||  ! ctx .Repo .CanWrite (unit .TypeActions ) ||  actionsConfig .IsWorkflowDisabled (workflowID ) {
190+ 	if  curWorkflowID  ==  ""  ||  ! ctx .Repo .CanWrite (unit .TypeActions ) ||  actionsConfig .IsWorkflowDisabled (curWorkflowID ) {
195191		return 
196192	}
197193
198- 	ctx .Data ["CurWorkflowExists" ] =  false 
199194	var  curWorkflow  * act_model.Workflow 
200195	for  _ , workflowInfo  :=  range  workflowInfos  {
201- 		if  workflowInfo .Entry .Name () ==  workflowID  {
196+ 		if  workflowInfo .Entry .Name () ==  curWorkflowID  {
202197			if  workflowInfo .Workflow  ==  nil  {
203- 				log .Error ( " %s workflowInfo.Workflow is nil"workflowID )
198+ 				log .Debug ( "CurWorkflowID  %s is found but its  workflowInfo.Workflow is nil"curWorkflowID )
204199				return 
205200			}
206201			curWorkflow  =  workflowInfo .Workflow 
207- 			ctx .Data ["CurWorkflowExists" ] =  true 
208202			break 
209203		}
210204	}
@@ -213,12 +207,13 @@ func prepareWorkflowDispatchTemplate(ctx *context.Context, workflowInfos []Workf
213207		return 
214208	}
215209
216- 	workflowDispatchConfig  :=  workflowDispatchConfig (curWorkflow )
217- 	if  workflowDispatchConfig  ==  nil  {
210+ 	ctx .Data ["CurWorkflowExists" ] =  true 
211+ 	curWfDispatchCfg  :=  workflowDispatchConfig (curWorkflow )
212+ 	if  curWfDispatchCfg  ==  nil  {
218213		return 
219214	}
220215
221- 	ctx .Data ["WorkflowDispatchConfig" ] =  workflowDispatchConfig 
216+ 	ctx .Data ["WorkflowDispatchConfig" ] =  curWfDispatchCfg 
222217
223218	branchOpts  :=  git_model.FindBranchOptions {
224219		RepoID :          ctx .Repo .Repository .ID ,
0 commit comments