Skip to content

Commit

Permalink
fix: fix MVS with transforms (#1074)
Browse files Browse the repository at this point in the history
  • Loading branch information
chase-crumbaugh authored Nov 7, 2024
1 parent c777a93 commit b8f71f6
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
19 changes: 13 additions & 6 deletions internal/run/minimumViableSpec.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,19 @@ func (w *Workflow) retryWithMinimumViableSpec(ctx context.Context, parentStep *w
substep := parentStep.NewSubstep("Retrying with minimum viable document")
source := w.workflow.Sources[sourceID]

source.Transformations = append(source.Transformations, workflow.Transformation{
FilterOperations: &workflow.FilterOperationsOptions{
Operations: strings.Join(invalidOperations, ","),
Exclude: pointer.ToBool(true),
},
})
if len(invalidOperations) > 0 {
source.Transformations = append(source.Transformations, workflow.Transformation{
FilterOperations: &workflow.FilterOperationsOptions{
Operations: strings.Join(invalidOperations, ","),
Exclude: pointer.ToBool(true),
},
})
} else {
// Sometimes the document has invalid, unused sections
source.Transformations = append(source.Transformations, workflow.Transformation{
RemoveUnused: pointer.ToBool(true),
})
}
w.workflow.Sources[sourceID] = source

sourcePath, sourceRes, err := w.RunSource(ctx, substep, sourceID, targetID)
Expand Down
14 changes: 7 additions & 7 deletions internal/run/transform.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,20 @@ func (t Transform) Do(ctx context.Context, inputPath string) (string, error) {
return "", err
}

var out bytes.Buffer
var out *bytes.Buffer
for _, transformation := range t.source.Transformations {
out = bytes.Buffer{}
out = &bytes.Buffer{}

if transformation.Cleanup != nil {
transformStep.NewSubstep("Cleaning up document")

if err := transform.CleanupFromReader(ctx, in, inputPath, &out, yamlOut); err != nil {
if err := transform.CleanupFromReader(ctx, in, inputPath, out, yamlOut); err != nil {
return "", err
}
} else if transformation.RemoveUnused != nil {
transformStep.NewSubstep("Removing unused nodes")

if err := transform.RemoveUnusedFromReader(ctx, in, inputPath, &out, yamlOut); err != nil {
if err := transform.RemoveUnusedFromReader(ctx, in, inputPath, out, yamlOut); err != nil {
return "", err
}
} else if transformation.FilterOperations != nil {
Expand All @@ -78,20 +78,20 @@ func (t Transform) Do(ctx context.Context, inputPath string) (string, error) {
}
transformStep.NewSubstep(fmt.Sprintf("Filtering %s %d operations", inOutString, len(operations)))

if err := transform.FilterOperationsFromReader(ctx, in, inputPath, operations, include, &out, yamlOut); err != nil {
if err := transform.FilterOperationsFromReader(ctx, in, inputPath, operations, include, out, yamlOut); err != nil {
return "", err
}
}

in = &out
in = bytes.NewReader(out.Bytes())
}

outFile, err := os.Create(outputPath)
defer outFile.Close()
if err != nil {
return "", err
}
if _, err := io.Copy(outFile, &out); err != nil {
if _, err := io.Copy(outFile, out); err != nil {
return "", err
}

Expand Down
2 changes: 0 additions & 2 deletions prompts/sources.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,8 +400,6 @@ func PromptForNewSource(currentWorkflow *workflow.Workflow) (string, *workflow.S
return "", nil, err
}

println("FILE LOCATION: " + fileLocation)

document, err := formatDocument(fileLocation, authHeader, false)
if err != nil {
return "", nil, err
Expand Down

0 comments on commit b8f71f6

Please sign in to comment.