@@ -135,25 +135,29 @@ func ApplyRetentionPolicyOnWorkflow(ctx context.Context, store cache.Store, db *
135135 if gitRepo , has := payload ["git.repository" ]; has {
136136 if gitRepo != app .RepositoryFullname {
137137 isFork = true
138- forkBranches , err = getBranches (ctx , gitRepo , vcsClient )
139- if err != nil {
140- return err
138+ if vcsClient != nil {
139+ forkBranches , err = getBranches (ctx , gitRepo , vcsClient )
140+ if err != nil {
141+ return err
142+ }
141143 }
142144 }
143145 }
144146
145147 var keep bool
146- if ! isFork {
147- keep , err = applyRetentionPolicyOnRun (ctx , db , wf , run , payload , branchesMap , app , vcsClient , opts )
148- } else {
148+ if isFork {
149149 keep , err = applyRetentionPolicyOnRun (ctx , db , wf , run , payload , forkBranches , app , vcsClient , opts )
150- }
151- if err != nil {
152- return err
150+ } else {
151+ keep , err = applyRetentionPolicyOnRun (ctx , db , wf , run , payload , branchesMap , app , vcsClient , opts )
153152 }
154153 if keep {
155154 runs = append (runs , sdk.WorkflowRunToKeep {ID : run .ID , Num : run .Number , Status : run .Status })
156155 }
156+ if err != nil {
157+ log .Error (ctx , "error on run %v:%d err:%v" , wf .Name , run .Number , err )
158+ continue
159+
160+ }
157161 }
158162
159163 if count > offset + limit {
@@ -292,6 +296,9 @@ func purgeComputeVariables(ctx context.Context, luaCheck *luascript.Check, run s
292296 if has {
293297 _ , exist = branchesMap [b ]
294298 }
299+ if has && vcsClient == nil {
300+ return sdk .NewErrorFrom (sdk .ErrUnknownError , "vcsClient nil but git branch exists" )
301+ }
295302 vars [RunHasGitBranch ] = strconv .FormatBool (has )
296303 vars [RunGitBranchExist ] = strconv .FormatBool (exist )
297304
0 commit comments