Skip to content

Commit 5c4dfa9

Browse files
authored
feat(discovery): return latest entries (#845)
Signed-off-by: Miguel Martinez Trivino <[email protected]>
1 parent e61dffb commit 5c4dfa9

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

app/controlplane/internal/biz/referrer_integration_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func (s *referrerIntegrationTestSuite) TestExtractAndPersistsDependentAttestatio
137137
s.NoError(err)
138138
// It has a commit and an attestation
139139
require.Len(s.T(), got.References, 2)
140-
s.Equal(wantDependentAtt, got.References[1].Digest)
140+
s.Equal(wantDependentAtt, got.References[0].Digest)
141141
})
142142
}
143143

@@ -226,7 +226,7 @@ func (s *referrerIntegrationTestSuite) TestExtractAndPersists() {
226226
require.Len(t, got.References, 6)
227227

228228
for i, want := range []*biz.Referrer{
229-
wantReferrerCommit, wantReferrerSBOM, wantReferrerArtifact, wantReferrerOpenVEX, wantReferrerSarif, wantReferrerContainerImage} {
229+
wantReferrerArtifact, wantReferrerContainerImage, wantReferrerCommit, wantReferrerOpenVEX, wantReferrerSarif, wantReferrerSBOM} {
230230
gotR := got.References[i]
231231
s.Equal(want, gotR.Referrer)
232232
}
@@ -345,9 +345,9 @@ func (s *referrerIntegrationTestSuite) TestExtractAndPersists() {
345345
// it should be referenced by two attestations since it's subject of both
346346
require.Len(t, got.References, 2)
347347
s.Equal("ATTESTATION", got.References[0].Kind)
348-
s.Equal("sha256:c90ccaab0b2cfda9980836aef407f62d747680ea9793ddc6ad2e2d7ab615933d", got.References[0].Digest)
348+
s.Equal("sha256:de36d470d792499b1489fc0e6623300fc8822b8f0d2981bb5ec563f8dde723c7", got.References[0].Digest)
349349
s.Equal("ATTESTATION", got.References[1].Kind)
350-
s.Equal("sha256:de36d470d792499b1489fc0e6623300fc8822b8f0d2981bb5ec563f8dde723c7", got.References[1].Digest)
350+
s.Equal("sha256:c90ccaab0b2cfda9980836aef407f62d747680ea9793ddc6ad2e2d7ab615933d", got.References[1].Digest)
351351
})
352352

353353
s.T().Run("if all associated workflows are private, the referrer is private", func(t *testing.T) {

app/controlplane/internal/data/referrer.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,9 @@ func (r *ReferrerRepo) doGet(ctx context.Context, root *ent.Referrer, allowedOrg
236236
// Attach the workflow predicate
237237
predicateReferrer = append(predicateReferrer, referrer.HasWorkflowsWith(predicateWF...))
238238

239-
refs, err := root.QueryReferences().Where(predicateReferrer...).WithWorkflows().Order(referrer.ByDigest()).All(ctx)
239+
// sort the references by creation date in descending order
240+
// so whenever we add pagination we'll get the latest x references
241+
refs, err := root.QueryReferences().Where(predicateReferrer...).WithWorkflows().Order(referrer.ByCreatedAt(), ent.Desc()).All(ctx)
240242
if err != nil {
241243
return nil, fmt.Errorf("failed to query references: %w", err)
242244
}

0 commit comments

Comments
 (0)