Skip to content
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
18 changes: 16 additions & 2 deletions github/orgs_properties.go
Original file line numberDiff line numberDiff line change
Expand Up@@ -64,8 +64,22 @@ func (cp CustomProperty) DefaultValueString() (string, bool) {
func (cp CustomProperty) DefaultValueStrings() ([]string, bool) {
switch cp.ValueType {
case PropertyValueTypeMultiSelect:
s, ok := cp.DefaultValue.([]string)
return s, ok
switch v := cp.DefaultValue.(type) {
case []string:
return v, true
case []any:
vals := make([]string, len(v))
for i, item := range v {
s, ok := item.(string)
if !ok {
return nil, false
Comment thread
stevehipwell marked this conversation as resolved.
}
vals[i] = s
}
return vals, true
default:
return nil, false
}
default:
return nil, false
}
Expand Down
121 changes: 87 additions & 34 deletions github/orgs_properties_test.go
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,35 +21,51 @@ func TestOrganizationsService_GetAllCustomProperties(t *testing.T) {
mux.HandleFunc("/orgs/o/properties/schema", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `[
{
"property_name": "name",
"value_type": "single_select",
"required": true,
"default_value": "production",
"description": "Prod or dev environment",
"allowed_values":[
"production",
"development"
],
"values_editable_by": "org_actors"
},
{
"property_name": "service",
"value_type": "string"
},
{
"property_name": "team",
"value_type": "string",
"description": "Team owning the repository"
},
{
"property_name": "documentation",
"value_type": "url",
"required": true,
"description": "Link to the documentation",
"default_value": "https://example.com/docs"
}
]`)
{
"property_name": "name",
"value_type": "single_select",
"required": true,
"default_value": "production",
"description": "Prod or dev environment",
"allowed_values":[
"production",
"development"
],
"values_editable_by": "org_actors"
},
{
"property_name": "test",
"value_type": "multi_select",
"required": true,
"default_value": [
"foo",
"baz"
],
"description": "Prod or dev environment",
"allowed_values":[
"foo",
"bar",
"baz"
],
"values_editable_by": "org_actors"
},
{
"property_name": "service",
"value_type": "string"
},
{
"property_name": "team",
"value_type": "string",
"description": "Team owning the repository"
},
{
"property_name": "documentation",
"value_type": "url",
"required": true,
"description": "Link to the documentation",
"default_value": "https://example.com/docs"
}
]`)
})

ctx := t.Context()
Expand All@@ -68,6 +84,15 @@ func TestOrganizationsService_GetAllCustomProperties(t *testing.T) {
AllowedValues: []string{"production", "development"},
ValuesEditableBy: Ptr("org_actors"),
},
{
PropertyName: Ptr("test"),
ValueType: PropertyValueTypeMultiSelect,
Required: Ptr(true),
DefaultValue: []any{"foo", "baz"},
Description: Ptr("Prod or dev environment"),
AllowedValues: []string{"foo", "bar", "baz"},
ValuesEditableBy: Ptr("org_actors"),
},
{
PropertyName: Ptr("service"),
ValueType: PropertyValueTypeString,
Expand All@@ -85,12 +110,13 @@ func TestOrganizationsService_GetAllCustomProperties(t *testing.T) {
DefaultValue: "https://example.com/docs",
},
}
if !cmp.Equal(properties, want) {
t.Errorf("Organizations.GetAllCustomProperties returned %+v, want %+v", properties, want)
}

const methodName = "GetAllCustomProperties"

if diff := cmp.Diff(want, properties); diff != "" {
t.Errorf("Organizations.%v diff mismatch (-want +got):\n%v", methodName, diff)
}

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Organizations.GetAllCustomProperties(ctx, "o")
if got != nil {
Expand DownExpand Up@@ -617,6 +643,15 @@ func TestCustomPropertyDefaultValueStrings(t *testing.T) {
ok: false,
want: []string{},
},
{
testName: "invalid_slice",
property: &CustomProperty{
ValueType: PropertyValueTypeString,
DefaultValue: []any{1, 2, 3},
},
ok: false,
want: []string{},
},
{
testName: "multi_select_invalid_value",
property: &CustomProperty{
Expand All@@ -636,7 +671,16 @@ func TestCustomPropertyDefaultValueStrings(t *testing.T) {
want: []string{},
},
{
testName: "multi_select_single_value",
testName: "multi_select_any_slice_single_value",
property: &CustomProperty{
ValueType: PropertyValueTypeMultiSelect,
DefaultValue: []any{"a"},
},
ok: true,
want: []string{"a"},
},
{
testName: "multi_select_string_slice_single_value",
property: &CustomProperty{
ValueType: PropertyValueTypeMultiSelect,
DefaultValue: []string{"a"},
Expand All@@ -645,7 +689,16 @@ func TestCustomPropertyDefaultValueStrings(t *testing.T) {
want: []string{"a"},
},
{
testName: "multi_select_multi_value",
testName: "multi_select_any_slice_multi_value",
property: &CustomProperty{
ValueType: PropertyValueTypeMultiSelect,
DefaultValue: []any{"a", "b"},
},
ok: true,
want: []string{"a", "b"},
},
{
testName: "multi_select_string_slice_multi_value",
property: &CustomProperty{
ValueType: PropertyValueTypeMultiSelect,
DefaultValue: []string{"a", "b"},
Expand Down
Loading