From 65cfb359750e978e972dc52f94facc4a2ceb5e4c Mon Sep 17 00:00:00 2001 From: Dhananjay Mishra Date: Wed, 5 Nov 2025 03:48:53 +0000 Subject: [PATCH 01/11] add endpoint for organization's custom property and organization custom properties in an enterprise --- github/enterprise_custom_properties.go | 220 +++++++++++++++ github/enterprise_custom_properties_test.go | 94 +++++++ github/github-accessors.go | 80 ++++++ github/github-accessors_test.go | 110 ++++++++ github/organizations_custom_properties.go | 59 ++++ .../organizations_custom_properties_test.go | 264 ++++++++++++++++++ 6 files changed, 827 insertions(+) create mode 100644 github/enterprise_custom_properties.go create mode 100644 github/enterprise_custom_properties_test.go create mode 100644 github/organizations_custom_properties.go create mode 100644 github/organizations_custom_properties_test.go diff --git a/github/enterprise_custom_properties.go b/github/enterprise_custom_properties.go new file mode 100644 index 00000000000..062b6c5c90b --- /dev/null +++ b/github/enterprise_custom_properties.go @@ -0,0 +1,220 @@ +// Copyright 2025 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github + +import ( + "context" + "fmt" +) + +// Property represents a custom property definition in an enterprise. +type Property struct { + // Name of the custom property. + Name string `json:"name"` + // The URL that can be used to fetch, update, or delete info about this property via the API. + URL *string `json:"url,omitempty"` + // The source type of the property. + SourceType *string `json:"source_type,omitempty"` + // The type of the value for the property. + ValueType string `json:"value_type"` + // Whether the property is required. + Required *bool `json:"required,omitempty"` + // The default value for the property. + DefaultValue *string `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 allowed values. + AllowedValues []string `json:"allowed_values,omitempty"` + // Who can edit the values of the property. + ValuesEditableBy *string `json:"values_editable_by,omitempty"` +} + +// EnterpriseCustomPropertySchema represents the schema response for GetEnterpriseCustomPropertiesSchema. +type EnterpriseCustomPropertySchema struct { + // An ordered list of the custom property defined in the enterprise. + Properties []*Property `json:"properties,omitempty"` +} + +// PropertyValue represents the custom property values for an organization. +type PropertyValue struct { + // The name of the property + PropertyName *string `json:"property_name,omitempty"` + // The value assigned to the property + Value *string `json:"value,omitempty"` +} + +// CustomPropertiesValues represents the custom properties values for an organization within an enterprise. +type CustomPropertiesValues struct { + // The Organization ID that the custom property values will be applied to. + OrganizationID *int64 `json:"organization_id,omitempty"` + // The names of organizations that the custom property values will be applied to. + OrganizationLogin *string `json:"organization_login,omitempty"` + // List of custom property names and associated values to apply to the organizations. + Properties []*PropertyValue `json:"properties,omitempty"` +} + +// CustomPropertiesValuesUpdate represents the request to update custom property values for organizations within an enterprise. +type CustomPropertiesValuesUpdate struct { + // The names of organizations that the custom property values will be applied to. + // OrganizationLogin specifies the organization name when updating multiple organizations. + OrganizationLogin []string `json:"organization_login"` + // List of custom property names and associated values to apply to the organizations. + Properties []*PropertyValue `json:"properties"` +} + +// GetEnterpriseCustomPropertySchema gives all organization custom property definitions that are defined on an enterprise. +// +// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/custom-properties-for-orgs#get-organization-custom-properties-schema-for-an-enterprise +// +//meta:operation GET /enterprises/{enterprise}/org-properties/schema +func (s *EnterpriseService) GetEnterpriseCustomPropertySchema(ctx context.Context, enterprise string) (*EnterpriseCustomPropertySchema, *Response, error) { + u := fmt.Sprintf("enterprises/%v/org-properties/schema", enterprise) + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + var schema *EnterpriseCustomPropertySchema + resp, err := s.client.Do(ctx, req, &schema) + if err != nil { + return nil, resp, err + } + + return schema, resp, nil +} + +// UpdateEnterpriseCustomPropertySchema creates new or updates existing organization custom properties defined on an enterprise in a batch. +// +// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/custom-properties-for-orgs#create-or-update-organization-custom-property-definitions-on-an-enterprise +// +//meta:operation PATCH /enterprises/{enterprise}/org-properties/schema +func (s *EnterpriseService) UpdateEnterpriseCustomPropertySchema(ctx context.Context, enterprise string, schema *EnterpriseCustomPropertySchema) (*Response, error) { + u := fmt.Sprintf("enterprises/%v/org-properties/schema", enterprise) + req, err := s.client.NewRequest("PATCH", u, schema) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(ctx, req, nil) + if err != nil { + return resp, err + } + + return resp, nil +} + +// GetEnterpriseCustomProperty retrieves a specific organization custom property definition from an enterprise. +// +// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/custom-properties-for-orgs#get-an-organization-custom-property-definition-from-an-enterprise +// +//meta:operation GET /enterprises/{enterprise}/org-properties/schema/{custom_property_name} +func (s *EnterpriseService) GetEnterpriseCustomProperty(ctx context.Context, enterprise, customPropertyName string) (*Property, *Response, error) { + u := fmt.Sprintf("enterprises/%v/org-properties/schema/%v", enterprise, customPropertyName) + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + var property *Property + resp, err := s.client.Do(ctx, req, &property) + if err != nil { + return nil, resp, err + } + + return property, resp, nil +} + +// UpdateEnterpriseCustomProperty creates a new or updates an existing organization custom property definition that is defined on an enterprise. +// +// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/custom-properties-for-orgs#create-or-update-an-organization-custom-property-definition-on-an-enterprise +// +//meta:operation PUT /enterprises/{enterprise}/org-properties/schema/{custom_property_name} +func (s *EnterpriseService) UpdateEnterpriseCustomProperty(ctx context.Context, enterprise, customPropertyName string, property *Property) (*Response, error) { + u := fmt.Sprintf("enterprises/%v/org-properties/schema/%v", enterprise, customPropertyName) + req, err := s.client.NewRequest("PUT", u, property) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(ctx, req, nil) + if err != nil { + return resp, err + } + + return resp, nil +} + +// DeleteEnterpriseCustomProperty removes an organization custom property definition that is defined on an enterprise. +// +// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/custom-properties-for-orgs#remove-an-organization-custom-property-definition-from-an-enterprise +// +//meta:operation DELETE /enterprises/{enterprise}/org-properties/schema/{custom_property_name} +func (s *EnterpriseService) DeleteEnterpriseCustomProperty(ctx context.Context, enterprise, customPropertyName string) (*Response, error) { + u := fmt.Sprintf("enterprises/%v/org-properties/schema/%v", enterprise, customPropertyName) + req, err := s.client.NewRequest("DELETE", u, nil) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(ctx, req, nil) + if err != nil { + return resp, err + } + + return resp, nil +} + +// GetEnterpriseCustomPropertyValues lists enterprise organizations with all of their custom property values. +// Returns a list of organizations and their custom property values defined in the enterprise. +// +// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/custom-properties-for-orgs#list-custom-property-values-for-organizations-in-an-enterprise +// +//meta:operation GET /enterprises/{enterprise}/org-properties/values +func (s *EnterpriseService) GetEnterpriseCustomPropertyValues(ctx context.Context, enterprise string, opts *ListOptions) ([]*CustomPropertiesValues, *Response, error) { + u := fmt.Sprintf("enterprises/%v/org-properties/values", enterprise) + + u, err := addOptions(u, opts) + if err != nil { + return nil, nil, err + } + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + var values []*CustomPropertiesValues + resp, err := s.client.Do(ctx, req, &values) + if err != nil { + return nil, resp, err + } + + return values, resp, nil +} + +// UpdateEnterpriseCustomPropertyValues create or update custom property values for organizations in an enterprise. +// To remove a custom property value from an organization, set the property value to null. +// +// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/custom-properties-for-orgs#create-or-update-custom-property-values-for-organizations-in-an-enterprise +// +//meta:operation PATCH /enterprises/{enterprise}/org-properties/values +func (s *EnterpriseService) UpdateEnterpriseCustomPropertyValues(ctx context.Context, enterprise string, values CustomPropertiesValuesUpdate) (*Response, error) { + u := fmt.Sprintf("enterprises/%v/org-properties/values", enterprise) + req, err := s.client.NewRequest("PATCH", u, values) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(ctx, req, nil) + if err != nil { + return resp, err + } + + return resp, nil +} diff --git a/github/enterprise_custom_properties_test.go b/github/enterprise_custom_properties_test.go new file mode 100644 index 00000000000..1a75784d31f --- /dev/null +++ b/github/enterprise_custom_properties_test.go @@ -0,0 +1,94 @@ +// Copyright 2025 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github + +import ( + "fmt" + "net/http" + "testing" + + "github.com/google/go-cmp/cmp" +) + +func TestOrganizationsService_GetOrganizationCustomPropertyValues(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/organizations/o/org-properties/values", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `[{ + "property_name": "team", + "value": "core" + }, + { + "property_name": "level", + "value": "gold" + }]`) + }) + + ctx := t.Context() + got, _, err := client.Organizations.GetOrganizationCustomPropertyValues(ctx, "o") + if err != nil { + t.Errorf("Organizations.GetOrganizationCustomPropertyValues returned error: %v", err) + } + + want := []*PropertyValue{ + {PropertyName: Ptr("team"), Value: Ptr("core")}, + {PropertyName: Ptr("level"), Value: Ptr("gold")}, + } + + if !cmp.Equal(got, want) { + t.Errorf("Organizations.GetOrganizationCustomPropertyValues = %+v, want %+v", got, want) + } + + const methodName = "GetOrganizationCustomPropertyValues" + + testBadOptions(t, methodName, func() error { + _, _, err := client.Organizations.GetOrganizationCustomPropertyValues(ctx, "\n") + return err + }) + + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + got, resp, err := client.Organizations.GetOrganizationCustomPropertyValues(ctx, "o") + if got != nil { + t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) + } + return resp, err + }) +} + +func TestOrganizationsService_UpdateOrganizationCustomPropertyValues(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/organizations/o/org-properties/values", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "PATCH") + fmt.Fprint(w, `{}`) + }) + + ctx := t.Context() + values := []*PropertyValue{ + {PropertyName: Ptr("team"), Value: Ptr("core")}, + {PropertyName: Ptr("level"), Value: Ptr("gold")}, + } + + props := OrganizationCustomPropertyValues{ + Properties: values, + } + _, err := client.Organizations.UpdateOrganizationCustomPropertyValues(ctx, "o", props) + if err != nil { + t.Errorf("Organizations.UpdateOrganizationCustomPropertyValues returned error: %v", err) + } + + const methodName = "UpdateOrganizationCustomPropertyValues" + testBadOptions(t, methodName, func() error { + _, err := client.Organizations.UpdateOrganizationCustomPropertyValues(ctx, "\n", props) + return err + }) + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + return client.Organizations.UpdateOrganizationCustomPropertyValues(ctx, "o", props) + }) +} diff --git a/github/github-accessors.go b/github/github-accessors.go index 7844b5b36d0..5ea9ac89957 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -6782,6 +6782,22 @@ func (c *CustomPatternBackfillScan) GetPatternSlug() string { return *c.PatternSlug } +// GetOrganizationID returns the OrganizationID field if it's non-nil, zero value otherwise. +func (c *CustomPropertiesValues) GetOrganizationID() int64 { + if c == nil || c.OrganizationID == nil { + return 0 + } + return *c.OrganizationID +} + +// GetOrganizationLogin returns the OrganizationLogin field if it's non-nil, zero value otherwise. +func (c *CustomPropertiesValues) GetOrganizationLogin() string { + if c == nil || c.OrganizationLogin == nil { + return "" + } + return *c.OrganizationLogin +} + // GetDefaultValue returns the DefaultValue field if it's non-nil, zero value otherwise. func (c *CustomProperty) GetDefaultValue() string { if c == nil || c.DefaultValue == nil { @@ -19446,6 +19462,70 @@ func (p *ProjectV2ItemEvent) GetSender() *User { return p.Sender } +// GetDefaultValue returns the DefaultValue field if it's non-nil, zero value otherwise. +func (p *Property) GetDefaultValue() string { + if p == nil || p.DefaultValue == nil { + return "" + } + return *p.DefaultValue +} + +// GetDescription returns the Description field if it's non-nil, zero value otherwise. +func (p *Property) GetDescription() string { + if p == nil || p.Description == nil { + return "" + } + return *p.Description +} + +// GetRequired returns the Required field if it's non-nil, zero value otherwise. +func (p *Property) GetRequired() bool { + if p == nil || p.Required == nil { + return false + } + return *p.Required +} + +// GetSourceType returns the SourceType field if it's non-nil, zero value otherwise. +func (p *Property) GetSourceType() string { + if p == nil || p.SourceType == nil { + return "" + } + return *p.SourceType +} + +// GetURL returns the URL field if it's non-nil, zero value otherwise. +func (p *Property) GetURL() string { + if p == nil || p.URL == nil { + return "" + } + return *p.URL +} + +// GetValuesEditableBy returns the ValuesEditableBy field if it's non-nil, zero value otherwise. +func (p *Property) GetValuesEditableBy() string { + if p == nil || p.ValuesEditableBy == nil { + return "" + } + return *p.ValuesEditableBy +} + +// GetPropertyName returns the PropertyName field if it's non-nil, zero value otherwise. +func (p *PropertyValue) GetPropertyName() string { + if p == nil || p.PropertyName == nil { + return "" + } + return *p.PropertyName +} + +// GetValue returns the Value field if it's non-nil, zero value otherwise. +func (p *PropertyValue) GetValue() string { + if p == nil || p.Value == nil { + return "" + } + return *p.Value +} + // GetAllowDeletions returns the AllowDeletions field. func (p *Protection) GetAllowDeletions() *AllowDeletions { if p == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index c6ece7ee50a..a012fd88a70 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -8868,6 +8868,28 @@ func TestCustomPatternBackfillScan_GetPatternSlug(tt *testing.T) { c.GetPatternSlug() } +func TestCustomPropertiesValues_GetOrganizationID(tt *testing.T) { + tt.Parallel() + var zeroValue int64 + c := &CustomPropertiesValues{OrganizationID: &zeroValue} + c.GetOrganizationID() + c = &CustomPropertiesValues{} + c.GetOrganizationID() + c = nil + c.GetOrganizationID() +} + +func TestCustomPropertiesValues_GetOrganizationLogin(tt *testing.T) { + tt.Parallel() + var zeroValue string + c := &CustomPropertiesValues{OrganizationLogin: &zeroValue} + c.GetOrganizationLogin() + c = &CustomPropertiesValues{} + c.GetOrganizationLogin() + c = nil + c.GetOrganizationLogin() +} + func TestCustomProperty_GetDefaultValue(tt *testing.T) { tt.Parallel() var zeroValue string @@ -25249,6 +25271,94 @@ func TestProjectV2ItemEvent_GetSender(tt *testing.T) { p.GetSender() } +func TestProperty_GetDefaultValue(tt *testing.T) { + tt.Parallel() + var zeroValue string + p := &Property{DefaultValue: &zeroValue} + p.GetDefaultValue() + p = &Property{} + p.GetDefaultValue() + p = nil + p.GetDefaultValue() +} + +func TestProperty_GetDescription(tt *testing.T) { + tt.Parallel() + var zeroValue string + p := &Property{Description: &zeroValue} + p.GetDescription() + p = &Property{} + p.GetDescription() + p = nil + p.GetDescription() +} + +func TestProperty_GetRequired(tt *testing.T) { + tt.Parallel() + var zeroValue bool + p := &Property{Required: &zeroValue} + p.GetRequired() + p = &Property{} + p.GetRequired() + p = nil + p.GetRequired() +} + +func TestProperty_GetSourceType(tt *testing.T) { + tt.Parallel() + var zeroValue string + p := &Property{SourceType: &zeroValue} + p.GetSourceType() + p = &Property{} + p.GetSourceType() + p = nil + p.GetSourceType() +} + +func TestProperty_GetURL(tt *testing.T) { + tt.Parallel() + var zeroValue string + p := &Property{URL: &zeroValue} + p.GetURL() + p = &Property{} + p.GetURL() + p = nil + p.GetURL() +} + +func TestProperty_GetValuesEditableBy(tt *testing.T) { + tt.Parallel() + var zeroValue string + p := &Property{ValuesEditableBy: &zeroValue} + p.GetValuesEditableBy() + p = &Property{} + p.GetValuesEditableBy() + p = nil + p.GetValuesEditableBy() +} + +func TestPropertyValue_GetPropertyName(tt *testing.T) { + tt.Parallel() + var zeroValue string + p := &PropertyValue{PropertyName: &zeroValue} + p.GetPropertyName() + p = &PropertyValue{} + p.GetPropertyName() + p = nil + p.GetPropertyName() +} + +func TestPropertyValue_GetValue(tt *testing.T) { + tt.Parallel() + var zeroValue string + p := &PropertyValue{Value: &zeroValue} + p.GetValue() + p = &PropertyValue{} + p.GetValue() + p = nil + p.GetValue() +} + func TestProtection_GetAllowDeletions(tt *testing.T) { tt.Parallel() p := &Protection{} diff --git a/github/organizations_custom_properties.go b/github/organizations_custom_properties.go new file mode 100644 index 00000000000..6274c96bbcc --- /dev/null +++ b/github/organizations_custom_properties.go @@ -0,0 +1,59 @@ +// Copyright 2025 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github + +import ( + "context" + "fmt" +) + +// OrganizationCustomPropertyValues represents the custom property values for an organization. +type OrganizationCustomPropertyValues struct { + // List of custom property names and associated values to apply to the organization. + Properties []*PropertyValue `json:"properties,omitempty"` +} + +// GetOrganizationCustomPropertyValues returns all custom property names and their values for an organization. +// +// GitHub API docs: https://docs.github.com/rest/orgs/custom-properties-for-orgs#get-all-custom-property-values-for-an-organization +// +//meta:operation GET /organizations/{org}/org-properties/values +func (s *OrganizationsService) GetOrganizationCustomPropertyValues(ctx context.Context, org string) ([]*PropertyValue, *Response, error) { + u := fmt.Sprintf("organizations/%v/org-properties/values", org) + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + var values []*PropertyValue + resp, err := s.client.Do(ctx, req, &values) + if err != nil { + return nil, resp, err + } + + return values, resp, nil +} + +// UpdateOrganizationCustomPropertyValues creates or updates custom property values for an organization. +// +// GitHub API docs: https://docs.github.com/rest/orgs/custom-properties-for-orgs#create-or-update-custom-property-values-for-an-organization +// +//meta:operation PATCH /organizations/{org}/org-properties/values +func (s *OrganizationsService) UpdateOrganizationCustomPropertyValues(ctx context.Context, org string, properties OrganizationCustomPropertyValues) (*Response, error) { + u := fmt.Sprintf("organizations/%v/org-properties/values", org) + req, err := s.client.NewRequest("PATCH", u, properties) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(ctx, req, nil) + if err != nil { + return resp, err + } + + return resp, nil +} diff --git a/github/organizations_custom_properties_test.go b/github/organizations_custom_properties_test.go new file mode 100644 index 00000000000..9d3cab1620b --- /dev/null +++ b/github/organizations_custom_properties_test.go @@ -0,0 +1,264 @@ +// Copyright 2025 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github + +import ( + "fmt" + "net/http" + "testing" + + "github.com/google/go-cmp/cmp" +) + +func TestEnterpriseService_GetEnterpriseCustomPropertySchema(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/enterprises/e/org-properties/schema", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `{ + "properties": [{ + "name": "team", + "value_type": "string", + "description": "Team name" + }] + }`) + }) + + ctx := t.Context() + got, _, err := client.Enterprise.GetEnterpriseCustomPropertySchema(ctx, "e") + if err != nil { + t.Errorf("Enterprise.GetEnterpriseCustomPropertySchema returned error: %v", err) + } + + want := &EnterpriseCustomPropertySchema{ + Properties: []*Property{ + { + Name: "team", + ValueType: "string", + Description: Ptr("Team name"), + }, + }, + } + + if !cmp.Equal(got, want) { + t.Errorf("Enterprise.GetEnterpriseCustomPropertySchema = %+v, want %+v", got, want) + } + + const methodName = "GetEnterpriseCustomPropertySchema" + testBadOptions(t, methodName, func() error { + _, _, err := client.Enterprise.GetEnterpriseCustomPropertySchema(ctx, "\n") + return err + }) + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + got, resp, err := client.Enterprise.GetEnterpriseCustomPropertySchema(ctx, "e") + if got != nil { + t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) + } + return resp, err + }) +} + +func TestEnterpriseService_UpdateEnterpriseCustomPropertySchema(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/enterprises/e/org-properties/schema", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "PATCH") + fmt.Fprint(w, `{}`) + }) + + ctx := t.Context() + schema := &EnterpriseCustomPropertySchema{ + Properties: []*Property{{Name: "team"}}, + } + _, err := client.Enterprise.UpdateEnterpriseCustomPropertySchema(ctx, "e", schema) + if err != nil { + t.Errorf("Enterprise.UpdateEnterpriseCustomPropertySchema returned error: %v", err) + } + + const methodName = "UpdateEnterpriseCustomPropertySchema" + testBadOptions(t, methodName, func() error { + _, err := client.Enterprise.UpdateEnterpriseCustomPropertySchema(ctx, "\n", schema) + return err + }) + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + return client.Enterprise.UpdateEnterpriseCustomPropertySchema(ctx, "e", schema) + }) +} + +func TestEnterpriseService_GetEnterpriseCustomProperty(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/enterprises/e/org-properties/schema/prop", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `{ + "name": "team", + "value_type": "string", + "description": "Team name" + }`) + }) + + ctx := t.Context() + got, _, err := client.Enterprise.GetEnterpriseCustomProperty(ctx, "e", "prop") + if err != nil { + t.Errorf("Enterprise.GetEnterpriseCustomProperty returned error: %v", err) + } + + want := &Property{ + Name: "team", + ValueType: "string", + Description: Ptr("Team name"), + } + + if !cmp.Equal(got, want) { + t.Errorf("Enterprise.GetEnterpriseCustomProperty = %+v, want %+v", got, want) + } + + const methodName = "GetEnterpriseCustomProperty" + testBadOptions(t, methodName, func() error { + _, _, err := client.Enterprise.GetEnterpriseCustomProperty(ctx, "\n", "prop") + return err + }) + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + got, resp, err := client.Enterprise.GetEnterpriseCustomProperty(ctx, "e", "prop") + if got != nil { + t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) + } + return resp, err + }) +} + +func TestEnterpriseService_UpdateEnterpriseCustomProperty(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/enterprises/e/org-properties/schema/prop", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "PUT") + fmt.Fprint(w, `{}`) + }) + + ctx := t.Context() + property := &Property{Name: "team"} + _, err := client.Enterprise.UpdateEnterpriseCustomProperty(ctx, "e", "prop", property) + if err != nil { + t.Errorf("Enterprise.UpdateEnterpriseCustomProperty returned error: %v", err) + } + + const methodName = "UpdateEnterpriseCustomProperty" + testBadOptions(t, methodName, func() error { + _, err := client.Enterprise.UpdateEnterpriseCustomProperty(ctx, "\n", "prop", property) + return err + }) + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + return client.Enterprise.UpdateEnterpriseCustomProperty(ctx, "e", "prop", property) + }) +} + +func TestEnterpriseService_DeleteEnterpriseCustomProperty(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/enterprises/e/org-properties/schema/prop", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "DELETE") + w.WriteHeader(http.StatusNoContent) + }) + + ctx := t.Context() + _, err := client.Enterprise.DeleteEnterpriseCustomProperty(ctx, "e", "prop") + if err != nil { + t.Errorf("Enterprise.DeleteEnterpriseCustomProperty returned error: %v", err) + } + + const methodName = "DeleteEnterpriseCustomProperty" + testBadOptions(t, methodName, func() error { + _, err := client.Enterprise.DeleteEnterpriseCustomProperty(ctx, "\n", "prop") + return err + }) + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + return client.Enterprise.DeleteEnterpriseCustomProperty(ctx, "e", "prop") + }) +} + +func TestEnterpriseService_GetEnterpriseCustomPropertyValues(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/enterprises/e/org-properties/values", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `[{ + "organization_id": 1, + "organization_login": "org1", + "properties": [{"property_name": "team", "value": "core"}] + }]`) + }) + + ctx := t.Context() + got, _, err := client.Enterprise.GetEnterpriseCustomPropertyValues(ctx, "e", nil) + if err != nil { + t.Errorf("Enterprise.GetEnterpriseCustomPropertyValues returned error: %v", err) + } + + want := []*CustomPropertiesValues{ + { + OrganizationID: Ptr(int64(1)), + OrganizationLogin: Ptr("org1"), + Properties: []*PropertyValue{ + {PropertyName: Ptr("team"), Value: Ptr("core")}, + }, + }, + } + + if !cmp.Equal(got, want) { + t.Errorf("Enterprise.GetEnterpriseCustomPropertyValues = %+v, want %+v", got, want) + } + + const methodName = "GetEnterpriseCustomPropertyValues" + testBadOptions(t, methodName, func() error { + _, _, err := client.Enterprise.GetEnterpriseCustomPropertyValues(ctx, "\n", nil) + return err + }) + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + got, resp, err := client.Enterprise.GetEnterpriseCustomPropertyValues(ctx, "e", nil) + if got != nil { + t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) + } + return resp, err + }) +} + +func TestEnterpriseService_UpdateEnterpriseCustomPropertyValues(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/enterprises/e/org-properties/values", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "PATCH") + fmt.Fprint(w, `{}`) + }) + + ctx := t.Context() + values := []*PropertyValue{{PropertyName: Ptr("team"), Value: Ptr("core")}} + orgs := []string{"org1"} + + opts := CustomPropertiesValuesUpdate{ + OrganizationLogin: orgs, + Properties: values, + } + _, err := client.Enterprise.UpdateEnterpriseCustomPropertyValues(ctx, "e", opts) + if err != nil { + t.Errorf("Enterprise.UpdateEnterpriseCustomPropertyValues returned error: %v", err) + } + + const methodName = "UpdateEnterpriseCustomPropertyValues" + testBadOptions(t, methodName, func() error { + _, err := client.Enterprise.UpdateEnterpriseCustomPropertyValues(ctx, "\n", opts) + return err + }) + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + return client.Enterprise.UpdateEnterpriseCustomPropertyValues(ctx, "e", opts) + }) +} From 1a6a82337eba885c004988ef7e2ab0ab88f85542 Mon Sep 17 00:00:00 2001 From: Dhananjay Mishra Date: Wed, 5 Nov 2025 06:52:23 +0000 Subject: [PATCH 02/11] add OrganizationProperty to enterprise rule and change struct and method names --- github/enterprise_custom_properties.go | 16 +++---- github/enterprise_custom_properties_test.go | 12 +++--- github/github-accessors.go | 16 +++++++ github/github-accessors_test.go | 19 +++++++++ github/organizations_custom_properties.go | 4 +- .../organizations_custom_properties_test.go | 42 +++++++++---------- github/rules.go | 26 +++++++++--- 7 files changed, 92 insertions(+), 43 deletions(-) diff --git a/github/enterprise_custom_properties.go b/github/enterprise_custom_properties.go index 062b6c5c90b..b0633dc814b 100644 --- a/github/enterprise_custom_properties.go +++ b/github/enterprise_custom_properties.go @@ -57,8 +57,8 @@ type CustomPropertiesValues struct { Properties []*PropertyValue `json:"properties,omitempty"` } -// CustomPropertiesValuesUpdate represents the request to update custom property values for organizations within an enterprise. -type CustomPropertiesValuesUpdate struct { +// EnterpriseCustomPropertyValues represents the request to update custom property values for organizations within an enterprise. +type EnterpriseCustomPropertyValues struct { // The names of organizations that the custom property values will be applied to. // OrganizationLogin specifies the organization name when updating multiple organizations. OrganizationLogin []string `json:"organization_login"` @@ -88,12 +88,12 @@ func (s *EnterpriseService) GetEnterpriseCustomPropertySchema(ctx context.Contex return schema, resp, nil } -// UpdateEnterpriseCustomPropertySchema creates new or updates existing organization custom properties defined on an enterprise in a batch. +// CreateOrUpdateEnterpriseCustomPropertySchema creates new or updates existing organization custom properties defined on an enterprise in a batch. // // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/custom-properties-for-orgs#create-or-update-organization-custom-property-definitions-on-an-enterprise // //meta:operation PATCH /enterprises/{enterprise}/org-properties/schema -func (s *EnterpriseService) UpdateEnterpriseCustomPropertySchema(ctx context.Context, enterprise string, schema *EnterpriseCustomPropertySchema) (*Response, error) { +func (s *EnterpriseService) CreateOrUpdateEnterpriseCustomPropertySchema(ctx context.Context, enterprise string, schema EnterpriseCustomPropertySchema) (*Response, error) { u := fmt.Sprintf("enterprises/%v/org-properties/schema", enterprise) req, err := s.client.NewRequest("PATCH", u, schema) if err != nil { @@ -130,12 +130,12 @@ func (s *EnterpriseService) GetEnterpriseCustomProperty(ctx context.Context, ent return property, resp, nil } -// UpdateEnterpriseCustomProperty creates a new or updates an existing organization custom property definition that is defined on an enterprise. +// CreateOrUpdateEnterpriseCustomProperty creates a new or updates an existing organization custom property definition that is defined on an enterprise. // // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/custom-properties-for-orgs#create-or-update-an-organization-custom-property-definition-on-an-enterprise // //meta:operation PUT /enterprises/{enterprise}/org-properties/schema/{custom_property_name} -func (s *EnterpriseService) UpdateEnterpriseCustomProperty(ctx context.Context, enterprise, customPropertyName string, property *Property) (*Response, error) { +func (s *EnterpriseService) CreateOrUpdateEnterpriseCustomProperty(ctx context.Context, enterprise, customPropertyName string, property Property) (*Response, error) { u := fmt.Sprintf("enterprises/%v/org-properties/schema/%v", enterprise, customPropertyName) req, err := s.client.NewRequest("PUT", u, property) if err != nil { @@ -198,13 +198,13 @@ func (s *EnterpriseService) GetEnterpriseCustomPropertyValues(ctx context.Contex return values, resp, nil } -// UpdateEnterpriseCustomPropertyValues create or update custom property values for organizations in an enterprise. +// CreateOrUpdateEnterpriseCustomPropertyValues create or update custom property values for organizations in an enterprise. // To remove a custom property value from an organization, set the property value to null. // // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/custom-properties-for-orgs#create-or-update-custom-property-values-for-organizations-in-an-enterprise // //meta:operation PATCH /enterprises/{enterprise}/org-properties/values -func (s *EnterpriseService) UpdateEnterpriseCustomPropertyValues(ctx context.Context, enterprise string, values CustomPropertiesValuesUpdate) (*Response, error) { +func (s *EnterpriseService) CreateOrUpdateEnterpriseCustomPropertyValues(ctx context.Context, enterprise string, values EnterpriseCustomPropertyValues) (*Response, error) { u := fmt.Sprintf("enterprises/%v/org-properties/values", enterprise) req, err := s.client.NewRequest("PATCH", u, values) if err != nil { diff --git a/github/enterprise_custom_properties_test.go b/github/enterprise_custom_properties_test.go index 1a75784d31f..8fe94ca58fd 100644 --- a/github/enterprise_custom_properties_test.go +++ b/github/enterprise_custom_properties_test.go @@ -60,7 +60,7 @@ func TestOrganizationsService_GetOrganizationCustomPropertyValues(t *testing.T) }) } -func TestOrganizationsService_UpdateOrganizationCustomPropertyValues(t *testing.T) { +func TestOrganizationsService_CreateOrUpdateOrgCustomPropertyValues(t *testing.T) { t.Parallel() client, mux, _ := setup(t) @@ -78,17 +78,17 @@ func TestOrganizationsService_UpdateOrganizationCustomPropertyValues(t *testing. props := OrganizationCustomPropertyValues{ Properties: values, } - _, err := client.Organizations.UpdateOrganizationCustomPropertyValues(ctx, "o", props) + _, err := client.Organizations.CreateOrUpdateOrgCustomPropertyValues(ctx, "o", props) if err != nil { - t.Errorf("Organizations.UpdateOrganizationCustomPropertyValues returned error: %v", err) + t.Errorf("Organizations.CreateOrUpdateOrgCustomPropertyValues returned error: %v", err) } - const methodName = "UpdateOrganizationCustomPropertyValues" + const methodName = "CreateOrUpdateOrgCustomPropertyValues" testBadOptions(t, methodName, func() error { - _, err := client.Organizations.UpdateOrganizationCustomPropertyValues(ctx, "\n", props) + _, err := client.Organizations.CreateOrUpdateOrgCustomPropertyValues(ctx, "\n", props) return err }) testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - return client.Organizations.UpdateOrganizationCustomPropertyValues(ctx, "o", props) + return client.Organizations.CreateOrUpdateOrgCustomPropertyValues(ctx, "o", props) }) } diff --git a/github/github-accessors.go b/github/github-accessors.go index 5ea9ac89957..2ce8317a0d4 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -24598,6 +24598,14 @@ func (r *RepositoryRulesetConditions) GetOrganizationName() *RepositoryRulesetOr return r.OrganizationName } +// GetOrganizationProperty returns the OrganizationProperty field. +func (r *RepositoryRulesetConditions) GetOrganizationProperty() *RepositoryRulesetOrganizationPropertyConditionParameters { + if r == nil { + return nil + } + return r.OrganizationProperty +} + // GetRefName returns the RefName field. func (r *RepositoryRulesetConditions) GetRefName() *RepositoryRulesetRefConditionParameters { if r == nil { @@ -24718,6 +24726,14 @@ func (r *RepositoryRulesetLinks) GetSelf() *RepositoryRulesetLink { return r.Self } +// GetSource returns the Source field if it's non-nil, zero value otherwise. +func (r *RepositoryRulesetOrganizationPropertyTargetParameters) GetSource() string { + if r == nil || r.Source == nil { + return "" + } + return *r.Source +} + // GetProtected returns the Protected field if it's non-nil, zero value otherwise. func (r *RepositoryRulesetRepositoryNamesConditionParameters) GetProtected() bool { if r == nil || r.Protected == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index a012fd88a70..264bbd02345 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -31787,6 +31787,14 @@ func TestRepositoryRulesetConditions_GetOrganizationName(tt *testing.T) { r.GetOrganizationName() } +func TestRepositoryRulesetConditions_GetOrganizationProperty(tt *testing.T) { + tt.Parallel() + r := &RepositoryRulesetConditions{} + r.GetOrganizationProperty() + r = nil + r.GetOrganizationProperty() +} + func TestRepositoryRulesetConditions_GetRefName(tt *testing.T) { tt.Parallel() r := &RepositoryRulesetConditions{} @@ -31913,6 +31921,17 @@ func TestRepositoryRulesetLinks_GetSelf(tt *testing.T) { r.GetSelf() } +func TestRepositoryRulesetOrganizationPropertyTargetParameters_GetSource(tt *testing.T) { + tt.Parallel() + var zeroValue string + r := &RepositoryRulesetOrganizationPropertyTargetParameters{Source: &zeroValue} + r.GetSource() + r = &RepositoryRulesetOrganizationPropertyTargetParameters{} + r.GetSource() + r = nil + r.GetSource() +} + func TestRepositoryRulesetRepositoryNamesConditionParameters_GetProtected(tt *testing.T) { tt.Parallel() var zeroValue bool diff --git a/github/organizations_custom_properties.go b/github/organizations_custom_properties.go index 6274c96bbcc..b63f720cd6a 100644 --- a/github/organizations_custom_properties.go +++ b/github/organizations_custom_properties.go @@ -38,12 +38,12 @@ func (s *OrganizationsService) GetOrganizationCustomPropertyValues(ctx context.C return values, resp, nil } -// UpdateOrganizationCustomPropertyValues creates or updates custom property values for an organization. +// CreateOrUpdateOrgCustomPropertyValues creates or updates custom property values for an organization. // // GitHub API docs: https://docs.github.com/rest/orgs/custom-properties-for-orgs#create-or-update-custom-property-values-for-an-organization // //meta:operation PATCH /organizations/{org}/org-properties/values -func (s *OrganizationsService) UpdateOrganizationCustomPropertyValues(ctx context.Context, org string, properties OrganizationCustomPropertyValues) (*Response, error) { +func (s *OrganizationsService) CreateOrUpdateOrgCustomPropertyValues(ctx context.Context, org string, properties OrganizationCustomPropertyValues) (*Response, error) { u := fmt.Sprintf("organizations/%v/org-properties/values", org) req, err := s.client.NewRequest("PATCH", u, properties) if err != nil { diff --git a/github/organizations_custom_properties_test.go b/github/organizations_custom_properties_test.go index 9d3cab1620b..22253978a38 100644 --- a/github/organizations_custom_properties_test.go +++ b/github/organizations_custom_properties_test.go @@ -62,7 +62,7 @@ func TestEnterpriseService_GetEnterpriseCustomPropertySchema(t *testing.T) { }) } -func TestEnterpriseService_UpdateEnterpriseCustomPropertySchema(t *testing.T) { +func TestEnterpriseService_CreateOrUpdateEnterpriseCustomPropertySchema(t *testing.T) { t.Parallel() client, mux, _ := setup(t) @@ -72,21 +72,21 @@ func TestEnterpriseService_UpdateEnterpriseCustomPropertySchema(t *testing.T) { }) ctx := t.Context() - schema := &EnterpriseCustomPropertySchema{ + schema := EnterpriseCustomPropertySchema{ Properties: []*Property{{Name: "team"}}, } - _, err := client.Enterprise.UpdateEnterpriseCustomPropertySchema(ctx, "e", schema) + _, err := client.Enterprise.CreateOrUpdateEnterpriseCustomPropertySchema(ctx, "e", schema) if err != nil { - t.Errorf("Enterprise.UpdateEnterpriseCustomPropertySchema returned error: %v", err) + t.Errorf("Enterprise.CreateOrUpdateEnterpriseCustomPropertySchema returned error: %v", err) } - const methodName = "UpdateEnterpriseCustomPropertySchema" + const methodName = "CreateOrUpdateEnterpriseCustomPropertySchema" testBadOptions(t, methodName, func() error { - _, err := client.Enterprise.UpdateEnterpriseCustomPropertySchema(ctx, "\n", schema) + _, err := client.Enterprise.CreateOrUpdateEnterpriseCustomPropertySchema(ctx, "\n", schema) return err }) testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - return client.Enterprise.UpdateEnterpriseCustomPropertySchema(ctx, "e", schema) + return client.Enterprise.CreateOrUpdateEnterpriseCustomPropertySchema(ctx, "e", schema) }) } @@ -133,7 +133,7 @@ func TestEnterpriseService_GetEnterpriseCustomProperty(t *testing.T) { }) } -func TestEnterpriseService_UpdateEnterpriseCustomProperty(t *testing.T) { +func TestEnterpriseService_CreateOrUpdateEnterpriseCustomProperty(t *testing.T) { t.Parallel() client, mux, _ := setup(t) @@ -143,19 +143,19 @@ func TestEnterpriseService_UpdateEnterpriseCustomProperty(t *testing.T) { }) ctx := t.Context() - property := &Property{Name: "team"} - _, err := client.Enterprise.UpdateEnterpriseCustomProperty(ctx, "e", "prop", property) + property := Property{Name: "team"} + _, err := client.Enterprise.CreateOrUpdateEnterpriseCustomProperty(ctx, "e", "prop", property) if err != nil { - t.Errorf("Enterprise.UpdateEnterpriseCustomProperty returned error: %v", err) + t.Errorf("Enterprise.CreateOrUpdateEnterpriseCustomProperty returned error: %v", err) } - const methodName = "UpdateEnterpriseCustomProperty" + const methodName = "CreateOrUpdateEnterpriseCustomProperty" testBadOptions(t, methodName, func() error { - _, err := client.Enterprise.UpdateEnterpriseCustomProperty(ctx, "\n", "prop", property) + _, err := client.Enterprise.CreateOrUpdateEnterpriseCustomProperty(ctx, "\n", "prop", property) return err }) testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - return client.Enterprise.UpdateEnterpriseCustomProperty(ctx, "e", "prop", property) + return client.Enterprise.CreateOrUpdateEnterpriseCustomProperty(ctx, "e", "prop", property) }) } @@ -231,7 +231,7 @@ func TestEnterpriseService_GetEnterpriseCustomPropertyValues(t *testing.T) { }) } -func TestEnterpriseService_UpdateEnterpriseCustomPropertyValues(t *testing.T) { +func TestEnterpriseService_CreateOrUpdateEnterpriseCustomPropertyValues(t *testing.T) { t.Parallel() client, mux, _ := setup(t) @@ -244,21 +244,21 @@ func TestEnterpriseService_UpdateEnterpriseCustomPropertyValues(t *testing.T) { values := []*PropertyValue{{PropertyName: Ptr("team"), Value: Ptr("core")}} orgs := []string{"org1"} - opts := CustomPropertiesValuesUpdate{ + opts := EnterpriseCustomPropertyValues{ OrganizationLogin: orgs, Properties: values, } - _, err := client.Enterprise.UpdateEnterpriseCustomPropertyValues(ctx, "e", opts) + _, err := client.Enterprise.CreateOrUpdateEnterpriseCustomPropertyValues(ctx, "e", opts) if err != nil { - t.Errorf("Enterprise.UpdateEnterpriseCustomPropertyValues returned error: %v", err) + t.Errorf("Enterprise.CreateOrUpdateEnterpriseCustomPropertyValues returned error: %v", err) } - const methodName = "UpdateEnterpriseCustomPropertyValues" + const methodName = "CreateOrUpdateEnterpriseCustomPropertyValues" testBadOptions(t, methodName, func() error { - _, err := client.Enterprise.UpdateEnterpriseCustomPropertyValues(ctx, "\n", opts) + _, err := client.Enterprise.CreateOrUpdateEnterpriseCustomPropertyValues(ctx, "\n", opts) return err }) testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - return client.Enterprise.UpdateEnterpriseCustomPropertyValues(ctx, "e", opts) + return client.Enterprise.CreateOrUpdateEnterpriseCustomPropertyValues(ctx, "e", opts) }) } diff --git a/github/rules.go b/github/rules.go index 7b474f00e68..a381976421f 100644 --- a/github/rules.go +++ b/github/rules.go @@ -203,12 +203,13 @@ type RepositoryRulesetLink struct { // RepositoryRulesetConditions represents the conditions object in a ruleset. // Set either RepositoryName or RepositoryID or RepositoryProperty, not more than one. type RepositoryRulesetConditions struct { - RefName *RepositoryRulesetRefConditionParameters `json:"ref_name,omitempty"` - RepositoryID *RepositoryRulesetRepositoryIDsConditionParameters `json:"repository_id,omitempty"` - RepositoryName *RepositoryRulesetRepositoryNamesConditionParameters `json:"repository_name,omitempty"` - RepositoryProperty *RepositoryRulesetRepositoryPropertyConditionParameters `json:"repository_property,omitempty"` - OrganizationID *RepositoryRulesetOrganizationIDsConditionParameters `json:"organization_id,omitempty"` - OrganizationName *RepositoryRulesetOrganizationNamesConditionParameters `json:"organization_name,omitempty"` + RefName *RepositoryRulesetRefConditionParameters `json:"ref_name,omitempty"` + RepositoryID *RepositoryRulesetRepositoryIDsConditionParameters `json:"repository_id,omitempty"` + RepositoryName *RepositoryRulesetRepositoryNamesConditionParameters `json:"repository_name,omitempty"` + RepositoryProperty *RepositoryRulesetRepositoryPropertyConditionParameters `json:"repository_property,omitempty"` + OrganizationID *RepositoryRulesetOrganizationIDsConditionParameters `json:"organization_id,omitempty"` + OrganizationName *RepositoryRulesetOrganizationNamesConditionParameters `json:"organization_name,omitempty"` + OrganizationProperty *RepositoryRulesetOrganizationPropertyConditionParameters `json:"organization_property,omitempty"` } // RepositoryRulesetRefConditionParameters represents the conditions object for ref_names. @@ -217,6 +218,19 @@ type RepositoryRulesetRefConditionParameters struct { Exclude []string `json:"exclude"` } +// RepositoryRulesetOrganizationPropertyTargetParameters represents an organization_property name and values to be used for targeting. +type RepositoryRulesetOrganizationPropertyTargetParameters struct { + Name string `json:"name"` + PropertyValues []string `json:"property_values"` + Source *string `json:"source,omitempty"` +} + +// RepositoryRulesetOrganizationPropertyConditionParameters represents the conditions object for an organization property selector. +type RepositoryRulesetOrganizationPropertyConditionParameters struct { + Include []*RepositoryRulesetOrganizationPropertyTargetParameters `json:"include"` + Exclude []*RepositoryRulesetOrganizationPropertyTargetParameters `json:"exclude"` +} + // RepositoryRulesetRepositoryIDsConditionParameters represents the conditions object for repository_id. type RepositoryRulesetRepositoryIDsConditionParameters struct { RepositoryIDs []int64 `json:"repository_ids,omitempty"` From a3df9cdde270c3c6f6bb23fa726ea3e7d1446eb6 Mon Sep 17 00:00:00 2001 From: Dhananjay Mishra Date: Wed, 5 Nov 2025 07:08:16 +0000 Subject: [PATCH 03/11] change input field of CreateOrUpdateOrgCustomPropertyValues from properties to values --- github/organizations_custom_properties.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/github/organizations_custom_properties.go b/github/organizations_custom_properties.go index b63f720cd6a..e53b8b4f67b 100644 --- a/github/organizations_custom_properties.go +++ b/github/organizations_custom_properties.go @@ -43,9 +43,9 @@ func (s *OrganizationsService) GetOrganizationCustomPropertyValues(ctx context.C // GitHub API docs: https://docs.github.com/rest/orgs/custom-properties-for-orgs#create-or-update-custom-property-values-for-an-organization // //meta:operation PATCH /organizations/{org}/org-properties/values -func (s *OrganizationsService) CreateOrUpdateOrgCustomPropertyValues(ctx context.Context, org string, properties OrganizationCustomPropertyValues) (*Response, error) { +func (s *OrganizationsService) CreateOrUpdateOrgCustomPropertyValues(ctx context.Context, org string, values OrganizationCustomPropertyValues) (*Response, error) { u := fmt.Sprintf("organizations/%v/org-properties/values", org) - req, err := s.client.NewRequest("PATCH", u, properties) + req, err := s.client.NewRequest("PATCH", u, values) if err != nil { return nil, err } From 9895bc5382439a2d1c619e0c4cca4f6e021182a4 Mon Sep 17 00:00:00 2001 From: Dhananjay Mishra Date: Wed, 5 Nov 2025 11:00:54 +0000 Subject: [PATCH 04/11] change filename, re use struct and swap test file --- github/enterprise_custom_properties.go | 57 +--- github/enterprise_custom_properties_test.go | 232 +++++++++++++-- github/github-accessors.go | 112 ++------ github/github-accessors_test.go | 154 +++------- .../organizations_custom_properties_test.go | 264 ------------------ ...roperties.go => orgs_custom_properties.go} | 6 +- github/orgs_custom_properties_test.go | 94 +++++++ github/orgs_properties.go | 2 + github/rules.go | 11 +- 9 files changed, 372 insertions(+), 560 deletions(-) delete mode 100644 github/organizations_custom_properties_test.go rename github/{organizations_custom_properties.go => orgs_custom_properties.go} (91%) create mode 100644 github/orgs_custom_properties_test.go diff --git a/github/enterprise_custom_properties.go b/github/enterprise_custom_properties.go index b0633dc814b..0d1c5ab5ae4 100644 --- a/github/enterprise_custom_properties.go +++ b/github/enterprise_custom_properties.go @@ -10,60 +10,29 @@ import ( "fmt" ) -// Property represents a custom property definition in an enterprise. -type Property struct { - // Name of the custom property. - Name string `json:"name"` - // The URL that can be used to fetch, update, or delete info about this property via the API. - URL *string `json:"url,omitempty"` - // The source type of the property. - SourceType *string `json:"source_type,omitempty"` - // The type of the value for the property. - ValueType string `json:"value_type"` - // Whether the property is required. - Required *bool `json:"required,omitempty"` - // The default value for the property. - DefaultValue *string `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 allowed values. - AllowedValues []string `json:"allowed_values,omitempty"` - // Who can edit the values of the property. - ValuesEditableBy *string `json:"values_editable_by,omitempty"` -} - // EnterpriseCustomPropertySchema represents the schema response for GetEnterpriseCustomPropertiesSchema. type EnterpriseCustomPropertySchema struct { // An ordered list of the custom property defined in the enterprise. - Properties []*Property `json:"properties,omitempty"` -} - -// PropertyValue represents the custom property values for an organization. -type PropertyValue struct { - // The name of the property - PropertyName *string `json:"property_name,omitempty"` - // The value assigned to the property - Value *string `json:"value,omitempty"` + Properties []*CustomProperty `json:"properties,omitempty"` } -// CustomPropertiesValues represents the custom properties values for an organization within an enterprise. -type CustomPropertiesValues struct { +// EnterpriseCustomPropertiesValues represents the custom properties values for an organization within an enterprise. +type EnterpriseCustomPropertiesValues struct { // The Organization ID that the custom property values will be applied to. OrganizationID *int64 `json:"organization_id,omitempty"` // The names of organizations that the custom property values will be applied to. OrganizationLogin *string `json:"organization_login,omitempty"` // List of custom property names and associated values to apply to the organizations. - Properties []*PropertyValue `json:"properties,omitempty"` + Properties []*CustomPropertyValue `json:"properties,omitempty"` } -// EnterpriseCustomPropertyValues represents the request to update custom property values for organizations within an enterprise. -type EnterpriseCustomPropertyValues struct { +// EnterpriseCustomPropertyValuesRequest represents the request to update custom property values for organizations within an enterprise. +type EnterpriseCustomPropertyValuesRequest struct { // The names of organizations that the custom property values will be applied to. // OrganizationLogin specifies the organization name when updating multiple organizations. OrganizationLogin []string `json:"organization_login"` // List of custom property names and associated values to apply to the organizations. - Properties []*PropertyValue `json:"properties"` + Properties []*CustomPropertyValue `json:"properties"` } // GetEnterpriseCustomPropertySchema gives all organization custom property definitions that are defined on an enterprise. @@ -113,7 +82,7 @@ func (s *EnterpriseService) CreateOrUpdateEnterpriseCustomPropertySchema(ctx con // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/custom-properties-for-orgs#get-an-organization-custom-property-definition-from-an-enterprise // //meta:operation GET /enterprises/{enterprise}/org-properties/schema/{custom_property_name} -func (s *EnterpriseService) GetEnterpriseCustomProperty(ctx context.Context, enterprise, customPropertyName string) (*Property, *Response, error) { +func (s *EnterpriseService) GetEnterpriseCustomProperty(ctx context.Context, enterprise, customPropertyName string) (*CustomProperty, *Response, error) { u := fmt.Sprintf("enterprises/%v/org-properties/schema/%v", enterprise, customPropertyName) req, err := s.client.NewRequest("GET", u, nil) @@ -121,7 +90,7 @@ func (s *EnterpriseService) GetEnterpriseCustomProperty(ctx context.Context, ent return nil, nil, err } - var property *Property + var property *CustomProperty resp, err := s.client.Do(ctx, req, &property) if err != nil { return nil, resp, err @@ -135,7 +104,7 @@ func (s *EnterpriseService) GetEnterpriseCustomProperty(ctx context.Context, ent // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/custom-properties-for-orgs#create-or-update-an-organization-custom-property-definition-on-an-enterprise // //meta:operation PUT /enterprises/{enterprise}/org-properties/schema/{custom_property_name} -func (s *EnterpriseService) CreateOrUpdateEnterpriseCustomProperty(ctx context.Context, enterprise, customPropertyName string, property Property) (*Response, error) { +func (s *EnterpriseService) CreateOrUpdateEnterpriseCustomProperty(ctx context.Context, enterprise, customPropertyName string, property CustomProperty) (*Response, error) { u := fmt.Sprintf("enterprises/%v/org-properties/schema/%v", enterprise, customPropertyName) req, err := s.client.NewRequest("PUT", u, property) if err != nil { @@ -176,7 +145,7 @@ func (s *EnterpriseService) DeleteEnterpriseCustomProperty(ctx context.Context, // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/custom-properties-for-orgs#list-custom-property-values-for-organizations-in-an-enterprise // //meta:operation GET /enterprises/{enterprise}/org-properties/values -func (s *EnterpriseService) GetEnterpriseCustomPropertyValues(ctx context.Context, enterprise string, opts *ListOptions) ([]*CustomPropertiesValues, *Response, error) { +func (s *EnterpriseService) GetEnterpriseCustomPropertyValues(ctx context.Context, enterprise string, opts *ListOptions) ([]*EnterpriseCustomPropertiesValues, *Response, error) { u := fmt.Sprintf("enterprises/%v/org-properties/values", enterprise) u, err := addOptions(u, opts) @@ -189,7 +158,7 @@ func (s *EnterpriseService) GetEnterpriseCustomPropertyValues(ctx context.Contex return nil, nil, err } - var values []*CustomPropertiesValues + var values []*EnterpriseCustomPropertiesValues resp, err := s.client.Do(ctx, req, &values) if err != nil { return nil, resp, err @@ -204,7 +173,7 @@ func (s *EnterpriseService) GetEnterpriseCustomPropertyValues(ctx context.Contex // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/custom-properties-for-orgs#create-or-update-custom-property-values-for-organizations-in-an-enterprise // //meta:operation PATCH /enterprises/{enterprise}/org-properties/values -func (s *EnterpriseService) CreateOrUpdateEnterpriseCustomPropertyValues(ctx context.Context, enterprise string, values EnterpriseCustomPropertyValues) (*Response, error) { +func (s *EnterpriseService) CreateOrUpdateEnterpriseCustomPropertyValues(ctx context.Context, enterprise string, values EnterpriseCustomPropertyValuesRequest) (*Response, error) { u := fmt.Sprintf("enterprises/%v/org-properties/values", enterprise) req, err := s.client.NewRequest("PATCH", u, values) if err != nil { diff --git a/github/enterprise_custom_properties_test.go b/github/enterprise_custom_properties_test.go index 8fe94ca58fd..81d62a9bd3a 100644 --- a/github/enterprise_custom_properties_test.go +++ b/github/enterprise_custom_properties_test.go @@ -13,46 +13,217 @@ import ( "github.com/google/go-cmp/cmp" ) -func TestOrganizationsService_GetOrganizationCustomPropertyValues(t *testing.T) { +func TestEnterpriseService_GetEnterpriseCustomPropertySchema(t *testing.T) { t.Parallel() client, mux, _ := setup(t) - mux.HandleFunc("/organizations/o/org-properties/values", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/enterprises/e/org-properties/schema", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") - fmt.Fprint(w, `[{ - "property_name": "team", - "value": "core" + fmt.Fprint(w, `{ + "properties": [{ + "name": "team", + "value_type": "string", + "description": "Team name" + }] + }`) + }) + + ctx := t.Context() + got, _, err := client.Enterprise.GetEnterpriseCustomPropertySchema(ctx, "e") + if err != nil { + t.Errorf("Enterprise.GetEnterpriseCustomPropertySchema returned error: %v", err) + } + + want := &EnterpriseCustomPropertySchema{ + Properties: []*CustomProperty{ + { + PropertyName: Ptr("team"), + ValueType: "string", + Description: Ptr("Team name"), + }, }, - { - "property_name": "level", - "value": "gold" - }]`) + } + + if !cmp.Equal(got, want) { + t.Errorf("Enterprise.GetEnterpriseCustomPropertySchema = %+v, want %+v", got, want) + } + + const methodName = "GetEnterpriseCustomPropertySchema" + testBadOptions(t, methodName, func() error { + _, _, err := client.Enterprise.GetEnterpriseCustomPropertySchema(ctx, "\n") + return err + }) + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + got, resp, err := client.Enterprise.GetEnterpriseCustomPropertySchema(ctx, "e") + if got != nil { + t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) + } + return resp, err + }) +} + +func TestEnterpriseService_CreateOrUpdateEnterpriseCustomPropertySchema(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/enterprises/e/org-properties/schema", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "PATCH") + fmt.Fprint(w, `{}`) }) ctx := t.Context() - got, _, err := client.Organizations.GetOrganizationCustomPropertyValues(ctx, "o") + schema := EnterpriseCustomPropertySchema{ + Properties: []*CustomProperty{{PropertyName: Ptr("team")}}, + } + _, err := client.Enterprise.CreateOrUpdateEnterpriseCustomPropertySchema(ctx, "e", schema) if err != nil { - t.Errorf("Organizations.GetOrganizationCustomPropertyValues returned error: %v", err) + t.Errorf("Enterprise.CreateOrUpdateEnterpriseCustomPropertySchema returned error: %v", err) } - want := []*PropertyValue{ - {PropertyName: Ptr("team"), Value: Ptr("core")}, - {PropertyName: Ptr("level"), Value: Ptr("gold")}, + const methodName = "CreateOrUpdateEnterpriseCustomPropertySchema" + testBadOptions(t, methodName, func() error { + _, err := client.Enterprise.CreateOrUpdateEnterpriseCustomPropertySchema(ctx, "\n", schema) + return err + }) + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + return client.Enterprise.CreateOrUpdateEnterpriseCustomPropertySchema(ctx, "e", schema) + }) +} + +func TestEnterpriseService_GetEnterpriseCustomProperty(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/enterprises/e/org-properties/schema/prop", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `{ + "name": "team", + "value_type": "string", + "description": "Team name" + }`) + }) + + ctx := t.Context() + got, _, err := client.Enterprise.GetEnterpriseCustomProperty(ctx, "e", "prop") + if err != nil { + t.Errorf("Enterprise.GetEnterpriseCustomProperty returned error: %v", err) + } + + want := &CustomProperty{ + PropertyName: Ptr("team"), + ValueType: "string", + Description: Ptr("Team name"), } if !cmp.Equal(got, want) { - t.Errorf("Organizations.GetOrganizationCustomPropertyValues = %+v, want %+v", got, want) + t.Errorf("Enterprise.GetEnterpriseCustomProperty = %+v, want %+v", got, want) + } + + const methodName = "GetEnterpriseCustomProperty" + testBadOptions(t, methodName, func() error { + _, _, err := client.Enterprise.GetEnterpriseCustomProperty(ctx, "\n", "prop") + return err + }) + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + got, resp, err := client.Enterprise.GetEnterpriseCustomProperty(ctx, "e", "prop") + if got != nil { + t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) + } + return resp, err + }) +} + +func TestEnterpriseService_CreateOrUpdateEnterpriseCustomProperty(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/enterprises/e/org-properties/schema/prop", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "PUT") + fmt.Fprint(w, `{}`) + }) + + ctx := t.Context() + property := CustomProperty{PropertyName: Ptr("team")} + _, err := client.Enterprise.CreateOrUpdateEnterpriseCustomProperty(ctx, "e", "prop", property) + if err != nil { + t.Errorf("Enterprise.CreateOrUpdateEnterpriseCustomProperty returned error: %v", err) } - const methodName = "GetOrganizationCustomPropertyValues" + const methodName = "CreateOrUpdateEnterpriseCustomProperty" + testBadOptions(t, methodName, func() error { + _, err := client.Enterprise.CreateOrUpdateEnterpriseCustomProperty(ctx, "\n", "prop", property) + return err + }) + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + return client.Enterprise.CreateOrUpdateEnterpriseCustomProperty(ctx, "e", "prop", property) + }) +} + +func TestEnterpriseService_DeleteEnterpriseCustomProperty(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/enterprises/e/org-properties/schema/prop", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "DELETE") + w.WriteHeader(http.StatusNoContent) + }) + ctx := t.Context() + _, err := client.Enterprise.DeleteEnterpriseCustomProperty(ctx, "e", "prop") + if err != nil { + t.Errorf("Enterprise.DeleteEnterpriseCustomProperty returned error: %v", err) + } + + const methodName = "DeleteEnterpriseCustomProperty" testBadOptions(t, methodName, func() error { - _, _, err := client.Organizations.GetOrganizationCustomPropertyValues(ctx, "\n") + _, err := client.Enterprise.DeleteEnterpriseCustomProperty(ctx, "\n", "prop") return err }) + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + return client.Enterprise.DeleteEnterpriseCustomProperty(ctx, "e", "prop") + }) +} + +func TestEnterpriseService_GetEnterpriseCustomPropertyValues(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/enterprises/e/org-properties/values", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `[{ + "organization_id": 1, + "organization_login": "org1", + "properties": [{"property_name": "team", "value": "core"}] + }]`) + }) + ctx := t.Context() + got, _, err := client.Enterprise.GetEnterpriseCustomPropertyValues(ctx, "e", nil) + if err != nil { + t.Errorf("Enterprise.GetEnterpriseCustomPropertyValues returned error: %v", err) + } + + want := []*EnterpriseCustomPropertiesValues{ + { + OrganizationID: Ptr(int64(1)), + OrganizationLogin: Ptr("org1"), + Properties: []*CustomPropertyValue{ + {PropertyName: "team", Value: Ptr("core")}, + }, + }, + } + + if !cmp.Equal(got, want) { + t.Errorf("Enterprise.GetEnterpriseCustomPropertyValues = %+v, want %+v", got, want) + } + + const methodName = "GetEnterpriseCustomPropertyValues" + testBadOptions(t, methodName, func() error { + _, _, err := client.Enterprise.GetEnterpriseCustomPropertyValues(ctx, "\n", nil) + return err + }) testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - got, resp, err := client.Organizations.GetOrganizationCustomPropertyValues(ctx, "o") + got, resp, err := client.Enterprise.GetEnterpriseCustomPropertyValues(ctx, "e", nil) if got != nil { t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) } @@ -60,35 +231,34 @@ func TestOrganizationsService_GetOrganizationCustomPropertyValues(t *testing.T) }) } -func TestOrganizationsService_CreateOrUpdateOrgCustomPropertyValues(t *testing.T) { +func TestEnterpriseService_CreateOrUpdateEnterpriseCustomPropertyValues(t *testing.T) { t.Parallel() client, mux, _ := setup(t) - mux.HandleFunc("/organizations/o/org-properties/values", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/enterprises/e/org-properties/values", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "PATCH") fmt.Fprint(w, `{}`) }) ctx := t.Context() - values := []*PropertyValue{ - {PropertyName: Ptr("team"), Value: Ptr("core")}, - {PropertyName: Ptr("level"), Value: Ptr("gold")}, - } + values := []*CustomPropertyValue{{PropertyName: "team", Value: Ptr("core")}} + orgs := []string{"org1"} - props := OrganizationCustomPropertyValues{ - Properties: values, + opts := EnterpriseCustomPropertyValuesRequest{ + OrganizationLogin: orgs, + Properties: values, } - _, err := client.Organizations.CreateOrUpdateOrgCustomPropertyValues(ctx, "o", props) + _, err := client.Enterprise.CreateOrUpdateEnterpriseCustomPropertyValues(ctx, "e", opts) if err != nil { - t.Errorf("Organizations.CreateOrUpdateOrgCustomPropertyValues returned error: %v", err) + t.Errorf("Enterprise.CreateOrUpdateEnterpriseCustomPropertyValues returned error: %v", err) } - const methodName = "CreateOrUpdateOrgCustomPropertyValues" + const methodName = "CreateOrUpdateEnterpriseCustomPropertyValues" testBadOptions(t, methodName, func() error { - _, err := client.Organizations.CreateOrUpdateOrgCustomPropertyValues(ctx, "\n", props) + _, err := client.Enterprise.CreateOrUpdateEnterpriseCustomPropertyValues(ctx, "\n", opts) return err }) testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - return client.Organizations.CreateOrUpdateOrgCustomPropertyValues(ctx, "o", props) + return client.Enterprise.CreateOrUpdateEnterpriseCustomPropertyValues(ctx, "e", opts) }) } diff --git a/github/github-accessors.go b/github/github-accessors.go index 2ce8317a0d4..826de9a4596 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -6782,22 +6782,6 @@ func (c *CustomPatternBackfillScan) GetPatternSlug() string { return *c.PatternSlug } -// GetOrganizationID returns the OrganizationID field if it's non-nil, zero value otherwise. -func (c *CustomPropertiesValues) GetOrganizationID() int64 { - if c == nil || c.OrganizationID == nil { - return 0 - } - return *c.OrganizationID -} - -// GetOrganizationLogin returns the OrganizationLogin field if it's non-nil, zero value otherwise. -func (c *CustomPropertiesValues) GetOrganizationLogin() string { - if c == nil || c.OrganizationLogin == nil { - return "" - } - return *c.OrganizationLogin -} - // GetDefaultValue returns the DefaultValue field if it's non-nil, zero value otherwise. func (c *CustomProperty) GetDefaultValue() string { if c == nil || c.DefaultValue == nil { @@ -6838,6 +6822,14 @@ func (c *CustomProperty) GetSourceType() string { return *c.SourceType } +// GetURL returns the URL field if it's non-nil, zero value otherwise. +func (c *CustomProperty) GetURL() string { + if c == nil || c.URL == nil { + return "" + } + return *c.URL +} + // GetValuesEditableBy returns the ValuesEditableBy field if it's non-nil, zero value otherwise. func (c *CustomProperty) GetValuesEditableBy() string { if c == nil || c.ValuesEditableBy == nil { @@ -9142,6 +9134,22 @@ func (e *Enterprise) GetWebsiteURL() string { return *e.WebsiteURL } +// GetOrganizationID returns the OrganizationID field if it's non-nil, zero value otherwise. +func (e *EnterpriseCustomPropertiesValues) GetOrganizationID() int64 { + if e == nil || e.OrganizationID == nil { + return 0 + } + return *e.OrganizationID +} + +// GetOrganizationLogin returns the OrganizationLogin field if it's non-nil, zero value otherwise. +func (e *EnterpriseCustomPropertiesValues) GetOrganizationLogin() string { + if e == nil || e.OrganizationLogin == nil { + return "" + } + return *e.OrganizationLogin +} + // GetEnterpriseServerUser returns the EnterpriseServerUser field if it's non-nil, zero value otherwise. func (e *EnterpriseLicensedUsers) GetEnterpriseServerUser() bool { if e == nil || e.EnterpriseServerUser == nil { @@ -19462,70 +19470,6 @@ func (p *ProjectV2ItemEvent) GetSender() *User { return p.Sender } -// GetDefaultValue returns the DefaultValue field if it's non-nil, zero value otherwise. -func (p *Property) GetDefaultValue() string { - if p == nil || p.DefaultValue == nil { - return "" - } - return *p.DefaultValue -} - -// GetDescription returns the Description field if it's non-nil, zero value otherwise. -func (p *Property) GetDescription() string { - if p == nil || p.Description == nil { - return "" - } - return *p.Description -} - -// GetRequired returns the Required field if it's non-nil, zero value otherwise. -func (p *Property) GetRequired() bool { - if p == nil || p.Required == nil { - return false - } - return *p.Required -} - -// GetSourceType returns the SourceType field if it's non-nil, zero value otherwise. -func (p *Property) GetSourceType() string { - if p == nil || p.SourceType == nil { - return "" - } - return *p.SourceType -} - -// GetURL returns the URL field if it's non-nil, zero value otherwise. -func (p *Property) GetURL() string { - if p == nil || p.URL == nil { - return "" - } - return *p.URL -} - -// GetValuesEditableBy returns the ValuesEditableBy field if it's non-nil, zero value otherwise. -func (p *Property) GetValuesEditableBy() string { - if p == nil || p.ValuesEditableBy == nil { - return "" - } - return *p.ValuesEditableBy -} - -// GetPropertyName returns the PropertyName field if it's non-nil, zero value otherwise. -func (p *PropertyValue) GetPropertyName() string { - if p == nil || p.PropertyName == nil { - return "" - } - return *p.PropertyName -} - -// GetValue returns the Value field if it's non-nil, zero value otherwise. -func (p *PropertyValue) GetValue() string { - if p == nil || p.Value == nil { - return "" - } - return *p.Value -} - // GetAllowDeletions returns the AllowDeletions field. func (p *Protection) GetAllowDeletions() *AllowDeletions { if p == nil { @@ -24726,14 +24670,6 @@ func (r *RepositoryRulesetLinks) GetSelf() *RepositoryRulesetLink { return r.Self } -// GetSource returns the Source field if it's non-nil, zero value otherwise. -func (r *RepositoryRulesetOrganizationPropertyTargetParameters) GetSource() string { - if r == nil || r.Source == nil { - return "" - } - return *r.Source -} - // GetProtected returns the Protected field if it's non-nil, zero value otherwise. func (r *RepositoryRulesetRepositoryNamesConditionParameters) GetProtected() bool { if r == nil || r.Protected == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 264bbd02345..ffa6294c240 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -8868,28 +8868,6 @@ func TestCustomPatternBackfillScan_GetPatternSlug(tt *testing.T) { c.GetPatternSlug() } -func TestCustomPropertiesValues_GetOrganizationID(tt *testing.T) { - tt.Parallel() - var zeroValue int64 - c := &CustomPropertiesValues{OrganizationID: &zeroValue} - c.GetOrganizationID() - c = &CustomPropertiesValues{} - c.GetOrganizationID() - c = nil - c.GetOrganizationID() -} - -func TestCustomPropertiesValues_GetOrganizationLogin(tt *testing.T) { - tt.Parallel() - var zeroValue string - c := &CustomPropertiesValues{OrganizationLogin: &zeroValue} - c.GetOrganizationLogin() - c = &CustomPropertiesValues{} - c.GetOrganizationLogin() - c = nil - c.GetOrganizationLogin() -} - func TestCustomProperty_GetDefaultValue(tt *testing.T) { tt.Parallel() var zeroValue string @@ -8945,6 +8923,17 @@ func TestCustomProperty_GetSourceType(tt *testing.T) { c.GetSourceType() } +func TestCustomProperty_GetURL(tt *testing.T) { + tt.Parallel() + var zeroValue string + c := &CustomProperty{URL: &zeroValue} + c.GetURL() + c = &CustomProperty{} + c.GetURL() + c = nil + c.GetURL() +} + func TestCustomProperty_GetValuesEditableBy(tt *testing.T) { tt.Parallel() var zeroValue string @@ -11837,6 +11826,28 @@ func TestEnterprise_GetWebsiteURL(tt *testing.T) { e.GetWebsiteURL() } +func TestEnterpriseCustomPropertiesValues_GetOrganizationID(tt *testing.T) { + tt.Parallel() + var zeroValue int64 + e := &EnterpriseCustomPropertiesValues{OrganizationID: &zeroValue} + e.GetOrganizationID() + e = &EnterpriseCustomPropertiesValues{} + e.GetOrganizationID() + e = nil + e.GetOrganizationID() +} + +func TestEnterpriseCustomPropertiesValues_GetOrganizationLogin(tt *testing.T) { + tt.Parallel() + var zeroValue string + e := &EnterpriseCustomPropertiesValues{OrganizationLogin: &zeroValue} + e.GetOrganizationLogin() + e = &EnterpriseCustomPropertiesValues{} + e.GetOrganizationLogin() + e = nil + e.GetOrganizationLogin() +} + func TestEnterpriseLicensedUsers_GetEnterpriseServerUser(tt *testing.T) { tt.Parallel() var zeroValue bool @@ -25271,94 +25282,6 @@ func TestProjectV2ItemEvent_GetSender(tt *testing.T) { p.GetSender() } -func TestProperty_GetDefaultValue(tt *testing.T) { - tt.Parallel() - var zeroValue string - p := &Property{DefaultValue: &zeroValue} - p.GetDefaultValue() - p = &Property{} - p.GetDefaultValue() - p = nil - p.GetDefaultValue() -} - -func TestProperty_GetDescription(tt *testing.T) { - tt.Parallel() - var zeroValue string - p := &Property{Description: &zeroValue} - p.GetDescription() - p = &Property{} - p.GetDescription() - p = nil - p.GetDescription() -} - -func TestProperty_GetRequired(tt *testing.T) { - tt.Parallel() - var zeroValue bool - p := &Property{Required: &zeroValue} - p.GetRequired() - p = &Property{} - p.GetRequired() - p = nil - p.GetRequired() -} - -func TestProperty_GetSourceType(tt *testing.T) { - tt.Parallel() - var zeroValue string - p := &Property{SourceType: &zeroValue} - p.GetSourceType() - p = &Property{} - p.GetSourceType() - p = nil - p.GetSourceType() -} - -func TestProperty_GetURL(tt *testing.T) { - tt.Parallel() - var zeroValue string - p := &Property{URL: &zeroValue} - p.GetURL() - p = &Property{} - p.GetURL() - p = nil - p.GetURL() -} - -func TestProperty_GetValuesEditableBy(tt *testing.T) { - tt.Parallel() - var zeroValue string - p := &Property{ValuesEditableBy: &zeroValue} - p.GetValuesEditableBy() - p = &Property{} - p.GetValuesEditableBy() - p = nil - p.GetValuesEditableBy() -} - -func TestPropertyValue_GetPropertyName(tt *testing.T) { - tt.Parallel() - var zeroValue string - p := &PropertyValue{PropertyName: &zeroValue} - p.GetPropertyName() - p = &PropertyValue{} - p.GetPropertyName() - p = nil - p.GetPropertyName() -} - -func TestPropertyValue_GetValue(tt *testing.T) { - tt.Parallel() - var zeroValue string - p := &PropertyValue{Value: &zeroValue} - p.GetValue() - p = &PropertyValue{} - p.GetValue() - p = nil - p.GetValue() -} - func TestProtection_GetAllowDeletions(tt *testing.T) { tt.Parallel() p := &Protection{} @@ -31921,17 +31844,6 @@ func TestRepositoryRulesetLinks_GetSelf(tt *testing.T) { r.GetSelf() } -func TestRepositoryRulesetOrganizationPropertyTargetParameters_GetSource(tt *testing.T) { - tt.Parallel() - var zeroValue string - r := &RepositoryRulesetOrganizationPropertyTargetParameters{Source: &zeroValue} - r.GetSource() - r = &RepositoryRulesetOrganizationPropertyTargetParameters{} - r.GetSource() - r = nil - r.GetSource() -} - func TestRepositoryRulesetRepositoryNamesConditionParameters_GetProtected(tt *testing.T) { tt.Parallel() var zeroValue bool diff --git a/github/organizations_custom_properties_test.go b/github/organizations_custom_properties_test.go deleted file mode 100644 index 22253978a38..00000000000 --- a/github/organizations_custom_properties_test.go +++ /dev/null @@ -1,264 +0,0 @@ -// Copyright 2025 The go-github AUTHORS. All rights reserved. -// -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package github - -import ( - "fmt" - "net/http" - "testing" - - "github.com/google/go-cmp/cmp" -) - -func TestEnterpriseService_GetEnterpriseCustomPropertySchema(t *testing.T) { - t.Parallel() - client, mux, _ := setup(t) - - mux.HandleFunc("/enterprises/e/org-properties/schema", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "GET") - fmt.Fprint(w, `{ - "properties": [{ - "name": "team", - "value_type": "string", - "description": "Team name" - }] - }`) - }) - - ctx := t.Context() - got, _, err := client.Enterprise.GetEnterpriseCustomPropertySchema(ctx, "e") - if err != nil { - t.Errorf("Enterprise.GetEnterpriseCustomPropertySchema returned error: %v", err) - } - - want := &EnterpriseCustomPropertySchema{ - Properties: []*Property{ - { - Name: "team", - ValueType: "string", - Description: Ptr("Team name"), - }, - }, - } - - if !cmp.Equal(got, want) { - t.Errorf("Enterprise.GetEnterpriseCustomPropertySchema = %+v, want %+v", got, want) - } - - const methodName = "GetEnterpriseCustomPropertySchema" - testBadOptions(t, methodName, func() error { - _, _, err := client.Enterprise.GetEnterpriseCustomPropertySchema(ctx, "\n") - return err - }) - testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - got, resp, err := client.Enterprise.GetEnterpriseCustomPropertySchema(ctx, "e") - if got != nil { - t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) - } - return resp, err - }) -} - -func TestEnterpriseService_CreateOrUpdateEnterpriseCustomPropertySchema(t *testing.T) { - t.Parallel() - client, mux, _ := setup(t) - - mux.HandleFunc("/enterprises/e/org-properties/schema", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "PATCH") - fmt.Fprint(w, `{}`) - }) - - ctx := t.Context() - schema := EnterpriseCustomPropertySchema{ - Properties: []*Property{{Name: "team"}}, - } - _, err := client.Enterprise.CreateOrUpdateEnterpriseCustomPropertySchema(ctx, "e", schema) - if err != nil { - t.Errorf("Enterprise.CreateOrUpdateEnterpriseCustomPropertySchema returned error: %v", err) - } - - const methodName = "CreateOrUpdateEnterpriseCustomPropertySchema" - testBadOptions(t, methodName, func() error { - _, err := client.Enterprise.CreateOrUpdateEnterpriseCustomPropertySchema(ctx, "\n", schema) - return err - }) - testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - return client.Enterprise.CreateOrUpdateEnterpriseCustomPropertySchema(ctx, "e", schema) - }) -} - -func TestEnterpriseService_GetEnterpriseCustomProperty(t *testing.T) { - t.Parallel() - client, mux, _ := setup(t) - - mux.HandleFunc("/enterprises/e/org-properties/schema/prop", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "GET") - fmt.Fprint(w, `{ - "name": "team", - "value_type": "string", - "description": "Team name" - }`) - }) - - ctx := t.Context() - got, _, err := client.Enterprise.GetEnterpriseCustomProperty(ctx, "e", "prop") - if err != nil { - t.Errorf("Enterprise.GetEnterpriseCustomProperty returned error: %v", err) - } - - want := &Property{ - Name: "team", - ValueType: "string", - Description: Ptr("Team name"), - } - - if !cmp.Equal(got, want) { - t.Errorf("Enterprise.GetEnterpriseCustomProperty = %+v, want %+v", got, want) - } - - const methodName = "GetEnterpriseCustomProperty" - testBadOptions(t, methodName, func() error { - _, _, err := client.Enterprise.GetEnterpriseCustomProperty(ctx, "\n", "prop") - return err - }) - testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - got, resp, err := client.Enterprise.GetEnterpriseCustomProperty(ctx, "e", "prop") - if got != nil { - t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) - } - return resp, err - }) -} - -func TestEnterpriseService_CreateOrUpdateEnterpriseCustomProperty(t *testing.T) { - t.Parallel() - client, mux, _ := setup(t) - - mux.HandleFunc("/enterprises/e/org-properties/schema/prop", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "PUT") - fmt.Fprint(w, `{}`) - }) - - ctx := t.Context() - property := Property{Name: "team"} - _, err := client.Enterprise.CreateOrUpdateEnterpriseCustomProperty(ctx, "e", "prop", property) - if err != nil { - t.Errorf("Enterprise.CreateOrUpdateEnterpriseCustomProperty returned error: %v", err) - } - - const methodName = "CreateOrUpdateEnterpriseCustomProperty" - testBadOptions(t, methodName, func() error { - _, err := client.Enterprise.CreateOrUpdateEnterpriseCustomProperty(ctx, "\n", "prop", property) - return err - }) - testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - return client.Enterprise.CreateOrUpdateEnterpriseCustomProperty(ctx, "e", "prop", property) - }) -} - -func TestEnterpriseService_DeleteEnterpriseCustomProperty(t *testing.T) { - t.Parallel() - client, mux, _ := setup(t) - - mux.HandleFunc("/enterprises/e/org-properties/schema/prop", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "DELETE") - w.WriteHeader(http.StatusNoContent) - }) - - ctx := t.Context() - _, err := client.Enterprise.DeleteEnterpriseCustomProperty(ctx, "e", "prop") - if err != nil { - t.Errorf("Enterprise.DeleteEnterpriseCustomProperty returned error: %v", err) - } - - const methodName = "DeleteEnterpriseCustomProperty" - testBadOptions(t, methodName, func() error { - _, err := client.Enterprise.DeleteEnterpriseCustomProperty(ctx, "\n", "prop") - return err - }) - testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - return client.Enterprise.DeleteEnterpriseCustomProperty(ctx, "e", "prop") - }) -} - -func TestEnterpriseService_GetEnterpriseCustomPropertyValues(t *testing.T) { - t.Parallel() - client, mux, _ := setup(t) - - mux.HandleFunc("/enterprises/e/org-properties/values", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "GET") - fmt.Fprint(w, `[{ - "organization_id": 1, - "organization_login": "org1", - "properties": [{"property_name": "team", "value": "core"}] - }]`) - }) - - ctx := t.Context() - got, _, err := client.Enterprise.GetEnterpriseCustomPropertyValues(ctx, "e", nil) - if err != nil { - t.Errorf("Enterprise.GetEnterpriseCustomPropertyValues returned error: %v", err) - } - - want := []*CustomPropertiesValues{ - { - OrganizationID: Ptr(int64(1)), - OrganizationLogin: Ptr("org1"), - Properties: []*PropertyValue{ - {PropertyName: Ptr("team"), Value: Ptr("core")}, - }, - }, - } - - if !cmp.Equal(got, want) { - t.Errorf("Enterprise.GetEnterpriseCustomPropertyValues = %+v, want %+v", got, want) - } - - const methodName = "GetEnterpriseCustomPropertyValues" - testBadOptions(t, methodName, func() error { - _, _, err := client.Enterprise.GetEnterpriseCustomPropertyValues(ctx, "\n", nil) - return err - }) - testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - got, resp, err := client.Enterprise.GetEnterpriseCustomPropertyValues(ctx, "e", nil) - if got != nil { - t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) - } - return resp, err - }) -} - -func TestEnterpriseService_CreateOrUpdateEnterpriseCustomPropertyValues(t *testing.T) { - t.Parallel() - client, mux, _ := setup(t) - - mux.HandleFunc("/enterprises/e/org-properties/values", func(w http.ResponseWriter, r *http.Request) { - testMethod(t, r, "PATCH") - fmt.Fprint(w, `{}`) - }) - - ctx := t.Context() - values := []*PropertyValue{{PropertyName: Ptr("team"), Value: Ptr("core")}} - orgs := []string{"org1"} - - opts := EnterpriseCustomPropertyValues{ - OrganizationLogin: orgs, - Properties: values, - } - _, err := client.Enterprise.CreateOrUpdateEnterpriseCustomPropertyValues(ctx, "e", opts) - if err != nil { - t.Errorf("Enterprise.CreateOrUpdateEnterpriseCustomPropertyValues returned error: %v", err) - } - - const methodName = "CreateOrUpdateEnterpriseCustomPropertyValues" - testBadOptions(t, methodName, func() error { - _, err := client.Enterprise.CreateOrUpdateEnterpriseCustomPropertyValues(ctx, "\n", opts) - return err - }) - testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - return client.Enterprise.CreateOrUpdateEnterpriseCustomPropertyValues(ctx, "e", opts) - }) -} diff --git a/github/organizations_custom_properties.go b/github/orgs_custom_properties.go similarity index 91% rename from github/organizations_custom_properties.go rename to github/orgs_custom_properties.go index e53b8b4f67b..9dd1bfb26ba 100644 --- a/github/organizations_custom_properties.go +++ b/github/orgs_custom_properties.go @@ -13,7 +13,7 @@ import ( // OrganizationCustomPropertyValues represents the custom property values for an organization. type OrganizationCustomPropertyValues struct { // List of custom property names and associated values to apply to the organization. - Properties []*PropertyValue `json:"properties,omitempty"` + Properties []*CustomPropertyValue `json:"properties,omitempty"` } // GetOrganizationCustomPropertyValues returns all custom property names and their values for an organization. @@ -21,7 +21,7 @@ type OrganizationCustomPropertyValues struct { // GitHub API docs: https://docs.github.com/rest/orgs/custom-properties-for-orgs#get-all-custom-property-values-for-an-organization // //meta:operation GET /organizations/{org}/org-properties/values -func (s *OrganizationsService) GetOrganizationCustomPropertyValues(ctx context.Context, org string) ([]*PropertyValue, *Response, error) { +func (s *OrganizationsService) GetOrganizationCustomPropertyValues(ctx context.Context, org string) ([]*CustomPropertyValue, *Response, error) { u := fmt.Sprintf("organizations/%v/org-properties/values", org) req, err := s.client.NewRequest("GET", u, nil) @@ -29,7 +29,7 @@ func (s *OrganizationsService) GetOrganizationCustomPropertyValues(ctx context.C return nil, nil, err } - var values []*PropertyValue + var values []*CustomPropertyValue resp, err := s.client.Do(ctx, req, &values) if err != nil { return nil, resp, err diff --git a/github/orgs_custom_properties_test.go b/github/orgs_custom_properties_test.go new file mode 100644 index 00000000000..c43d59cfbd3 --- /dev/null +++ b/github/orgs_custom_properties_test.go @@ -0,0 +1,94 @@ +// Copyright 2025 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github + +import ( + "fmt" + "net/http" + "testing" + + "github.com/google/go-cmp/cmp" +) + +func TestOrganizationsService_GetOrganizationCustomPropertyValues(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/organizations/o/org-properties/values", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "GET") + fmt.Fprint(w, `[{ + "property_name": "team", + "value": "core" + }, + { + "property_name": "level", + "value": "gold" + }]`) + }) + + ctx := t.Context() + got, _, err := client.Organizations.GetOrganizationCustomPropertyValues(ctx, "o") + if err != nil { + t.Errorf("Organizations.GetOrganizationCustomPropertyValues returned error: %v", err) + } + + want := []*CustomPropertyValue{ + {PropertyName: "team", Value: Ptr("core")}, + {PropertyName: "level", Value: Ptr("gold")}, + } + + if !cmp.Equal(got, want) { + t.Errorf("Organizations.GetOrganizationCustomPropertyValues = %+v, want %+v", got, want) + } + + const methodName = "GetOrganizationCustomPropertyValues" + + testBadOptions(t, methodName, func() error { + _, _, err := client.Organizations.GetOrganizationCustomPropertyValues(ctx, "\n") + return err + }) + + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + got, resp, err := client.Organizations.GetOrganizationCustomPropertyValues(ctx, "o") + if got != nil { + t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) + } + return resp, err + }) +} + +func TestOrganizationsService_CreateOrUpdateOrgCustomPropertyValues(t *testing.T) { + t.Parallel() + client, mux, _ := setup(t) + + mux.HandleFunc("/organizations/o/org-properties/values", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "PATCH") + fmt.Fprint(w, `{}`) + }) + + ctx := t.Context() + values := []*CustomPropertyValue{ + {PropertyName: "team", Value: Ptr("core")}, + {PropertyName: "level", Value: Ptr("gold")}, + } + + props := OrganizationCustomPropertyValues{ + Properties: values, + } + _, err := client.Organizations.CreateOrUpdateOrgCustomPropertyValues(ctx, "o", props) + if err != nil { + t.Errorf("Organizations.CreateOrUpdateOrgCustomPropertyValues returned error: %v", err) + } + + const methodName = "CreateOrUpdateOrgCustomPropertyValues" + testBadOptions(t, methodName, func() error { + _, err := client.Organizations.CreateOrUpdateOrgCustomPropertyValues(ctx, "\n", props) + return err + }) + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + return client.Organizations.CreateOrUpdateOrgCustomPropertyValues(ctx, "o", props) + }) +} diff --git a/github/orgs_properties.go b/github/orgs_properties.go index 257e765993b..0c23c91b227 100644 --- a/github/orgs_properties.go +++ b/github/orgs_properties.go @@ -17,6 +17,8 @@ type CustomProperty struct { // PropertyName is required for most endpoints except when calling CreateOrUpdateCustomProperty; // where this is sent in the path and thus can be omitted. PropertyName *string `json:"property_name,omitempty"` + // The URL that can be used to fetch, update, or delete info about this property via the API. + URL *string `json:"url,omitempty"` // SourceType is the source type of the property where it has been created. Can be one of: organization, enterprise. SourceType *string `json:"source_type,omitempty"` // The type of the value for the property. Can be one of: string, single_select, multi_select, true_false. diff --git a/github/rules.go b/github/rules.go index a381976421f..dc95abc0fc1 100644 --- a/github/rules.go +++ b/github/rules.go @@ -218,17 +218,10 @@ type RepositoryRulesetRefConditionParameters struct { Exclude []string `json:"exclude"` } -// RepositoryRulesetOrganizationPropertyTargetParameters represents an organization_property name and values to be used for targeting. -type RepositoryRulesetOrganizationPropertyTargetParameters struct { - Name string `json:"name"` - PropertyValues []string `json:"property_values"` - Source *string `json:"source,omitempty"` -} - // RepositoryRulesetOrganizationPropertyConditionParameters represents the conditions object for an organization property selector. type RepositoryRulesetOrganizationPropertyConditionParameters struct { - Include []*RepositoryRulesetOrganizationPropertyTargetParameters `json:"include"` - Exclude []*RepositoryRulesetOrganizationPropertyTargetParameters `json:"exclude"` + Include []*RepositoryRulesetRepositoryPropertyTargetParameters `json:"include"` + Exclude []*RepositoryRulesetRepositoryPropertyTargetParameters `json:"exclude"` } // RepositoryRulesetRepositoryIDsConditionParameters represents the conditions object for repository_id. From 167096035692a00f8274ab919100dced0bf9b00f Mon Sep 17 00:00:00 2001 From: Dhananjay Mishra Date: Wed, 5 Nov 2025 12:21:35 +0000 Subject: [PATCH 05/11] fix test --- github/enterprise_custom_properties_test.go | 16 +++++++++------- github/orgs_custom_properties_test.go | 6 +++--- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/github/enterprise_custom_properties_test.go b/github/enterprise_custom_properties_test.go index 81d62a9bd3a..8f9a39d1391 100644 --- a/github/enterprise_custom_properties_test.go +++ b/github/enterprise_custom_properties_test.go @@ -21,7 +21,7 @@ func TestEnterpriseService_GetEnterpriseCustomPropertySchema(t *testing.T) { testMethod(t, r, "GET") fmt.Fprint(w, `{ "properties": [{ - "name": "team", + "property_name": "team", "value_type": "string", "description": "Team name" }] @@ -31,7 +31,7 @@ func TestEnterpriseService_GetEnterpriseCustomPropertySchema(t *testing.T) { ctx := t.Context() got, _, err := client.Enterprise.GetEnterpriseCustomPropertySchema(ctx, "e") if err != nil { - t.Errorf("Enterprise.GetEnterpriseCustomPropertySchema returned error: %v", err) + t.Fatalf("Enterprise.GetEnterpriseCustomPropertySchema returned error: %v", err) } want := &EnterpriseCustomPropertySchema{ @@ -97,7 +97,7 @@ func TestEnterpriseService_GetEnterpriseCustomProperty(t *testing.T) { mux.HandleFunc("/enterprises/e/org-properties/schema/prop", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") fmt.Fprint(w, `{ - "name": "team", + "property_name": "team", "value_type": "string", "description": "Team name" }`) @@ -106,7 +106,7 @@ func TestEnterpriseService_GetEnterpriseCustomProperty(t *testing.T) { ctx := t.Context() got, _, err := client.Enterprise.GetEnterpriseCustomProperty(ctx, "e", "prop") if err != nil { - t.Errorf("Enterprise.GetEnterpriseCustomProperty returned error: %v", err) + t.Fatalf("Enterprise.GetEnterpriseCustomProperty returned error: %v", err) } want := &CustomProperty{ @@ -193,14 +193,16 @@ func TestEnterpriseService_GetEnterpriseCustomPropertyValues(t *testing.T) { fmt.Fprint(w, `[{ "organization_id": 1, "organization_login": "org1", - "properties": [{"property_name": "team", "value": "core"}] + "properties": [ + {"property_name": "team", "value": "core"} + ] }]`) }) ctx := t.Context() got, _, err := client.Enterprise.GetEnterpriseCustomPropertyValues(ctx, "e", nil) if err != nil { - t.Errorf("Enterprise.GetEnterpriseCustomPropertyValues returned error: %v", err) + t.Fatalf("Enterprise.GetEnterpriseCustomPropertyValues returned error: %v", err) } want := []*EnterpriseCustomPropertiesValues{ @@ -208,7 +210,7 @@ func TestEnterpriseService_GetEnterpriseCustomPropertyValues(t *testing.T) { OrganizationID: Ptr(int64(1)), OrganizationLogin: Ptr("org1"), Properties: []*CustomPropertyValue{ - {PropertyName: "team", Value: Ptr("core")}, + {PropertyName: "team", Value: "core"}, }, }, } diff --git a/github/orgs_custom_properties_test.go b/github/orgs_custom_properties_test.go index c43d59cfbd3..52bda7e60bd 100644 --- a/github/orgs_custom_properties_test.go +++ b/github/orgs_custom_properties_test.go @@ -32,12 +32,12 @@ func TestOrganizationsService_GetOrganizationCustomPropertyValues(t *testing.T) ctx := t.Context() got, _, err := client.Organizations.GetOrganizationCustomPropertyValues(ctx, "o") if err != nil { - t.Errorf("Organizations.GetOrganizationCustomPropertyValues returned error: %v", err) + t.Fatalf("Organizations.GetOrganizationCustomPropertyValues returned error: %v", err) } want := []*CustomPropertyValue{ - {PropertyName: "team", Value: Ptr("core")}, - {PropertyName: "level", Value: Ptr("gold")}, + {PropertyName: "team", Value: "core"}, + {PropertyName: "level", Value: "gold"}, } if !cmp.Equal(got, want) { From 82a1ca0ed4f7116e60786e78f916448728bf11b9 Mon Sep 17 00:00:00 2001 From: Dhananjay Mishra Date: Wed, 5 Nov 2025 13:15:38 +0000 Subject: [PATCH 06/11] test modification --- github/enterprise_custom_properties_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/github/enterprise_custom_properties_test.go b/github/enterprise_custom_properties_test.go index 8f9a39d1391..2146dacf0d2 100644 --- a/github/enterprise_custom_properties_test.go +++ b/github/enterprise_custom_properties_test.go @@ -200,7 +200,8 @@ func TestEnterpriseService_GetEnterpriseCustomPropertyValues(t *testing.T) { }) ctx := t.Context() - got, _, err := client.Enterprise.GetEnterpriseCustomPropertyValues(ctx, "e", nil) + opts := &ListOptions{Page: 1, PerPage: 10} + got, _, err := client.Enterprise.GetEnterpriseCustomPropertyValues(ctx, "e", opts) if err != nil { t.Fatalf("Enterprise.GetEnterpriseCustomPropertyValues returned error: %v", err) } @@ -221,7 +222,7 @@ func TestEnterpriseService_GetEnterpriseCustomPropertyValues(t *testing.T) { const methodName = "GetEnterpriseCustomPropertyValues" testBadOptions(t, methodName, func() error { - _, _, err := client.Enterprise.GetEnterpriseCustomPropertyValues(ctx, "\n", nil) + _, _, err := client.Enterprise.GetEnterpriseCustomPropertyValues(ctx, "\n", opts) return err }) testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { From 46c06b38432c1211a1019642709969e230de4130 Mon Sep 17 00:00:00 2001 From: Dhananjay Mishra Date: Wed, 5 Nov 2025 16:09:12 +0000 Subject: [PATCH 07/11] fix comments and change method name --- github/enterprise_custom_properties.go | 6 +++--- github/enterprise_custom_properties_test.go | 14 +++++++------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/github/enterprise_custom_properties.go b/github/enterprise_custom_properties.go index 0d1c5ab5ae4..a3da7801210 100644 --- a/github/enterprise_custom_properties.go +++ b/github/enterprise_custom_properties.go @@ -35,12 +35,12 @@ type EnterpriseCustomPropertyValuesRequest struct { Properties []*CustomPropertyValue `json:"properties"` } -// GetEnterpriseCustomPropertySchema gives all organization custom property definitions that are defined on an enterprise. +// GetEnterpriseCustomPropertySchema gets all organization custom property definitions that are defined on an enterprise. // // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/custom-properties-for-orgs#get-organization-custom-properties-schema-for-an-enterprise // //meta:operation GET /enterprises/{enterprise}/org-properties/schema -func (s *EnterpriseService) GetEnterpriseCustomPropertySchema(ctx context.Context, enterprise string) (*EnterpriseCustomPropertySchema, *Response, error) { +func (s *EnterpriseService) GetOrganizationCustomPropertySchema(ctx context.Context, enterprise string) (*EnterpriseCustomPropertySchema, *Response, error) { u := fmt.Sprintf("enterprises/%v/org-properties/schema", enterprise) req, err := s.client.NewRequest("GET", u, nil) @@ -167,7 +167,7 @@ func (s *EnterpriseService) GetEnterpriseCustomPropertyValues(ctx context.Contex return values, resp, nil } -// CreateOrUpdateEnterpriseCustomPropertyValues create or update custom property values for organizations in an enterprise. +// CreateOrUpdateEnterpriseCustomPropertyValues creates or updates custom property values for organizations in an enterprise. // To remove a custom property value from an organization, set the property value to null. // // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/custom-properties-for-orgs#create-or-update-custom-property-values-for-organizations-in-an-enterprise diff --git a/github/enterprise_custom_properties_test.go b/github/enterprise_custom_properties_test.go index 2146dacf0d2..08a6339a69b 100644 --- a/github/enterprise_custom_properties_test.go +++ b/github/enterprise_custom_properties_test.go @@ -13,7 +13,7 @@ import ( "github.com/google/go-cmp/cmp" ) -func TestEnterpriseService_GetEnterpriseCustomPropertySchema(t *testing.T) { +func TestEnterpriseService_GetOrganizationCustomPropertySchema(t *testing.T) { t.Parallel() client, mux, _ := setup(t) @@ -29,9 +29,9 @@ func TestEnterpriseService_GetEnterpriseCustomPropertySchema(t *testing.T) { }) ctx := t.Context() - got, _, err := client.Enterprise.GetEnterpriseCustomPropertySchema(ctx, "e") + got, _, err := client.Enterprise.GetOrganizationCustomPropertySchema(ctx, "e") if err != nil { - t.Fatalf("Enterprise.GetEnterpriseCustomPropertySchema returned error: %v", err) + t.Fatalf("Enterprise.GetOrganizationCustomPropertySchema returned error: %v", err) } want := &EnterpriseCustomPropertySchema{ @@ -45,16 +45,16 @@ func TestEnterpriseService_GetEnterpriseCustomPropertySchema(t *testing.T) { } if !cmp.Equal(got, want) { - t.Errorf("Enterprise.GetEnterpriseCustomPropertySchema = %+v, want %+v", got, want) + t.Errorf("Enterprise.GetOrganizationCustomPropertySchema = %+v, want %+v", got, want) } - const methodName = "GetEnterpriseCustomPropertySchema" + const methodName = "GetOrganizationCustomPropertySchema" testBadOptions(t, methodName, func() error { - _, _, err := client.Enterprise.GetEnterpriseCustomPropertySchema(ctx, "\n") + _, _, err := client.Enterprise.GetOrganizationCustomPropertySchema(ctx, "\n") return err }) testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - got, resp, err := client.Enterprise.GetEnterpriseCustomPropertySchema(ctx, "e") + got, resp, err := client.Enterprise.GetOrganizationCustomPropertySchema(ctx, "e") if got != nil { t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) } From a97d7781eedca54cde112ff59746028e8d81fb14 Mon Sep 17 00:00:00 2001 From: Dhananjay Mishra Date: Wed, 5 Nov 2025 16:15:21 +0000 Subject: [PATCH 08/11] change method names --- github/enterprise_custom_properties.go | 20 +++---- github/enterprise_custom_properties_test.go | 64 ++++++++++----------- 2 files changed, 42 insertions(+), 42 deletions(-) diff --git a/github/enterprise_custom_properties.go b/github/enterprise_custom_properties.go index a3da7801210..82d4d6e841c 100644 --- a/github/enterprise_custom_properties.go +++ b/github/enterprise_custom_properties.go @@ -57,12 +57,12 @@ func (s *EnterpriseService) GetOrganizationCustomPropertySchema(ctx context.Cont return schema, resp, nil } -// CreateOrUpdateEnterpriseCustomPropertySchema creates new or updates existing organization custom properties defined on an enterprise in a batch. +// CreateOrUpdateOrganizationCustomPropertySchema creates new or updates existing organization custom properties defined on an enterprise in a batch. // // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/custom-properties-for-orgs#create-or-update-organization-custom-property-definitions-on-an-enterprise // //meta:operation PATCH /enterprises/{enterprise}/org-properties/schema -func (s *EnterpriseService) CreateOrUpdateEnterpriseCustomPropertySchema(ctx context.Context, enterprise string, schema EnterpriseCustomPropertySchema) (*Response, error) { +func (s *EnterpriseService) CreateOrUpdateOrganizationCustomPropertySchema(ctx context.Context, enterprise string, schema EnterpriseCustomPropertySchema) (*Response, error) { u := fmt.Sprintf("enterprises/%v/org-properties/schema", enterprise) req, err := s.client.NewRequest("PATCH", u, schema) if err != nil { @@ -77,12 +77,12 @@ func (s *EnterpriseService) CreateOrUpdateEnterpriseCustomPropertySchema(ctx con return resp, nil } -// GetEnterpriseCustomProperty retrieves a specific organization custom property definition from an enterprise. +// GetOrganizationCustomProperty retrieves a specific organization custom property definition from an enterprise. // // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/custom-properties-for-orgs#get-an-organization-custom-property-definition-from-an-enterprise // //meta:operation GET /enterprises/{enterprise}/org-properties/schema/{custom_property_name} -func (s *EnterpriseService) GetEnterpriseCustomProperty(ctx context.Context, enterprise, customPropertyName string) (*CustomProperty, *Response, error) { +func (s *EnterpriseService) GetOrganizationCustomProperty(ctx context.Context, enterprise, customPropertyName string) (*CustomProperty, *Response, error) { u := fmt.Sprintf("enterprises/%v/org-properties/schema/%v", enterprise, customPropertyName) req, err := s.client.NewRequest("GET", u, nil) @@ -99,12 +99,12 @@ func (s *EnterpriseService) GetEnterpriseCustomProperty(ctx context.Context, ent return property, resp, nil } -// CreateOrUpdateEnterpriseCustomProperty creates a new or updates an existing organization custom property definition that is defined on an enterprise. +// CreateOrUpdateOrganizationCustomProperty creates a new or updates an existing organization custom property definition that is defined on an enterprise. // // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/custom-properties-for-orgs#create-or-update-an-organization-custom-property-definition-on-an-enterprise // //meta:operation PUT /enterprises/{enterprise}/org-properties/schema/{custom_property_name} -func (s *EnterpriseService) CreateOrUpdateEnterpriseCustomProperty(ctx context.Context, enterprise, customPropertyName string, property CustomProperty) (*Response, error) { +func (s *EnterpriseService) CreateOrUpdateOrganizationCustomProperty(ctx context.Context, enterprise, customPropertyName string, property CustomProperty) (*Response, error) { u := fmt.Sprintf("enterprises/%v/org-properties/schema/%v", enterprise, customPropertyName) req, err := s.client.NewRequest("PUT", u, property) if err != nil { @@ -119,12 +119,12 @@ func (s *EnterpriseService) CreateOrUpdateEnterpriseCustomProperty(ctx context.C return resp, nil } -// DeleteEnterpriseCustomProperty removes an organization custom property definition that is defined on an enterprise. +// DeleteOrganizationCustomProperty removes an organization custom property definition that is defined on an enterprise. // // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/custom-properties-for-orgs#remove-an-organization-custom-property-definition-from-an-enterprise // //meta:operation DELETE /enterprises/{enterprise}/org-properties/schema/{custom_property_name} -func (s *EnterpriseService) DeleteEnterpriseCustomProperty(ctx context.Context, enterprise, customPropertyName string) (*Response, error) { +func (s *EnterpriseService) DeleteOrganizationCustomProperty(ctx context.Context, enterprise, customPropertyName string) (*Response, error) { u := fmt.Sprintf("enterprises/%v/org-properties/schema/%v", enterprise, customPropertyName) req, err := s.client.NewRequest("DELETE", u, nil) if err != nil { @@ -139,13 +139,13 @@ func (s *EnterpriseService) DeleteEnterpriseCustomProperty(ctx context.Context, return resp, nil } -// GetEnterpriseCustomPropertyValues lists enterprise organizations with all of their custom property values. +// ListEnterpriseCustomPropertyValues lists enterprise organizations with all of their custom property values. // Returns a list of organizations and their custom property values defined in the enterprise. // // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/custom-properties-for-orgs#list-custom-property-values-for-organizations-in-an-enterprise // //meta:operation GET /enterprises/{enterprise}/org-properties/values -func (s *EnterpriseService) GetEnterpriseCustomPropertyValues(ctx context.Context, enterprise string, opts *ListOptions) ([]*EnterpriseCustomPropertiesValues, *Response, error) { +func (s *EnterpriseService) ListEnterpriseCustomPropertyValues(ctx context.Context, enterprise string, opts *ListOptions) ([]*EnterpriseCustomPropertiesValues, *Response, error) { u := fmt.Sprintf("enterprises/%v/org-properties/values", enterprise) u, err := addOptions(u, opts) diff --git a/github/enterprise_custom_properties_test.go b/github/enterprise_custom_properties_test.go index 08a6339a69b..55d6dd18a28 100644 --- a/github/enterprise_custom_properties_test.go +++ b/github/enterprise_custom_properties_test.go @@ -62,7 +62,7 @@ func TestEnterpriseService_GetOrganizationCustomPropertySchema(t *testing.T) { }) } -func TestEnterpriseService_CreateOrUpdateEnterpriseCustomPropertySchema(t *testing.T) { +func TestEnterpriseService_CreateOrUpdateOrganizationCustomPropertySchema(t *testing.T) { t.Parallel() client, mux, _ := setup(t) @@ -75,22 +75,22 @@ func TestEnterpriseService_CreateOrUpdateEnterpriseCustomPropertySchema(t *testi schema := EnterpriseCustomPropertySchema{ Properties: []*CustomProperty{{PropertyName: Ptr("team")}}, } - _, err := client.Enterprise.CreateOrUpdateEnterpriseCustomPropertySchema(ctx, "e", schema) + _, err := client.Enterprise.CreateOrUpdateOrganizationCustomPropertySchema(ctx, "e", schema) if err != nil { - t.Errorf("Enterprise.CreateOrUpdateEnterpriseCustomPropertySchema returned error: %v", err) + t.Errorf("Enterprise.CreateOrUpdateOrganizationCustomPropertySchema returned error: %v", err) } - const methodName = "CreateOrUpdateEnterpriseCustomPropertySchema" + const methodName = "CreateOrUpdateOrganizationCustomPropertySchema" testBadOptions(t, methodName, func() error { - _, err := client.Enterprise.CreateOrUpdateEnterpriseCustomPropertySchema(ctx, "\n", schema) + _, err := client.Enterprise.CreateOrUpdateOrganizationCustomPropertySchema(ctx, "\n", schema) return err }) testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - return client.Enterprise.CreateOrUpdateEnterpriseCustomPropertySchema(ctx, "e", schema) + return client.Enterprise.CreateOrUpdateOrganizationCustomPropertySchema(ctx, "e", schema) }) } -func TestEnterpriseService_GetEnterpriseCustomProperty(t *testing.T) { +func TestEnterpriseService_GetOrganizationCustomProperty(t *testing.T) { t.Parallel() client, mux, _ := setup(t) @@ -104,9 +104,9 @@ func TestEnterpriseService_GetEnterpriseCustomProperty(t *testing.T) { }) ctx := t.Context() - got, _, err := client.Enterprise.GetEnterpriseCustomProperty(ctx, "e", "prop") + got, _, err := client.Enterprise.GetOrganizationCustomProperty(ctx, "e", "prop") if err != nil { - t.Fatalf("Enterprise.GetEnterpriseCustomProperty returned error: %v", err) + t.Fatalf("Enterprise.GetOrganizationCustomProperty returned error: %v", err) } want := &CustomProperty{ @@ -116,16 +116,16 @@ func TestEnterpriseService_GetEnterpriseCustomProperty(t *testing.T) { } if !cmp.Equal(got, want) { - t.Errorf("Enterprise.GetEnterpriseCustomProperty = %+v, want %+v", got, want) + t.Errorf("Enterprise.GetOrganizationCustomProperty = %+v, want %+v", got, want) } - const methodName = "GetEnterpriseCustomProperty" + const methodName = "GetOrganizationCustomProperty" testBadOptions(t, methodName, func() error { - _, _, err := client.Enterprise.GetEnterpriseCustomProperty(ctx, "\n", "prop") + _, _, err := client.Enterprise.GetOrganizationCustomProperty(ctx, "\n", "prop") return err }) testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - got, resp, err := client.Enterprise.GetEnterpriseCustomProperty(ctx, "e", "prop") + got, resp, err := client.Enterprise.GetOrganizationCustomProperty(ctx, "e", "prop") if got != nil { t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) } @@ -133,7 +133,7 @@ func TestEnterpriseService_GetEnterpriseCustomProperty(t *testing.T) { }) } -func TestEnterpriseService_CreateOrUpdateEnterpriseCustomProperty(t *testing.T) { +func TestEnterpriseService_CreateOrUpdateOrganizationCustomProperty(t *testing.T) { t.Parallel() client, mux, _ := setup(t) @@ -144,22 +144,22 @@ func TestEnterpriseService_CreateOrUpdateEnterpriseCustomProperty(t *testing.T) ctx := t.Context() property := CustomProperty{PropertyName: Ptr("team")} - _, err := client.Enterprise.CreateOrUpdateEnterpriseCustomProperty(ctx, "e", "prop", property) + _, err := client.Enterprise.CreateOrUpdateOrganizationCustomProperty(ctx, "e", "prop", property) if err != nil { - t.Errorf("Enterprise.CreateOrUpdateEnterpriseCustomProperty returned error: %v", err) + t.Errorf("Enterprise.CreateOrUpdateOrganizationCustomProperty returned error: %v", err) } - const methodName = "CreateOrUpdateEnterpriseCustomProperty" + const methodName = "CreateOrUpdateOrganizationCustomProperty" testBadOptions(t, methodName, func() error { - _, err := client.Enterprise.CreateOrUpdateEnterpriseCustomProperty(ctx, "\n", "prop", property) + _, err := client.Enterprise.CreateOrUpdateOrganizationCustomProperty(ctx, "\n", "prop", property) return err }) testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - return client.Enterprise.CreateOrUpdateEnterpriseCustomProperty(ctx, "e", "prop", property) + return client.Enterprise.CreateOrUpdateOrganizationCustomProperty(ctx, "e", "prop", property) }) } -func TestEnterpriseService_DeleteEnterpriseCustomProperty(t *testing.T) { +func TestEnterpriseService_DeleteOrganizationCustomProperty(t *testing.T) { t.Parallel() client, mux, _ := setup(t) @@ -169,22 +169,22 @@ func TestEnterpriseService_DeleteEnterpriseCustomProperty(t *testing.T) { }) ctx := t.Context() - _, err := client.Enterprise.DeleteEnterpriseCustomProperty(ctx, "e", "prop") + _, err := client.Enterprise.DeleteOrganizationCustomProperty(ctx, "e", "prop") if err != nil { - t.Errorf("Enterprise.DeleteEnterpriseCustomProperty returned error: %v", err) + t.Errorf("Enterprise.DeleteOrganizationCustomProperty returned error: %v", err) } - const methodName = "DeleteEnterpriseCustomProperty" + const methodName = "DeleteOrganizationCustomProperty" testBadOptions(t, methodName, func() error { - _, err := client.Enterprise.DeleteEnterpriseCustomProperty(ctx, "\n", "prop") + _, err := client.Enterprise.DeleteOrganizationCustomProperty(ctx, "\n", "prop") return err }) testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - return client.Enterprise.DeleteEnterpriseCustomProperty(ctx, "e", "prop") + return client.Enterprise.DeleteOrganizationCustomProperty(ctx, "e", "prop") }) } -func TestEnterpriseService_GetEnterpriseCustomPropertyValues(t *testing.T) { +func TestEnterpriseService_ListEnterpriseCustomPropertyValues(t *testing.T) { t.Parallel() client, mux, _ := setup(t) @@ -201,9 +201,9 @@ func TestEnterpriseService_GetEnterpriseCustomPropertyValues(t *testing.T) { ctx := t.Context() opts := &ListOptions{Page: 1, PerPage: 10} - got, _, err := client.Enterprise.GetEnterpriseCustomPropertyValues(ctx, "e", opts) + got, _, err := client.Enterprise.ListEnterpriseCustomPropertyValues(ctx, "e", opts) if err != nil { - t.Fatalf("Enterprise.GetEnterpriseCustomPropertyValues returned error: %v", err) + t.Fatalf("Enterprise.ListEnterpriseCustomPropertyValues returned error: %v", err) } want := []*EnterpriseCustomPropertiesValues{ @@ -217,16 +217,16 @@ func TestEnterpriseService_GetEnterpriseCustomPropertyValues(t *testing.T) { } if !cmp.Equal(got, want) { - t.Errorf("Enterprise.GetEnterpriseCustomPropertyValues = %+v, want %+v", got, want) + t.Errorf("Enterprise.ListEnterpriseCustomPropertyValues = %+v, want %+v", got, want) } - const methodName = "GetEnterpriseCustomPropertyValues" + const methodName = "ListEnterpriseCustomPropertyValues" testBadOptions(t, methodName, func() error { - _, _, err := client.Enterprise.GetEnterpriseCustomPropertyValues(ctx, "\n", opts) + _, _, err := client.Enterprise.ListEnterpriseCustomPropertyValues(ctx, "\n", opts) return err }) testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - got, resp, err := client.Enterprise.GetEnterpriseCustomPropertyValues(ctx, "e", nil) + got, resp, err := client.Enterprise.ListEnterpriseCustomPropertyValues(ctx, "e", nil) if got != nil { t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) } From 01b95e5c5d39507c78ab6790ca7c1c62a84f750c Mon Sep 17 00:00:00 2001 From: Dhananjay Mishra Date: Wed, 5 Nov 2025 16:21:02 +0000 Subject: [PATCH 09/11] fix lint error --- github/enterprise_custom_properties.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/github/enterprise_custom_properties.go b/github/enterprise_custom_properties.go index 82d4d6e841c..7204a3afe79 100644 --- a/github/enterprise_custom_properties.go +++ b/github/enterprise_custom_properties.go @@ -35,7 +35,7 @@ type EnterpriseCustomPropertyValuesRequest struct { Properties []*CustomPropertyValue `json:"properties"` } -// GetEnterpriseCustomPropertySchema gets all organization custom property definitions that are defined on an enterprise. +// GetOrganizationCustomPropertySchema gets all organization custom property definitions that are defined on an enterprise. // // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/custom-properties-for-orgs#get-organization-custom-properties-schema-for-an-enterprise // From 13f79d5c6d1a1024c3f3a486bf93fb0b9d5c552c Mon Sep 17 00:00:00 2001 From: Dhananjay Mishra Date: Thu, 6 Nov 2025 10:35:54 +0000 Subject: [PATCH 10/11] fix comment --- github/orgs_custom_properties.go | 1 + 1 file changed, 1 insertion(+) diff --git a/github/orgs_custom_properties.go b/github/orgs_custom_properties.go index 9dd1bfb26ba..8459e195c0a 100644 --- a/github/orgs_custom_properties.go +++ b/github/orgs_custom_properties.go @@ -39,6 +39,7 @@ func (s *OrganizationsService) GetOrganizationCustomPropertyValues(ctx context.C } // CreateOrUpdateOrgCustomPropertyValues creates or updates custom property values for an organization. +// To remove a custom property value from an organization, set the property value to null. // // GitHub API docs: https://docs.github.com/rest/orgs/custom-properties-for-orgs#create-or-update-custom-property-values-for-an-organization // From 8a52a7efd4c4491b511f9fadffc88e35eb14ae6c Mon Sep 17 00:00:00 2001 From: Dhananjay Mishra Date: Fri, 7 Nov 2025 03:23:10 +0000 Subject: [PATCH 11/11] change filename --- ... => enterprise_organization_properties.go} | 8 +++---- ...nterprise_organization_properties_test.go} | 24 +++++++++---------- ...ies.go => orgs_organization_properties.go} | 4 ++-- ...o => orgs_organization_properties_test.go} | 12 +++++----- 4 files changed, 24 insertions(+), 24 deletions(-) rename github/{enterprise_custom_properties.go => enterprise_organization_properties.go} (92%) rename github/{enterprise_custom_properties_test.go => enterprise_organization_properties_test.go} (87%) rename github/{orgs_custom_properties.go => orgs_organization_properties.go} (86%) rename github/{orgs_custom_properties_test.go => orgs_organization_properties_test.go} (80%) diff --git a/github/enterprise_custom_properties.go b/github/enterprise_organization_properties.go similarity index 92% rename from github/enterprise_custom_properties.go rename to github/enterprise_organization_properties.go index 7204a3afe79..01a646b38aa 100644 --- a/github/enterprise_custom_properties.go +++ b/github/enterprise_organization_properties.go @@ -139,13 +139,13 @@ func (s *EnterpriseService) DeleteOrganizationCustomProperty(ctx context.Context return resp, nil } -// ListEnterpriseCustomPropertyValues lists enterprise organizations with all of their custom property values. +// ListOrganizationCustomPropertyValues lists enterprise organizations with all of their custom property values. // Returns a list of organizations and their custom property values defined in the enterprise. // // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/custom-properties-for-orgs#list-custom-property-values-for-organizations-in-an-enterprise // //meta:operation GET /enterprises/{enterprise}/org-properties/values -func (s *EnterpriseService) ListEnterpriseCustomPropertyValues(ctx context.Context, enterprise string, opts *ListOptions) ([]*EnterpriseCustomPropertiesValues, *Response, error) { +func (s *EnterpriseService) ListOrganizationCustomPropertyValues(ctx context.Context, enterprise string, opts *ListOptions) ([]*EnterpriseCustomPropertiesValues, *Response, error) { u := fmt.Sprintf("enterprises/%v/org-properties/values", enterprise) u, err := addOptions(u, opts) @@ -167,13 +167,13 @@ func (s *EnterpriseService) ListEnterpriseCustomPropertyValues(ctx context.Conte return values, resp, nil } -// CreateOrUpdateEnterpriseCustomPropertyValues creates or updates custom property values for organizations in an enterprise. +// CreateOrUpdateOrganizationCustomPropertyValues creates or updates custom property values for organizations in an enterprise. // To remove a custom property value from an organization, set the property value to null. // // GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/custom-properties-for-orgs#create-or-update-custom-property-values-for-organizations-in-an-enterprise // //meta:operation PATCH /enterprises/{enterprise}/org-properties/values -func (s *EnterpriseService) CreateOrUpdateEnterpriseCustomPropertyValues(ctx context.Context, enterprise string, values EnterpriseCustomPropertyValuesRequest) (*Response, error) { +func (s *EnterpriseService) CreateOrUpdateOrganizationCustomPropertyValues(ctx context.Context, enterprise string, values EnterpriseCustomPropertyValuesRequest) (*Response, error) { u := fmt.Sprintf("enterprises/%v/org-properties/values", enterprise) req, err := s.client.NewRequest("PATCH", u, values) if err != nil { diff --git a/github/enterprise_custom_properties_test.go b/github/enterprise_organization_properties_test.go similarity index 87% rename from github/enterprise_custom_properties_test.go rename to github/enterprise_organization_properties_test.go index 55d6dd18a28..2248285bd3f 100644 --- a/github/enterprise_custom_properties_test.go +++ b/github/enterprise_organization_properties_test.go @@ -184,7 +184,7 @@ func TestEnterpriseService_DeleteOrganizationCustomProperty(t *testing.T) { }) } -func TestEnterpriseService_ListEnterpriseCustomPropertyValues(t *testing.T) { +func TestEnterpriseService_ListOrganizationCustomPropertyValues(t *testing.T) { t.Parallel() client, mux, _ := setup(t) @@ -201,9 +201,9 @@ func TestEnterpriseService_ListEnterpriseCustomPropertyValues(t *testing.T) { ctx := t.Context() opts := &ListOptions{Page: 1, PerPage: 10} - got, _, err := client.Enterprise.ListEnterpriseCustomPropertyValues(ctx, "e", opts) + got, _, err := client.Enterprise.ListOrganizationCustomPropertyValues(ctx, "e", opts) if err != nil { - t.Fatalf("Enterprise.ListEnterpriseCustomPropertyValues returned error: %v", err) + t.Fatalf("Enterprise.ListOrganizationCustomPropertyValues returned error: %v", err) } want := []*EnterpriseCustomPropertiesValues{ @@ -217,16 +217,16 @@ func TestEnterpriseService_ListEnterpriseCustomPropertyValues(t *testing.T) { } if !cmp.Equal(got, want) { - t.Errorf("Enterprise.ListEnterpriseCustomPropertyValues = %+v, want %+v", got, want) + t.Errorf("Enterprise.ListOrganizationCustomPropertyValues = %+v, want %+v", got, want) } const methodName = "ListEnterpriseCustomPropertyValues" testBadOptions(t, methodName, func() error { - _, _, err := client.Enterprise.ListEnterpriseCustomPropertyValues(ctx, "\n", opts) + _, _, err := client.Enterprise.ListOrganizationCustomPropertyValues(ctx, "\n", opts) return err }) testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - got, resp, err := client.Enterprise.ListEnterpriseCustomPropertyValues(ctx, "e", nil) + got, resp, err := client.Enterprise.ListOrganizationCustomPropertyValues(ctx, "e", nil) if got != nil { t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) } @@ -234,7 +234,7 @@ func TestEnterpriseService_ListEnterpriseCustomPropertyValues(t *testing.T) { }) } -func TestEnterpriseService_CreateOrUpdateEnterpriseCustomPropertyValues(t *testing.T) { +func TestEnterpriseService_CreateOrUpdateOrganizationCustomPropertyValues(t *testing.T) { t.Parallel() client, mux, _ := setup(t) @@ -251,17 +251,17 @@ func TestEnterpriseService_CreateOrUpdateEnterpriseCustomPropertyValues(t *testi OrganizationLogin: orgs, Properties: values, } - _, err := client.Enterprise.CreateOrUpdateEnterpriseCustomPropertyValues(ctx, "e", opts) + _, err := client.Enterprise.CreateOrUpdateOrganizationCustomPropertyValues(ctx, "e", opts) if err != nil { - t.Errorf("Enterprise.CreateOrUpdateEnterpriseCustomPropertyValues returned error: %v", err) + t.Errorf("Enterprise.CreateOrUpdateOrganizationCustomPropertyValues returned error: %v", err) } - const methodName = "CreateOrUpdateEnterpriseCustomPropertyValues" + const methodName = "CreateOrUpdateOrganizationCustomPropertyValues" testBadOptions(t, methodName, func() error { - _, err := client.Enterprise.CreateOrUpdateEnterpriseCustomPropertyValues(ctx, "\n", opts) + _, err := client.Enterprise.CreateOrUpdateOrganizationCustomPropertyValues(ctx, "\n", opts) return err }) testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - return client.Enterprise.CreateOrUpdateEnterpriseCustomPropertyValues(ctx, "e", opts) + return client.Enterprise.CreateOrUpdateOrganizationCustomPropertyValues(ctx, "e", opts) }) } diff --git a/github/orgs_custom_properties.go b/github/orgs_organization_properties.go similarity index 86% rename from github/orgs_custom_properties.go rename to github/orgs_organization_properties.go index 8459e195c0a..ef997ec7996 100644 --- a/github/orgs_custom_properties.go +++ b/github/orgs_organization_properties.go @@ -38,13 +38,13 @@ func (s *OrganizationsService) GetOrganizationCustomPropertyValues(ctx context.C return values, resp, nil } -// CreateOrUpdateOrgCustomPropertyValues creates or updates custom property values for an organization. +// CreateOrUpdateOrganizationCustomPropertyValues creates or updates custom property values for an organization. // To remove a custom property value from an organization, set the property value to null. // // GitHub API docs: https://docs.github.com/rest/orgs/custom-properties-for-orgs#create-or-update-custom-property-values-for-an-organization // //meta:operation PATCH /organizations/{org}/org-properties/values -func (s *OrganizationsService) CreateOrUpdateOrgCustomPropertyValues(ctx context.Context, org string, values OrganizationCustomPropertyValues) (*Response, error) { +func (s *OrganizationsService) CreateOrUpdateOrganizationCustomPropertyValues(ctx context.Context, org string, values OrganizationCustomPropertyValues) (*Response, error) { u := fmt.Sprintf("organizations/%v/org-properties/values", org) req, err := s.client.NewRequest("PATCH", u, values) if err != nil { diff --git a/github/orgs_custom_properties_test.go b/github/orgs_organization_properties_test.go similarity index 80% rename from github/orgs_custom_properties_test.go rename to github/orgs_organization_properties_test.go index 52bda7e60bd..e7bc715c164 100644 --- a/github/orgs_custom_properties_test.go +++ b/github/orgs_organization_properties_test.go @@ -60,7 +60,7 @@ func TestOrganizationsService_GetOrganizationCustomPropertyValues(t *testing.T) }) } -func TestOrganizationsService_CreateOrUpdateOrgCustomPropertyValues(t *testing.T) { +func TestOrganizationsService_CreateOrUpdateOrganizationCustomPropertyValues(t *testing.T) { t.Parallel() client, mux, _ := setup(t) @@ -78,17 +78,17 @@ func TestOrganizationsService_CreateOrUpdateOrgCustomPropertyValues(t *testing.T props := OrganizationCustomPropertyValues{ Properties: values, } - _, err := client.Organizations.CreateOrUpdateOrgCustomPropertyValues(ctx, "o", props) + _, err := client.Organizations.CreateOrUpdateOrganizationCustomPropertyValues(ctx, "o", props) if err != nil { - t.Errorf("Organizations.CreateOrUpdateOrgCustomPropertyValues returned error: %v", err) + t.Errorf("Organizations.CreateOrUpdateOrganizationCustomPropertyValues returned error: %v", err) } - const methodName = "CreateOrUpdateOrgCustomPropertyValues" + const methodName = "CreateOrUpdateOrganizationCustomPropertyValues" testBadOptions(t, methodName, func() error { - _, err := client.Organizations.CreateOrUpdateOrgCustomPropertyValues(ctx, "\n", props) + _, err := client.Organizations.CreateOrUpdateOrganizationCustomPropertyValues(ctx, "\n", props) return err }) testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - return client.Organizations.CreateOrUpdateOrgCustomPropertyValues(ctx, "o", props) + return client.Organizations.CreateOrUpdateOrganizationCustomPropertyValues(ctx, "o", props) }) }