@@ -149,16 +149,16 @@ func VariableUpdate(ctx *context.Context) {
149149
150150 id := ctx .PathParamInt64 ("variable_id" )
151151
152- variable , ok := findVariable (ctx , id , vCtx )
153- if ! ok {
152+ variable := findActionsVariable (ctx , id , vCtx )
153+ if ctx . Written () {
154154 return
155155 }
156156
157157 form := web .GetForm (ctx ).(* forms.EditVariableForm )
158158 variable .Name = form .Name
159159 variable .Data = form .Data
160160
161- if ok , err := actions_service .UpdateVariable (ctx , variable ); err != nil || ! ok {
161+ if ok , err := actions_service .UpdateVariableNameData (ctx , variable ); err != nil || ! ok {
162162 log .Error ("UpdateVariable: %v" , err )
163163 ctx .JSONError (ctx .Tr ("actions.variables.update.failed" ))
164164 return
@@ -167,31 +167,36 @@ func VariableUpdate(ctx *context.Context) {
167167 ctx .JSONRedirect (vCtx .RedirectLink )
168168}
169169
170- func findVariable (ctx * context.Context , id int64 , vCtx * variablesCtx ) ( * actions_model.ActionVariable , bool ) {
170+ func findActionsVariable (ctx * context.Context , id int64 , vCtx * variablesCtx ) * actions_model.ActionVariable {
171171 opts := actions_model.FindVariablesOpts {
172172 IDs : []int64 {id },
173173 }
174174 switch {
175175 case vCtx .IsRepo :
176176 opts .RepoID = vCtx .RepoID
177+ if opts .RepoID == 0 {
178+ panic ("RepoID is 0" )
179+ }
177180 case vCtx .IsOrg , vCtx .IsUser :
178181 opts .OwnerID = vCtx .OwnerID
182+ if opts .OwnerID == 0 {
183+ panic ("OwnerID is 0" )
184+ }
179185 case vCtx .IsGlobal :
180186 // do nothing
181187 default :
182- ctx .ServerError ("findVariable" , errors .New ("unable to determine" ))
183- return nil , false
188+ panic ("invalid actions variable" )
184189 }
185190
186191 got , err := actions_model .FindVariables (ctx , opts )
187192 if err != nil {
188193 ctx .ServerError ("FindVariables" , err )
189- return nil , false
194+ return nil
190195 } else if len (got ) == 0 {
191196 ctx .NotFound ("FindVariables" , nil )
192- return nil , false
197+ return nil
193198 }
194- return got [0 ], true
199+ return got [0 ]
195200}
196201
197202func VariableDelete (ctx * context.Context ) {
@@ -203,8 +208,8 @@ func VariableDelete(ctx *context.Context) {
203208
204209 id := ctx .PathParamInt64 ("variable_id" )
205210
206- variable , ok := findVariable (ctx , id , vCtx )
207- if ! ok {
211+ variable := findActionsVariable (ctx , id , vCtx )
212+ if ctx . Written () {
208213 return
209214 }
210215
0 commit comments