From c7fba2c14add1730ab53deedbc99c0d1fc9ffb29 Mon Sep 17 00:00:00 2001 From: zyfy29 Date: Sat, 27 Sep 2025 12:40:28 +0900 Subject: [PATCH 1/4] refactor: Support array type for `DefaultValue` field --- github/enterprise_properties_test.go | 8 ++++---- github/event_types_test.go | 2 +- github/github-accessors.go | 8 -------- github/github-accessors_test.go | 11 ----------- github/orgs_properties.go | 4 ++-- github/orgs_properties_test.go | 18 ++++++++++++++---- 6 files changed, 21 insertions(+), 30 deletions(-) diff --git a/github/enterprise_properties_test.go b/github/enterprise_properties_test.go index 3155f9669bc..268a27eb0fb 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"), @@ -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..3dc8e4db0ed 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,omitempty"` // 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..7f7b9f95c07 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) @@ -179,7 +189,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 +233,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 +246,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"), From c9761dc7f9f748ce7351c2a67063f75ce2f1ed28 Mon Sep 17 00:00:00 2001 From: zyfy29 Date: Sat, 27 Sep 2025 22:53:46 +0900 Subject: [PATCH 2/4] fix: remove "omitempty" to "passed through `null` value --- github/orgs_properties.go | 2 +- github/orgs_properties_test.go | 32 +++++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/github/orgs_properties.go b/github/orgs_properties.go index 3dc8e4db0ed..7cf89db2de3 100644 --- a/github/orgs_properties.go +++ b/github/orgs_properties.go @@ -24,7 +24,7 @@ type CustomProperty struct { // Whether the property is required. Required *bool `json:"required,omitempty"` // Default value of the property. Can be null, string or array of strings. - DefaultValue any `json:"default_value,omitempty"` + 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 7f7b9f95c07..c3136ac236d 100644 --- a/github/orgs_properties_test.go +++ b/github/orgs_properties_test.go @@ -102,7 +102,7 @@ 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, `{"properties":[{"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}]}`+"\n") fmt.Fprint(w, `[ { "property_name": "name", @@ -112,6 +112,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 } ]`) }) @@ -127,6 +137,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) @@ -142,6 +162,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) { From ff8e35a6312a4b0ee862e0035155fe06f2147572 Mon Sep 17 00:00:00 2001 From: zyfy29 Date: Sat, 27 Sep 2025 22:56:59 +0900 Subject: [PATCH 3/4] style: use fmt.Sprintf to improve readability --- github/orgs_properties_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/github/orgs_properties_test.go b/github/orgs_properties_test.go index c3136ac236d..e99f0ee2e50 100644 --- a/github/orgs_properties_test.go +++ b/github/orgs_properties_test.go @@ -102,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,"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}]}`+"\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", From 6abfd6245f1109a0e8c712c3d394891f4e529490 Mon Sep 17 00:00:00 2001 From: zyfy29 Date: Sun, 28 Sep 2025 10:58:58 +0900 Subject: [PATCH 4/4] fix test case --- github/enterprise_properties_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/enterprise_properties_test.go b/github/enterprise_properties_test.go index 268a27eb0fb..c78c17e6d75 100644 --- a/github/enterprise_properties_test.go +++ b/github/enterprise_properties_test.go @@ -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",