Skip to content

Commit

Permalink
fix(api): purge check vcsclient (#6019)
Browse files Browse the repository at this point in the history
* fix(api): check vcsclient

Signed-off-by: Yvonnick Esnault <[email protected]>

* fix: cr

Signed-off-by: Yvonnick Esnault <[email protected]>

* fix: cr

Signed-off-by: Yvonnick Esnault <[email protected]>

* fix:  cr

Signed-off-by: Yvonnick Esnault <[email protected]>
  • Loading branch information
yesnault authored Nov 19, 2021
1 parent fb437e9 commit 982f2a1
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions engine/api/purge/purge_run.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,25 +135,29 @@ func ApplyRetentionPolicyOnWorkflow(ctx context.Context, store cache.Store, db *
if gitRepo, has := payload["git.repository"]; has {
if gitRepo != app.RepositoryFullname {
isFork = true
forkBranches, err = getBranches(ctx, gitRepo, vcsClient)
if err != nil {
return err
if vcsClient != nil {
forkBranches, err = getBranches(ctx, gitRepo, vcsClient)
if err != nil {
return err
}
}
}
}

var keep bool
if !isFork {
keep, err = applyRetentionPolicyOnRun(ctx, db, wf, run, payload, branchesMap, app, vcsClient, opts)
} else {
if isFork {
keep, err = applyRetentionPolicyOnRun(ctx, db, wf, run, payload, forkBranches, app, vcsClient, opts)
}
if err != nil {
return err
} else {
keep, err = applyRetentionPolicyOnRun(ctx, db, wf, run, payload, branchesMap, app, vcsClient, opts)
}
if keep {
runs = append(runs, sdk.WorkflowRunToKeep{ID: run.ID, Num: run.Number, Status: run.Status})
}
if err != nil {
log.Error(ctx, "error on run %v:%d err:%v", wf.Name, run.Number, err)
continue

}
}

if count > offset+limit {
Expand Down Expand Up @@ -292,6 +296,9 @@ func purgeComputeVariables(ctx context.Context, luaCheck *luascript.Check, run s
if has {
_, exist = branchesMap[b]
}
if has && vcsClient == nil {
return sdk.NewErrorFrom(sdk.ErrUnknownError, "vcsClient nil but git branch exists")
}
vars[RunHasGitBranch] = strconv.FormatBool(has)
vars[RunGitBranchExist] = strconv.FormatBool(exist)

Expand Down

0 comments on commit 982f2a1

Please sign in to comment.