diff --git a/github/enterprise_properties_test.go b/github/enterprise_properties_test.go index 3155f9669bc..c78c17e6d75 100644 --- a/github/enterprise_properties_test.go +++ b/github/enterprise_properties_test.go @@ -56,7 +56,7 @@ func TestEnterpriseService_GetAllCustomProperties(t *testing.T) { PropertyName: Ptr("name"), ValueType: "single_select", Required: Ptr(true), - DefaultValue: Ptr("production"), + DefaultValue: "production", Description: Ptr("Prod or dev environment"), AllowedValues: []string{"production", "development"}, ValuesEditableBy: Ptr("org_actors"), @@ -92,7 +92,7 @@ func TestEnterpriseService_CreateOrUpdateCustomProperties(t *testing.T) { mux.HandleFunc("/enterprises/e/properties/schema", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "PATCH") - testBody(t, r, `{"properties":[{"property_name":"name","value_type":"single_select","required":true},{"property_name":"service","value_type":"string"}]}`+"\n") + testBody(t, r, `{"properties":[{"property_name":"name","value_type":"single_select","required":true,"default_value":null},{"property_name":"service","value_type":"string","default_value":null}]}`+"\n") fmt.Fprint(w, `[ { "property_name": "name", @@ -179,7 +179,7 @@ func TestEnterpriseService_GetCustomProperty(t *testing.T) { PropertyName: Ptr("name"), ValueType: "single_select", Required: Ptr(true), - DefaultValue: Ptr("production"), + DefaultValue: "production", Description: Ptr("Prod or dev environment"), AllowedValues: []string{"production", "development"}, ValuesEditableBy: Ptr("org_actors"), @@ -223,7 +223,7 @@ func TestEnterpriseService_CreateOrUpdateCustomProperty(t *testing.T) { property, _, err := client.Enterprise.CreateOrUpdateCustomProperty(ctx, "e", "name", &CustomProperty{ ValueType: "single_select", Required: Ptr(true), - DefaultValue: Ptr("production"), + DefaultValue: "production", Description: Ptr("Prod or dev environment"), AllowedValues: []string{"production", "development"}, ValuesEditableBy: Ptr("org_actors"), @@ -236,7 +236,7 @@ func TestEnterpriseService_CreateOrUpdateCustomProperty(t *testing.T) { PropertyName: Ptr("name"), ValueType: "single_select", Required: Ptr(true), - DefaultValue: Ptr("production"), + DefaultValue: "production", Description: Ptr("Prod or dev environment"), AllowedValues: []string{"production", "development"}, ValuesEditableBy: Ptr("org_actors"), diff --git a/github/event_types_test.go b/github/event_types_test.go index 9ad223dca69..2c0cca2e07c 100644 --- a/github/event_types_test.go +++ b/github/event_types_test.go @@ -13735,7 +13735,7 @@ func TestCustomPropertyEvent_Marshal(t *testing.T) { ValueType: "single_select", SourceType: Ptr("enterprise"), Required: Ptr(true), - DefaultValue: Ptr("production"), + DefaultValue: "production", Description: Ptr("Prod or dev environment"), AllowedValues: []string{"production", "development"}, ValuesEditableBy: Ptr("org_actors"), diff --git a/github/github-accessors.go b/github/github-accessors.go index 0a8f83ee2e1..d3c0d0d1df7 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -6734,14 +6734,6 @@ func (c *CustomOrgRoles) GetUpdatedAt() Timestamp { return *c.UpdatedAt } -// GetDefaultValue returns the DefaultValue field if it's non-nil, zero value otherwise. -func (c *CustomProperty) GetDefaultValue() string { - if c == nil || c.DefaultValue == nil { - return "" - } - return *c.DefaultValue -} - // GetDescription returns the Description field if it's non-nil, zero value otherwise. func (c *CustomProperty) GetDescription() string { if c == nil || c.Description == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 3c78a1436b8..18237768776 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -8802,17 +8802,6 @@ func TestCustomOrgRoles_GetUpdatedAt(tt *testing.T) { c.GetUpdatedAt() } -func TestCustomProperty_GetDefaultValue(tt *testing.T) { - tt.Parallel() - var zeroValue string - c := &CustomProperty{DefaultValue: &zeroValue} - c.GetDefaultValue() - c = &CustomProperty{} - c.GetDefaultValue() - c = nil - c.GetDefaultValue() -} - func TestCustomProperty_GetDescription(tt *testing.T) { tt.Parallel() var zeroValue string diff --git a/github/orgs_properties.go b/github/orgs_properties.go index 257e765993b..7cf89db2de3 100644 --- a/github/orgs_properties.go +++ b/github/orgs_properties.go @@ -23,8 +23,8 @@ type CustomProperty struct { ValueType string `json:"value_type"` // Whether the property is required. Required *bool `json:"required,omitempty"` - // Default value of the property. - DefaultValue *string `json:"default_value,omitempty"` + // Default value of the property. Can be null, string or array of strings. + DefaultValue any `json:"default_value"` // Short description of the property. Description *string `json:"description,omitempty"` // An ordered list of the allowed values of the property. The property can have up to 200 diff --git a/github/orgs_properties_test.go b/github/orgs_properties_test.go index e8bf5fe6502..e99f0ee2e50 100644 --- a/github/orgs_properties_test.go +++ b/github/orgs_properties_test.go @@ -41,6 +41,11 @@ func TestOrganizationsService_GetAllCustomProperties(t *testing.T) { "property_name": "team", "value_type": "string", "description": "Team owning the repository" + }, + { + "property_name": "multi_select_property", + "value_type": "multi_select", + "default_value": ["production", "development"] } ]`) }) @@ -56,7 +61,7 @@ func TestOrganizationsService_GetAllCustomProperties(t *testing.T) { PropertyName: Ptr("name"), ValueType: "single_select", Required: Ptr(true), - DefaultValue: Ptr("production"), + DefaultValue: "production", Description: Ptr("Prod or dev environment"), AllowedValues: []string{"production", "development"}, ValuesEditableBy: Ptr("org_actors"), @@ -70,6 +75,11 @@ func TestOrganizationsService_GetAllCustomProperties(t *testing.T) { ValueType: "string", Description: Ptr("Team owning the repository"), }, + { + PropertyName: Ptr("multi_select_property"), + ValueType: "multi_select", + DefaultValue: []any{"production", "development"}, + }, } if !cmp.Equal(properties, want) { t.Errorf("Organizations.GetAllCustomProperties returned %+v, want %+v", properties, want) @@ -92,7 +102,11 @@ func TestOrganizationsService_CreateOrUpdateCustomProperties(t *testing.T) { mux.HandleFunc("/orgs/o/properties/schema", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "PATCH") - testBody(t, r, `{"properties":[{"property_name":"name","value_type":"single_select","required":true},{"property_name":"service","value_type":"string"}]}`+"\n") + testBody(t, r, fmt.Sprintf(`{"properties":[%s,%s,%s,%s]}`+"\n", + `{"property_name":"name","value_type":"single_select","required":true,"default_value":null}`, + `{"property_name":"service","value_type":"string","default_value":null}`, + `{"property_name":"multi_select_property","value_type":"multi_select","default_value":["production","development"]}`, + `{"property_name":"multi_select_property_null","value_type":"multi_select","default_value":null}`)) fmt.Fprint(w, `[ { "property_name": "name", @@ -102,6 +116,16 @@ func TestOrganizationsService_CreateOrUpdateCustomProperties(t *testing.T) { { "property_name": "service", "value_type": "string" + }, + { + "property_name": "multi_select_property", + "value_type": "multi_select", + "default_value": ["production", "development"] + }, + { + "property_name": "multi_select_property_null", + "value_type": "multi_select", + "default_value": null } ]`) }) @@ -117,6 +141,16 @@ func TestOrganizationsService_CreateOrUpdateCustomProperties(t *testing.T) { PropertyName: Ptr("service"), ValueType: "string", }, + { + PropertyName: Ptr("multi_select_property"), + ValueType: "multi_select", + DefaultValue: []any{"production", "development"}, + }, + { + PropertyName: Ptr("multi_select_property_null"), + ValueType: "multi_select", + DefaultValue: nil, + }, }) if err != nil { t.Errorf("Organizations.CreateOrUpdateCustomProperties returned error: %v", err) @@ -132,6 +166,16 @@ func TestOrganizationsService_CreateOrUpdateCustomProperties(t *testing.T) { PropertyName: Ptr("service"), ValueType: "string", }, + { + PropertyName: Ptr("multi_select_property"), + ValueType: "multi_select", + DefaultValue: []any{"production", "development"}, + }, + { + PropertyName: Ptr("multi_select_property_null"), + ValueType: "multi_select", + DefaultValue: nil, + }, } if !cmp.Equal(properties, want) { @@ -179,7 +223,7 @@ func TestOrganizationsService_GetCustomProperty(t *testing.T) { PropertyName: Ptr("name"), ValueType: "single_select", Required: Ptr(true), - DefaultValue: Ptr("production"), + DefaultValue: "production", Description: Ptr("Prod or dev environment"), AllowedValues: []string{"production", "development"}, ValuesEditableBy: Ptr("org_actors"), @@ -223,7 +267,7 @@ func TestOrganizationsService_CreateOrUpdateCustomProperty(t *testing.T) { property, _, err := client.Organizations.CreateOrUpdateCustomProperty(ctx, "o", "name", &CustomProperty{ ValueType: "single_select", Required: Ptr(true), - DefaultValue: Ptr("production"), + DefaultValue: "production", Description: Ptr("Prod or dev environment"), AllowedValues: []string{"production", "development"}, ValuesEditableBy: Ptr("org_actors"), @@ -236,7 +280,7 @@ func TestOrganizationsService_CreateOrUpdateCustomProperty(t *testing.T) { PropertyName: Ptr("name"), ValueType: "single_select", Required: Ptr(true), - DefaultValue: Ptr("production"), + DefaultValue: "production", Description: Ptr("Prod or dev environment"), AllowedValues: []string{"production", "development"}, ValuesEditableBy: Ptr("org_actors"),