Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

properties service: Don't fail if multiple entries are found #4642

Merged
merged 2 commits into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/entities/properties/service/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ func matchEntityWithHint(
continue
} else if errors.Is(err, ErrMultipleEntities) {
l.Error().Msg("multiple entities matched")
return nil, ErrMultipleEntities
continue
}
return nil, fmt.Errorf("failed to match entity by hint: %w", err)
}
Expand Down
80 changes: 79 additions & 1 deletion internal/entities/properties/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,85 @@ func TestPropertiesService_EntityWithPropertiesByUpstreamHint(t *testing.T) {
insertPropertiesFromMap(ctx, t, store, ent.ID, propMap)
}
},
expectedError: ErrMultipleEntities,
expectedError: ErrEntityNotFound,
},
{
name: "Multiple pull requests with the same ID matched by name",
entType: minderv1.Entity_ENTITY_PULL_REQUESTS,
byPropMap: map[string]any{
properties.PropertyUpstreamID: "1",
properties.PropertyName: "test-repo-2-with-pr/1",
},
hint: ByUpstreamHint{
ProviderImplements: db.NullProviderType{
ProviderType: db.ProviderTypeGithub,
Valid: true,
},
},
dbSetup: func(t *testing.T, store db.Store) {
t.Helper()

repo1, err := store.CreateEntity(ctx, db.CreateEntityParams{
EntityType: entities.EntityTypeToDB(minderv1.Entity_ENTITY_REPOSITORIES),
Name: "test-repo-1-with-pr",
ProjectID: tctx.dbProj.ID,
ProviderID: tctx.ghAppProvider.ID,
})
require.NoError(t, err)

repo2, err := store.CreateEntity(ctx, db.CreateEntityParams{
EntityType: entities.EntityTypeToDB(minderv1.Entity_ENTITY_REPOSITORIES),
Name: "test-repo-2-with-pr",
ProjectID: tctx.dbProj.ID,
ProviderID: tctx.ghAppProvider.ID,
})
require.NoError(t, err)

repo1Pr, err := store.CreateEntity(ctx, db.CreateEntityParams{
EntityType: entities.EntityTypeToDB(minderv1.Entity_ENTITY_PULL_REQUESTS),
Name: "test-repo-1-with-pr/1",
ProjectID: tctx.dbProj.ID,
ProviderID: tctx.ghAppProvider.ID,
OriginatedFrom: uuid.NullUUID{
UUID: repo1.ID,
},
})
require.NoError(t, err)

insertPropertiesFromMap(ctx, t, store,
repo1Pr.ID,
map[string]any{
properties.PropertyUpstreamID: "1",
properties.PropertyName: "test-repo-1-with-pr/1",
},
)

repo2Pr, err := store.CreateEntity(ctx, db.CreateEntityParams{
EntityType: entities.EntityTypeToDB(minderv1.Entity_ENTITY_PULL_REQUESTS),
Name: "test-repo-2-with-pr/1",
ProjectID: tctx.dbProj.ID,
ProviderID: tctx.ghAppProvider.ID,
OriginatedFrom: uuid.NullUUID{
UUID: repo2.ID,
},
})
require.NoError(t, err)

insertPropertiesFromMap(ctx, t, store,
repo2Pr.ID,
map[string]any{
properties.PropertyUpstreamID: "1",
properties.PropertyName: "test-repo-2-with-pr/1",
},
)
},
checkResult: func(t *testing.T, result *models.EntityWithProperties) {
t.Helper()
require.NotNil(t, result)
require.Equal(t, "test-repo-2-with-pr/1", result.Entity.Name)
require.Equal(t, "1", result.Properties.GetProperty(properties.PropertyUpstreamID).GetString())
require.Equal(t, tctx.ghAppProvider.ID, result.Entity.ProviderID)
},
},
{
name: "One of multiple entities matched by provider hint",
Expand Down