Skip to content

Commit

Permalink
download a re-run folder, and it gets rendered images too.
Browse files Browse the repository at this point in the history
Signed-off-by: Mike Cobbett <[email protected]>
  • Loading branch information
techcobweb committed Feb 2, 2024
1 parent f98328d commit aa8888d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 25 deletions.
20 changes: 0 additions & 20 deletions pkg/cmd/runsDownload.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,10 @@
package cmd

import (
"fmt"
"log"

"github.com/galasa-dev/cli/pkg/api"
"github.com/galasa-dev/cli/pkg/auth"
"github.com/galasa-dev/cli/pkg/embedded"
galasaErrors "github.com/galasa-dev/cli/pkg/errors"
"github.com/galasa-dev/cli/pkg/images"
"github.com/galasa-dev/cli/pkg/runs"
"github.com/galasa-dev/cli/pkg/utils"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -154,22 +150,6 @@ func (cmd *RunsDownloadCommand) executeRunsDownload(
apiClient,
cmd.values.runDownloadTargetFolder,
)

if err == nil {
// No error, so try to expand the files.
embeddedFileSystem := embedded.GetReadOnlyFileSystem()
renderer := images.NewImageRenderer(embeddedFileSystem)
expander := images.NewImageExpander(fileSystem, renderer)

err = expander.ExpandImages(cmd.values.runDownloadTargetFolder)
if err == nil {

// Write out a status string to the console about how many files were rendered.
count := expander.GetExpandedImageFileCount()
message := fmt.Sprintf(galasaErrors.GALASA_INFO_RENDERED_IMAGE_COUNT.Template, count)
console.WriteString(message)
}
}
}
}
}
Expand Down
48 changes: 43 additions & 5 deletions pkg/runs/runsDownload.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
galasaErrors "github.com/galasa-dev/cli/pkg/errors"
"github.com/galasa-dev/cli/pkg/files"
"github.com/galasa-dev/cli/pkg/galasaapi"
"github.com/galasa-dev/cli/pkg/images"
"github.com/galasa-dev/cli/pkg/utils"
)

Expand Down Expand Up @@ -70,7 +71,7 @@ func DownloadArtifacts(
var folderName string
folderName, err = nameDownloadFolder(runs[0], runName, timeService)
if err == nil {
err = downloadArtifactsToDirectory(apiClient, folderName, runs[0], fileSystem, forceDownload, console, runDownloadTargetFolder)
err = downloadArtifactsAndRenderImagesToDirectory(apiClient, folderName, runs[0], fileSystem, forceDownload, console, runDownloadTargetFolder)
}
} else {
log.Printf("No artifacts to download for run: '%s'", runName)
Expand All @@ -97,7 +98,7 @@ func downloadReRunArtfifacts(
for reRunIndex, reRun := range reRunsList {
if err == nil {
directoryName := nameReRunArtifactDownloadDirectory(reRun, reRunIndex, timeService)
err = downloadArtifactsToDirectory(
err = downloadArtifactsAndRenderImagesToDirectory(
apiClient,
directoryName,
reRun,
Expand Down Expand Up @@ -158,16 +159,34 @@ func nameDownloadFolder(run galasaapi.Run, runName string, timeService utils.Tim
return directoryName, err
}

func downloadArtifactsToDirectory(apiClient *galasaapi.APIClient,
func renderImagesInFolder(fileSystem files.FileSystem, folderName string, console utils.Console) error {
var err error

// No error, so try to expand the files.
embeddedFileSystem := embedded.GetReadOnlyFileSystem()
renderer := images.NewImageRenderer(embeddedFileSystem)
expander := images.NewImageExpander(fileSystem, renderer)

err = expander.ExpandImages(folderName)
if err == nil {

// Write out a status string to the console about how many files were rendered.
count := expander.GetExpandedImageFileCount()
message := fmt.Sprintf(galasaErrors.GALASA_INFO_RENDERED_IMAGE_COUNT.Template, count)
console.WriteString(message)
}
return err
}

func downloadArtifactsAndRenderImagesToDirectory(apiClient *galasaapi.APIClient,
directoryName string,
run galasaapi.Run,
fileSystem files.FileSystem,
forceDownload bool,
console utils.Console,
runDownloadTargetFolder string,
) error {

runId := run.GetRunId()
var err error

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

err = downloadArtifactsToDirectory(apiClient, directoryName, run, fileSystem, forceDownload, console)

if err == nil {
err = renderImagesInFolder(fileSystem, directoryName, console)
}

return err
}

func downloadArtifactsToDirectory(apiClient *galasaapi.APIClient,
directoryName string,
run galasaapi.Run,
fileSystem files.FileSystem,
forceDownload bool,
console utils.Console,
) error {

runId := run.GetRunId()

filesWrittenOkCount := 0

artifactPaths, err := GetArtifactPathsFromRestApi(runId, apiClient)
Expand Down

0 comments on commit aa8888d

Please sign in to comment.