Skip to content

Commit

Permalink
breakout parsing custom_property_value as a string slice to its own f…
Browse files Browse the repository at this point in the history
…unction
  • Loading branch information
felixlut committed Oct 9, 2024
1 parent bc93a88 commit d298e07
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
23 changes: 16 additions & 7 deletions github/data_source_github_repository_custom_properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,26 @@ func flattenRepositoryCustomProperties(customProperties []*github.CustomProperty

result["property_name"] = prop.PropertyName

switch value := prop.Value.(type) {
case string:
result["property_value"] = []string{value}
case []string:
result["property_value"] = value
default:
return nil, fmt.Errorf("custom property value couldn't be parsed as a string or a list of strings: %s", value)
propertyValue, err := parseRepositoryCustomPropertyValueToStringSlice(prop)
if err != nil {
return nil, err
}

result["property_value"] = propertyValue

results = append(results, result)
}

return results, nil
}

func parseRepositoryCustomPropertyValueToStringSlice(prop *github.CustomPropertyValue) ([]string, error) {
switch value := prop.Value.(type) {
case string:
return []string{value}, nil
case []string:
return value, nil
default:
return nil, fmt.Errorf("custom property value couldn't be parsed as a string or a list of strings: %s", value)
}
}
13 changes: 4 additions & 9 deletions github/resource_github_repository_custom_property.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,10 @@ func readRepositoryCustomPropertyValue(ctx context.Context, client *github.Clien
return nil, fmt.Errorf("could not find a custom property with name: %s", propertyName)
}

var wantedCustomPropertyValue []string
switch value := wantedCustomProperty.Value.(type) {
case string:
wantedCustomPropertyValue = []string{value}
case []string:
wantedCustomPropertyValue = value
default:
return nil, fmt.Errorf("custom property value couldn't be parsed as a string or a list of strings: %s", value)
wantedPropertyValue, err := parseRepositoryCustomPropertyValueToStringSlice(wantedCustomProperty)
if err != nil {
return nil, err
}

return wantedCustomPropertyValue, nil
return wantedPropertyValue, nil
}

0 comments on commit d298e07

Please sign in to comment.