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

Fix entity id in ListEvaluationHistory RPC. #3933

Merged
merged 1 commit into from
Jul 19, 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
22 changes: 14 additions & 8 deletions database/query/eval_history.sql
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,21 @@ INSERT INTO alert_events(
SELECT s.id::uuid AS evaluation_id,
s.evaluation_time as evaluated_at,
-- entity type
CASE WHEN ere.repository_id IS NOT NULL THEN 'repository'::entities
WHEN ere.pull_request_id IS NOT NULL THEN 'pull_request'::entities
WHEN ere.artifact_id IS NOT NULL THEN 'artifact'::entities
END AS entity_type,
CAST(
CASE
WHEN ere.repository_id IS NOT NULL THEN 'repository'
WHEN ere.pull_request_id IS NOT NULL THEN 'pull_request'
WHEN ere.artifact_id IS NOT NULL THEN 'artifact'
END AS entities
) AS entity_type,
-- entity id
CASE WHEN ere.repository_id IS NOT NULL THEN r.id
WHEN ere.pull_request_id IS NOT NULL THEN pr.id
WHEN ere.artifact_id IS NOT NULL THEN a.id
END AS entity_id,
CAST(
CASE
WHEN ere.repository_id IS NOT NULL THEN r.id
WHEN ere.pull_request_id IS NOT NULL THEN pr.id
WHEN ere.artifact_id IS NOT NULL THEN a.id
END AS uuid
) AS entity_id,
-- raw fields for entity names
r.repo_owner,
r.repo_name,
Expand Down
2 changes: 1 addition & 1 deletion internal/controlplane/handlers_evalstatus.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ func fromEvaluationHistoryRow(
res = append(res, &minderv1.EvaluationHistory{
EvaluatedAt: timestamppb.New(row.EvaluatedAt),
Entity: &minderv1.EvaluationHistoryEntity{
Id: row.EvaluationID.String(),
Id: row.EntityID.String(),
Type: entityType,
Name: entityName,
},
Expand Down
26 changes: 16 additions & 10 deletions internal/db/eval_history.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions internal/history/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func TestListEvaluationHistory(t *testing.T) {
evaluatedAt1 := time.Now()
evaluatedAt2 := evaluatedAt1.Add(-1 * time.Second)
evaluatedAt3 := evaluatedAt1.Add(-2 * time.Second)
entityType := []byte("repository")
entityType := db.EntitiesRepository

remediation := db.NullRemediationStatusTypes{
RemediationStatusTypes: db.RemediationStatusTypesSuccess,
Expand Down Expand Up @@ -664,7 +664,7 @@ func TestListEvaluationHistory(t *testing.T) {
func makeHistoryRow(
id uuid.UUID,
evaluatedAt time.Time,
entityType interface{},
entityType db.Entities,
status db.NullRemediationStatusTypes,
alert db.NullAlertStatusTypes,
) db.ListEvaluationHistoryRow {
Expand Down