Skip to content

Commit f77a443

Browse files
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>
1 parent 0c09a77 commit f77a443

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

pkg/artifacts/arifacts_v4.go

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ import (
8484
"encoding/base64"
8585
"errors"
8686
"fmt"
87+
"hash/fnv"
8788
"io"
8889
"io/fs"
8990
"net/http"
@@ -119,6 +120,12 @@ type ArtifactContext struct {
119120
Resp http.ResponseWriter
120121
}
121122

123+
func artifactNameToID(s string) int64 {
124+
h := fnv.New64a()
125+
h.Write([]byte(s))
126+
return int64(h.Sum64())
127+
}
128+
122129
func (c ArtifactContext) Error(status int, _ ...interface{}) {
123130
c.Resp.WriteHeader(status)
124131
}
@@ -342,7 +349,7 @@ func (r *artifactV4Routes) finalizeArtifact(ctx *ArtifactContext) {
342349

343350
respData := FinalizeArtifactResponse{
344351
Ok: true,
345-
ArtifactId: 1,
352+
ArtifactId: artifactNameToID(req.Name),
346353
}
347354
r.sendProtbufBody(ctx, &respData)
348355
}
@@ -368,11 +375,12 @@ func (r *artifactV4Routes) listArtifacts(ctx *ArtifactContext) {
368375
list := []*ListArtifactsResponse_MonolithArtifact{}
369376

370377
for _, entry := range entries {
371-
if req.NameFilter == nil || req.NameFilter.Value == entry.Name() {
378+
id := artifactNameToID(entry.Name())
379+
if (req.NameFilter == nil || req.NameFilter.Value == entry.Name()) || (req.IdFilter == nil || req.IdFilter.Value == id) {
372380
data := &ListArtifactsResponse_MonolithArtifact{
373381
Name: entry.Name(),
374382
CreatedAt: timestamppb.Now(),
375-
DatabaseId: 1,
383+
DatabaseId: id,
376384
WorkflowRunBackendId: req.WorkflowRunBackendId,
377385
WorkflowJobRunBackendId: req.WorkflowJobRunBackendId,
378386
Size: 0,
@@ -442,7 +450,7 @@ func (r *artifactV4Routes) deleteArtifact(ctx *ArtifactContext) {
442450

443451
respData := DeleteArtifactResponse{
444452
Ok: true,
445-
ArtifactId: 1,
453+
ArtifactId: artifactNameToID(req.Name),
446454
}
447455
r.sendProtbufBody(ctx, &respData)
448456
}

0 commit comments

Comments
 (0)