Skip to content

Commit af4e228

Browse files
authored
[CI-5600] Preserve subfolder structure of attachments (#251)
* [CI-5600] Preserve subfolder structure of attachments * refactor * fix AI review comments * fix: rename separator variable to pathComponent
1 parent e5fa275 commit af4e228

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

test/test.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ func (results Results) Upload(apiToken, endpointBaseURL, appSlug, buildSlug stri
282282
return fmt.Errorf("failed to get file info for %s: %w", asset, err)
283283
}
284284
uploadReq.Assets = append(uploadReq.Assets, FileInfo{
285-
FileName: filepath.Base(asset),
285+
FileName: relativeFilePath(asset, result.Name),
286286
FileSize: int(fi.Size()),
287287
})
288288
}
@@ -306,7 +306,7 @@ func (results Results) Upload(apiToken, endpointBaseURL, appSlug, buildSlug stri
306306

307307
for _, upload := range uploadResponse.Assets {
308308
for _, file := range result.AttachmentPaths {
309-
if filepath.Base(file) == upload.FileName {
309+
if relativeFilePath(file, result.Name) == upload.FileName {
310310
fi, err := os.Open(file)
311311
if err != nil {
312312
return fmt.Errorf("failed to open test result attachment (%s): %w", file, err)
@@ -335,3 +335,11 @@ func (results Results) calculateTotalSizeOfXMLContent() int {
335335
}
336336
return totalSize
337337
}
338+
339+
func relativeFilePath(absoluteFilePath, reportName string) string {
340+
pathComponent := string(filepath.Separator) + reportName + string(filepath.Separator)
341+
if strings.Contains(absoluteFilePath, pathComponent) {
342+
return strings.SplitN(absoluteFilePath, pathComponent, 2)[1]
343+
}
344+
return filepath.Base(absoluteFilePath)
345+
}

0 commit comments

Comments
 (0)