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>
This commit is contained in:
ChristopherHX
2024-10-28 04:45:20 +01:00
committed by GitHub
parent 0c09a77836
commit f77a443edf

View File

@@ -84,6 +84,7 @@ import (
"encoding/base64" "encoding/base64"
"errors" "errors"
"fmt" "fmt"
"hash/fnv"
"io" "io"
"io/fs" "io/fs"
"net/http" "net/http"
@@ -119,6 +120,12 @@ type ArtifactContext struct {
Resp http.ResponseWriter 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{}) { func (c ArtifactContext) Error(status int, _ ...interface{}) {
c.Resp.WriteHeader(status) c.Resp.WriteHeader(status)
} }
@@ -342,7 +349,7 @@ func (r *artifactV4Routes) finalizeArtifact(ctx *ArtifactContext) {
respData := FinalizeArtifactResponse{ respData := FinalizeArtifactResponse{
Ok: true, Ok: true,
ArtifactId: 1, ArtifactId: artifactNameToID(req.Name),
} }
r.sendProtbufBody(ctx, &respData) r.sendProtbufBody(ctx, &respData)
} }
@@ -368,11 +375,12 @@ func (r *artifactV4Routes) listArtifacts(ctx *ArtifactContext) {
list := []*ListArtifactsResponse_MonolithArtifact{} list := []*ListArtifactsResponse_MonolithArtifact{}
for _, entry := range entries { 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{ data := &ListArtifactsResponse_MonolithArtifact{
Name: entry.Name(), Name: entry.Name(),
CreatedAt: timestamppb.Now(), CreatedAt: timestamppb.Now(),
DatabaseId: 1, DatabaseId: id,
WorkflowRunBackendId: req.WorkflowRunBackendId, WorkflowRunBackendId: req.WorkflowRunBackendId,
WorkflowJobRunBackendId: req.WorkflowJobRunBackendId, WorkflowJobRunBackendId: req.WorkflowJobRunBackendId,
Size: 0, Size: 0,
@@ -442,7 +450,7 @@ func (r *artifactV4Routes) deleteArtifact(ctx *ArtifactContext) {
respData := DeleteArtifactResponse{ respData := DeleteArtifactResponse{
Ok: true, Ok: true,
ArtifactId: 1, ArtifactId: artifactNameToID(req.Name),
} }
r.sendProtbufBody(ctx, &respData) r.sendProtbufBody(ctx, &respData)
} }