github.com/cobalt77/jfrog-client-go@v0.14.5/artifactory/services/utils/fileinfoutils.go (about) 1 package utils 2 3 import ( 4 "strings" 5 6 "github.com/cobalt77/jfrog-client-go/artifactory/buildinfo" 7 "github.com/cobalt77/jfrog-client-go/utils/io/fileutils" 8 ) 9 10 type FileHashes struct { 11 Sha256 string `json:"sha256,omitempty"` 12 Sha1 string `json:"sha1,omitempty"` 13 Md5 string `json:"md5,omitempty"` 14 } 15 16 type FileInfo struct { 17 *FileHashes 18 LocalPath string `json:"localPath,omitempty"` 19 ArtifactoryPath string `json:"artifactoryPath,omitempty"` 20 InternalArtifactoryPath string `json:"internalArtifactoryPath,omitempty"` 21 } 22 23 func (fileInfo *FileInfo) ToBuildArtifacts() buildinfo.Artifact { 24 artifact := buildinfo.Artifact{Checksum: &buildinfo.Checksum{}} 25 artifact.Sha1 = fileInfo.Sha1 26 artifact.Md5 = fileInfo.Md5 27 // Artifact name in build info as the name in artifactory 28 filename, _ := fileutils.GetFileAndDirFromPath(fileInfo.ArtifactoryPath) 29 artifact.Name = filename 30 if i := strings.LastIndex(filename, "."); i != -1 { 31 artifact.Type = filename[i+1:] 32 } 33 artifact.Path = fileInfo.InternalArtifactoryPath 34 return artifact 35 } 36 37 func FlattenFileInfoArray(dependenciesBuildInfo [][]FileInfo) []FileInfo { 38 var buildInfo []FileInfo 39 for _, v := range dependenciesBuildInfo { 40 buildInfo = append(buildInfo, v...) 41 } 42 return buildInfo 43 }