Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

download a re-run folder, and it gets rendered images too. #210

Merged
merged 4 commits into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 2 additions & 0 deletions pkg/images/imageExpander.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ func (expander *ImageExpanderImpl) GetExpandedImageFileCount() int {
func (expander *ImageExpanderImpl) ExpandImages(rootFolderPath string) error {
var err error

log.Printf("Expanding any 3270 image descriptions we have into images. Folder scanned: %s\n", rootFolderPath)

var paths []string
paths, err = expander.fs.GetAllFilePaths(rootFolderPath)

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, folderName)
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