-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Description
I've encountered the following possibly erroneous behaviour:
Version: master (unreleased)
Description:
PR #3906 introduced breaking changes. After adapting to these changes and using the new DefaultValueStrings() method, I've noticed that default values for custom properties of type multi_select always return [], false in my setup.
Expected Root Cause:
The JSON unmarshalling of DefaultValue (type any) results in []interface{} instead of []string, causing the type assertion at orgs_properties.go:L67 to fail.
Expected Behavior:
DefaultValueStrings() should return the default values for multi_select properties.
Actual Behavior:
Always returns [], false.
Suggested Fix:
Similar to the custom unmarshalling implemented for CustomPropertyValue (orgs_properties.go:L128-L136), CustomProperty.DefaultValue likely needs custom unmarshalling logic.
Workaround:
I've worked around this issue by using the "raw" value DefaultValue and handling both []string and []any types:
[...]
case github.PropertyValueTypeMultiSelect:
var v []string
switch val := current.DefaultValue.(type) {
case []string:
v = val
case []any:
v = make([]string, len(val))
for i, item := range val {
str, ok := item.(string)
if !ok {
return nil, fmt.Errorf("failed to convert default value for custom property %s to []string: %+v", current.GetPropertyName(), current.DefaultValue)
}
v[i] = str
}
default:
return nil, fmt.Errorf("unsupported default value type for multi_select: %T", current.DefaultValue)
}
[...]
return v, nilMinimal Reproduction (untested)
- Create Custom Property "schema" for repositories at org level (
https://github.com/organizations/<YOUR ORG>/settings/custom-properties-> New property) of type "Multi select" with- some arbitrary name
- some arbitrary options
- "Require this property for all repositories" checked and some arbitrary default values
- Use go-github@master
GetAllCustomProperties(ctx context.Context, org string)(https://github.com/google/go-github/blob/master/github/orgs_properties.go#L148) to fetch Custom Properties - use
DefaultValueStrings()on the struct representing the newly created multi select property
Disclaimer
I've not had the time to thoroughly investigate the issue. So the error might be caused in our implementation. :)