Skip to content

Commit

Permalink
Fix issue with multiple entity IDs (#3699)
Browse files Browse the repository at this point in the history
Spotted by @eleftherias in smoke tests. When evaluating a PR, the repo
ID is also passed around. This violated the assumption that only one
entity type would be specified.

Change the logic so that we try and find a PR or artifact ID first, then
a repo ID later.
  • Loading branch information
dmjb committed Jun 24, 2024
1 parent 5f200ed commit ef45f63
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions internal/entities/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
package entities

import (
"fmt"
"errors"

"github.com/google/uuid"

Expand All @@ -31,14 +31,16 @@ func EntityFromIDs(
artifactID uuid.UUID,
pullRequestID uuid.UUID,
) (uuid.UUID, db.Entities, error) {
if repositoryID != uuid.Nil && artifactID == uuid.Nil && pullRequestID == uuid.Nil {
return repositoryID, db.EntitiesRepository, nil
// Note that the repo ID is often passed around with PRs.
// As a result, we test PRs and artifacts first, then repos.
if pullRequestID != uuid.Nil {
return pullRequestID, db.EntitiesPullRequest, nil
}
if repositoryID == uuid.Nil && artifactID != uuid.Nil && pullRequestID == uuid.Nil {
if artifactID != uuid.Nil {
return artifactID, db.EntitiesArtifact, nil
}
if repositoryID == uuid.Nil && artifactID == uuid.Nil && pullRequestID != uuid.Nil {
return pullRequestID, db.EntitiesPullRequest, nil
if repositoryID != uuid.Nil {
return repositoryID, db.EntitiesRepository, nil
}
return uuid.Nil, "", fmt.Errorf("unexpected combination of IDs: %s %s %s", repositoryID, artifactID, pullRequestID)
return uuid.Nil, "", errors.New("all entity IDs are nil")
}

0 comments on commit ef45f63

Please sign in to comment.