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: don't upsert empty tags as valid value #1025

Merged
merged 4 commits into from
Sep 27, 2023
Merged
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
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