Skip to content

Commit

Permalink
Merge pull request #1025 from rdimitrov/fix-empty-tags-upsert
Browse files Browse the repository at this point in the history
fix: don't upsert empty tags as valid value
  • Loading branch information
rdimitrov authored Sep 27, 2023
2 parents f123f9f + ac78233 commit 1f28744
Showing 1 changed file with 9 additions and 10 deletions.
19 changes: 9 additions & 10 deletions internal/controlplane/handlers_githubwebhooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -758,15 +758,15 @@ func upsertVersionedArtifact(

// To avoid conflicts, we search for all existing entries that have the incoming tag in their Tags field.
// If found, the existing artifact is updated by removing the incoming tag from its tags column.
// Loop through all incomming tags
// Loop through all incoming tags
for _, incomingTag := range versionedArtifact.Version.Tags {
// Search artifact versions having the incomming tag (there should be at most 1 or no matches at all)
// Search artifact versions having the incoming tag (there should be at most 1 or no matches at all)
existingArtifactVersions, err := qtx.ListArtifactVersionsByArtifactIDAndTag(ctx,
db.ListArtifactVersionsByArtifactIDAndTagParams{ArtifactID: dbArtifact.ID,
Tags: sql.NullString{Valid: true, String: incomingTag},
Limit: sql.NullInt32{Valid: false, Int32: 0}})
if errors.Is(err, sql.ErrNoRows) {
// There're no tagged versions matching the incoming tag, all okay
// There are no tagged versions matching the incoming tag, all okay
continue
} else if err != nil {
// Unexpected failure
Expand All @@ -779,14 +779,13 @@ func upsertVersionedArtifact(
}
// Rebuild the Tags list removing anything that would conflict
newTags := slices.DeleteFunc(strings.Split(existing.Tags.String, ","), func(in string) bool { return in == incomingTag })
// Update the versioned artifact row in the store (we should't change anything else except the tags value)
newTagsSQL := sql.NullString{String: strings.Join(newTags, ",")}
newTagsSQL.Valid = len(newTagsSQL.String) > 0
// Update the versioned artifact row in the store (we shouldn't change anything else except the tags value)
_, err := qtx.UpsertArtifactVersion(ctx, db.UpsertArtifactVersionParams{
ArtifactID: existing.ArtifactID,
Version: existing.Version,
Tags: sql.NullString{
String: strings.Join(newTags, ","),
Valid: true,
},
ArtifactID: existing.ArtifactID,
Version: existing.Version,
Tags: newTagsSQL,
Sha: existing.Sha,
CreatedAt: existing.CreatedAt,
SignatureVerification: existing.SignatureVerification.RawMessage,
Expand Down

0 comments on commit 1f28744

Please sign in to comment.