Skip to content

Commit e286104

Browse files
committed
fix: output not render error
Signed-off-by: Meng JiaFeng <[email protected]>
1 parent c4a8d2a commit e286104

File tree

3 files changed

+24
-16
lines changed

3 files changed

+24
-16
lines changed

internal/pkg/pluginengine/outputs.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,13 @@ import (
1414
func HandleOutputsReferences(smgr statemanager.Manager, options configmanager.RawOptions) []error {
1515
errorsList := make([]error, 0)
1616

17-
for optionKey, optionValue := range options {
17+
for optionKey, optionInterface := range options {
18+
switch optionValue := optionInterface.(type) {
1819
// only process string values in the options
1920
// since all outputs references are strings, not ints, not booleans, not maps
20-
if optionValueStr, ok := optionValue.(string); ok {
21-
log.Debugf("Before: %s: %s", optionKey, optionValueStr)
22-
match, toolName, instanceID, outputReferenceKey := getToolNamePluginOutputKey(optionValueStr)
21+
case string:
22+
log.Debugf("Before: %s: %s", optionKey, optionValue)
23+
match, toolName, instanceID, outputReferenceKey := getToolNamePluginOutputKey(optionValue)
2324
// do nothing, if the value string isn't in the format of a valid output reference
2425
if !match {
2526
continue
@@ -30,18 +31,17 @@ func HandleOutputsReferences(smgr statemanager.Manager, options configmanager.Ra
3031
continue
3132
}
3233
if val, ok := outputs[outputReferenceKey]; ok {
33-
options[optionKey] = replaceOutputKeyWithValue(optionValueStr, val.(string))
34+
options[optionKey] = replaceOutputKeyWithValue(optionValue, val.(string))
3435
log.Debugf("After: %s: %s", optionKey, options[optionKey])
3536
} else {
3637
errorsList = append(errorsList, fmt.Errorf("can't find Output reference key %s", outputReferenceKey))
3738
}
38-
}
39-
40-
// recursive if the value is a map (which means Tool.Option is a nested map)
41-
optionValueMap, ok := optionValue.(map[string]interface{})
42-
log.Debugf("Got nested map: %v", optionValueMap)
43-
if ok {
44-
errorsList = append(errorsList, HandleOutputsReferences(smgr, optionValueMap)...)
39+
case configmanager.RawOptions:
40+
// recursive if the value is a map (which means Tool.Option is a nested map)
41+
log.Debugf("Got nested map: %v", optionValue)
42+
errorsList = append(errorsList, HandleOutputsReferences(smgr, optionValue)...)
43+
default:
44+
log.Warnf("option %+v process output can't get valid type", optionInterface)
4545
}
4646
}
4747

internal/pkg/pluginengine/pluginengine_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,12 @@ var _ = Describe("Pluginengine", func() {
218218
Expect(err).NotTo(HaveOccurred())
219219

220220
dependantOptions := configmanager.RawOptions{
221-
"outerKey": map[string]interface{}{
221+
"outerKey": configmanager.RawOptions{
222222
"innerKey": fmt.Sprintf("${{ %s.%s.outputs.boardId }}", trelloName, trelloInstance),
223223
},
224224
}
225225
expectResult := configmanager.RawOptions{
226-
"outerKey": map[string]interface{}{
226+
"outerKey": configmanager.RawOptions{
227227
"innerKey": expectedBoardId,
228228
},
229229
}

internal/pkg/statemanager/state.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ import (
55
"fmt"
66
"sort"
77

8+
"golang.org/x/exp/maps"
9+
810
"github.com/devstream-io/devstream/internal/pkg/configmanager"
911

1012
"gopkg.in/yaml.v3"
@@ -36,8 +38,14 @@ func (rs ResourceStatus) GetOutputs() ResourceOutputs {
3638
if !ok {
3739
return nil
3840
}
39-
40-
return outputs.(ResourceOutputs)
41+
outputStatus, isStatus := outputs.(ResourceStatus)
42+
if !isStatus {
43+
return outputs.(ResourceOutputs)
44+
}
45+
// if outputs type is ResourceStatus, transfer this type to ResourceOutputs
46+
outputData := ResourceOutputs{}
47+
maps.Copy(outputData, outputStatus)
48+
return outputData
4149
}
4250

4351
type StatesMap struct {

0 commit comments

Comments
 (0)