From f77a443edf9b63dcf736eab033f6baa64d8778a7 Mon Sep 17 00:00:00 2001 From: ChristopherHX Date: Mon, 28 Oct 2024 04:45:20 +0100 Subject: [PATCH] fix: merge-multiple artifacts were broken (#2505) * fix: merge-multiple artifacts were broken * Update arifacts_v4.go * Update arifacts_v4.go * update id of delete artifact reqest --------- Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- pkg/artifacts/arifacts_v4.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/pkg/artifacts/arifacts_v4.go b/pkg/artifacts/arifacts_v4.go index 1d5611b..5cac996 100644 --- a/pkg/artifacts/arifacts_v4.go +++ b/pkg/artifacts/arifacts_v4.go @@ -84,6 +84,7 @@ import ( "encoding/base64" "errors" "fmt" + "hash/fnv" "io" "io/fs" "net/http" @@ -119,6 +120,12 @@ type ArtifactContext struct { Resp http.ResponseWriter } +func artifactNameToID(s string) int64 { + h := fnv.New64a() + h.Write([]byte(s)) + return int64(h.Sum64()) +} + func (c ArtifactContext) Error(status int, _ ...interface{}) { c.Resp.WriteHeader(status) } @@ -342,7 +349,7 @@ func (r *artifactV4Routes) finalizeArtifact(ctx *ArtifactContext) { respData := FinalizeArtifactResponse{ Ok: true, - ArtifactId: 1, + ArtifactId: artifactNameToID(req.Name), } r.sendProtbufBody(ctx, &respData) } @@ -368,11 +375,12 @@ func (r *artifactV4Routes) listArtifacts(ctx *ArtifactContext) { list := []*ListArtifactsResponse_MonolithArtifact{} for _, entry := range entries { - if req.NameFilter == nil || req.NameFilter.Value == entry.Name() { + id := artifactNameToID(entry.Name()) + if (req.NameFilter == nil || req.NameFilter.Value == entry.Name()) || (req.IdFilter == nil || req.IdFilter.Value == id) { data := &ListArtifactsResponse_MonolithArtifact{ Name: entry.Name(), CreatedAt: timestamppb.Now(), - DatabaseId: 1, + DatabaseId: id, WorkflowRunBackendId: req.WorkflowRunBackendId, WorkflowJobRunBackendId: req.WorkflowJobRunBackendId, Size: 0, @@ -442,7 +450,7 @@ func (r *artifactV4Routes) deleteArtifact(ctx *ArtifactContext) { respData := DeleteArtifactResponse{ Ok: true, - ArtifactId: 1, + ArtifactId: artifactNameToID(req.Name), } r.sendProtbufBody(ctx, &respData) }