Skip to content

Commit f092c0e

Browse files
authored
Merge pull request #210 from galasa-dev/mcobbett-render-images-on-test-re-run-folders-too
download a re-run folder, and it gets rendered images too.
2 parents 29e8a2a + 8957596 commit f092c0e

File tree

3 files changed

+45
-25
lines changed

3 files changed

+45
-25
lines changed

pkg/cmd/runsDownload.go

-20
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,10 @@
66
package cmd
77

88
import (
9-
"fmt"
109
"log"
1110

1211
"github.com/galasa-dev/cli/pkg/api"
1312
"github.com/galasa-dev/cli/pkg/auth"
14-
"github.com/galasa-dev/cli/pkg/embedded"
15-
galasaErrors "github.com/galasa-dev/cli/pkg/errors"
16-
"github.com/galasa-dev/cli/pkg/images"
1713
"github.com/galasa-dev/cli/pkg/runs"
1814
"github.com/galasa-dev/cli/pkg/utils"
1915
"github.com/spf13/cobra"
@@ -154,22 +150,6 @@ func (cmd *RunsDownloadCommand) executeRunsDownload(
154150
apiClient,
155151
cmd.values.runDownloadTargetFolder,
156152
)
157-
158-
if err == nil {
159-
// No error, so try to expand the files.
160-
embeddedFileSystem := embedded.GetReadOnlyFileSystem()
161-
renderer := images.NewImageRenderer(embeddedFileSystem)
162-
expander := images.NewImageExpander(fileSystem, renderer)
163-
164-
err = expander.ExpandImages(cmd.values.runDownloadTargetFolder)
165-
if err == nil {
166-
167-
// Write out a status string to the console about how many files were rendered.
168-
count := expander.GetExpandedImageFileCount()
169-
message := fmt.Sprintf(galasaErrors.GALASA_INFO_RENDERED_IMAGE_COUNT.Template, count)
170-
console.WriteString(message)
171-
}
172-
}
173153
}
174154
}
175155
}

pkg/images/imageExpander.go

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ func (expander *ImageExpanderImpl) GetExpandedImageFileCount() int {
4040
func (expander *ImageExpanderImpl) ExpandImages(rootFolderPath string) error {
4141
var err error
4242

43+
log.Printf("Expanding any 3270 image descriptions we have into images. Folder scanned: %s\n", rootFolderPath)
44+
4345
var paths []string
4446
paths, err = expander.fs.GetAllFilePaths(rootFolderPath)
4547

pkg/runs/runsDownload.go

+43-5
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
galasaErrors "github.com/galasa-dev/cli/pkg/errors"
2323
"github.com/galasa-dev/cli/pkg/files"
2424
"github.com/galasa-dev/cli/pkg/galasaapi"
25+
"github.com/galasa-dev/cli/pkg/images"
2526
"github.com/galasa-dev/cli/pkg/utils"
2627
)
2728

@@ -70,7 +71,7 @@ func DownloadArtifacts(
7071
var folderName string
7172
folderName, err = nameDownloadFolder(runs[0], runName, timeService)
7273
if err == nil {
73-
err = downloadArtifactsToDirectory(apiClient, folderName, runs[0], fileSystem, forceDownload, console, runDownloadTargetFolder)
74+
err = downloadArtifactsAndRenderImagesToDirectory(apiClient, folderName, runs[0], fileSystem, forceDownload, console, runDownloadTargetFolder)
7475
}
7576
} else {
7677
log.Printf("No artifacts to download for run: '%s'", runName)
@@ -97,7 +98,7 @@ func downloadReRunArtfifacts(
9798
for reRunIndex, reRun := range reRunsList {
9899
if err == nil {
99100
directoryName := nameReRunArtifactDownloadDirectory(reRun, reRunIndex, timeService)
100-
err = downloadArtifactsToDirectory(
101+
err = downloadArtifactsAndRenderImagesToDirectory(
101102
apiClient,
102103
directoryName,
103104
reRun,
@@ -158,16 +159,34 @@ func nameDownloadFolder(run galasaapi.Run, runName string, timeService utils.Tim
158159
return directoryName, err
159160
}
160161

161-
func downloadArtifactsToDirectory(apiClient *galasaapi.APIClient,
162+
func renderImagesInFolder(fileSystem files.FileSystem, folderName string, console utils.Console) error {
163+
var err error
164+
165+
// No error, so try to expand the files.
166+
embeddedFileSystem := embedded.GetReadOnlyFileSystem()
167+
renderer := images.NewImageRenderer(embeddedFileSystem)
168+
expander := images.NewImageExpander(fileSystem, renderer)
169+
170+
err = expander.ExpandImages(folderName)
171+
if err == nil {
172+
173+
// Write out a status string to the console about how many files were rendered.
174+
count := expander.GetExpandedImageFileCount()
175+
message := fmt.Sprintf(galasaErrors.GALASA_INFO_RENDERED_IMAGE_COUNT.Template, count, folderName)
176+
console.WriteString(message)
177+
}
178+
return err
179+
}
180+
181+
func downloadArtifactsAndRenderImagesToDirectory(apiClient *galasaapi.APIClient,
162182
directoryName string,
163183
run galasaapi.Run,
164184
fileSystem files.FileSystem,
165185
forceDownload bool,
166186
console utils.Console,
167187
runDownloadTargetFolder string,
168188
) error {
169-
170-
runId := run.GetRunId()
189+
var err error
171190

172191
// We want to base the directory we download to on the destination folder.
173192
// If the destination folder is "." (current folder/relative)
@@ -177,6 +196,25 @@ func downloadArtifactsToDirectory(apiClient *galasaapi.APIClient,
177196
directoryName = filepath.Join(runDownloadTargetFolder, directoryName)
178197
}
179198

199+
err = downloadArtifactsToDirectory(apiClient, directoryName, run, fileSystem, forceDownload, console)
200+
201+
if err == nil {
202+
err = renderImagesInFolder(fileSystem, directoryName, console)
203+
}
204+
205+
return err
206+
}
207+
208+
func downloadArtifactsToDirectory(apiClient *galasaapi.APIClient,
209+
directoryName string,
210+
run galasaapi.Run,
211+
fileSystem files.FileSystem,
212+
forceDownload bool,
213+
console utils.Console,
214+
) error {
215+
216+
runId := run.GetRunId()
217+
180218
filesWrittenOkCount := 0
181219

182220
artifactPaths, err := GetArtifactPathsFromRestApi(runId, apiClient)

0 commit comments

Comments
 (0)