Skip to content

Commit 435a171

Browse files
authored
fix(api): use right ref (#7495)
1 parent 3262c08 commit 435a171

2 files changed

Lines changed: 17 additions & 11 deletions

File tree

engine/api/purge/purge_v2_test.go

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,14 +91,16 @@ func TestApplyRunRetentionOnProject_WorkflowWithRetention(t *testing.T) {
9191
Initiator: &sdk.V2Initiator{
9292
UserID: lambdauser.ID,
9393
},
94-
RunNumber: 0,
95-
WorkflowRef: "",
94+
RunNumber: 0,
95+
Contexts: sdk.WorkflowRunContext{
96+
Git: sdk.GitContext{Ref: ""},
97+
},
9698
}
9799
// Create run on master - We must keep only run_number 19 and 20
98100
for i := 0; i < 20; i++ {
99101
wr.RunNumber = int64(runNumber)
100102
runNumber++
101-
wr.WorkflowRef = "refs/heads/master"
103+
wr.Contexts.Git.Ref = "refs/heads/master"
102104

103105
require.NoError(t, workflow_v2.InsertRun(ctx, db, &wr))
104106

@@ -113,15 +115,15 @@ func TestApplyRunRetentionOnProject_WorkflowWithRetention(t *testing.T) {
113115
for i := 0; i < 20; i++ {
114116
wr.RunNumber = int64(runNumber)
115117
runNumber++
116-
wr.WorkflowRef = "refs/heads/dev/my/feat"
118+
wr.Contexts.Git.Ref = "refs/heads/dev/my/feat"
117119
require.NoError(t, workflow_v2.InsertRun(ctx, db, &wr))
118120
}
119121

120122
// Create run on fix branch. We must keep ony run_number 60
121123
for i := 0; i < 20; i++ {
122124
wr.RunNumber = int64(runNumber)
123125
runNumber++
124-
wr.WorkflowRef = "refs/heads/fix"
126+
wr.Contexts.Git.Ref = "refs/heads/fix"
125127
require.NoError(t, workflow_v2.InsertRun(ctx, db, &wr))
126128
}
127129

@@ -201,14 +203,18 @@ func TestApplyRunRetentionOnProject_FallbackProjectDefaultRule(t *testing.T) {
201203
Initiator: &sdk.V2Initiator{
202204
UserID: lambdauser.ID,
203205
},
204-
RunNumber: 0,
205-
WorkflowRef: "",
206+
RunNumber: 0,
207+
Contexts: sdk.WorkflowRunContext{
208+
Git: sdk.GitContext{
209+
Ref: "",
210+
},
211+
},
206212
}
207213
// Create run on master - We must keep only run_number 19 and 20
208214
for i := 0; i < 20; i++ {
209215
wr.RunNumber = int64(runNumber)
210216
runNumber++
211-
wr.WorkflowRef = "refs/heads/master"
217+
wr.Contexts.Git.Ref = "refs/heads/master"
212218
require.NoError(t, workflow_v2.InsertRun(ctx, db, &wr))
213219

214220
}

engine/api/workflow_v2/dao_run.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ func LoadRunsWorkflowRefsByWorkflow(ctx context.Context, db gorp.SqlExecutor, pr
254254
_, next := telemetry.Span(ctx, "LoadRunsWorkflowRefsByWorkflow")
255255
defer next()
256256
if _, err := db.Select(&refs, `
257-
SELECT DISTINCT workflow_ref
257+
SELECT DISTINCT contexts -> 'git' ->> 'ref'::TEXT
258258
FROM v2_workflow_run
259259
WHERE project_key = $1 AND vcs_server = $2 AND repository = $3 AND workflow_name = $4
260260
`, projKey, vcs, repository, workflow); err != nil {
@@ -655,7 +655,7 @@ func LoadRunsDescAtOffset(ctx context.Context, db gorp.SqlExecutor, projKey, vcs
655655
vcs_server = $2 AND
656656
repository = $3 AND
657657
workflow_name = $4 AND
658-
workflow_ref = $5
658+
contexts -> 'git' ->> 'ref'::TEXT = $5
659659
ORDER BY run_number DESC
660660
OFFSET $6`
661661

@@ -673,7 +673,7 @@ func LoadOlderRuns(ctx context.Context, db gorp.SqlExecutor, projKey, vcs, repo,
673673
vcs_server = $2 AND
674674
repository = $3 AND
675675
workflow_name = $4 AND
676-
workflow_ref = $5 AND
676+
contexts -> 'git' ->> 'ref'::TEXT = $5 AND
677677
now() - started > $6 * INTERVAL '1' DAY`
678678

679679
var ids []string

0 commit comments

Comments
 (0)