Skip to content

Commit 9c16433

Browse files
Add support for new custom properties for orgs APIs (#3804)
1 parent 8a32731 commit 9c16433

8 files changed

+698
-6
lines changed
Lines changed: 189 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,189 @@
1+
// Copyright 2025 The go-github AUTHORS. All rights reserved.
2+
//
3+
// Use of this source code is governed by a BSD-style
4+
// license that can be found in the LICENSE file.
5+
6+
package github
7+
8+
import (
9+
"context"
10+
"fmt"
11+
)
12+
13+
// EnterpriseCustomPropertySchema represents the schema response for GetEnterpriseCustomPropertiesSchema.
14+
type EnterpriseCustomPropertySchema struct {
15+
// An ordered list of the custom property defined in the enterprise.
16+
Properties []*CustomProperty `json:"properties,omitempty"`
17+
}
18+
19+
// EnterpriseCustomPropertiesValues represents the custom properties values for an organization within an enterprise.
20+
type EnterpriseCustomPropertiesValues struct {
21+
// The Organization ID that the custom property values will be applied to.
22+
OrganizationID *int64 `json:"organization_id,omitempty"`
23+
// The names of organizations that the custom property values will be applied to.
24+
OrganizationLogin *string `json:"organization_login,omitempty"`
25+
// List of custom property names and associated values to apply to the organizations.
26+
Properties []*CustomPropertyValue `json:"properties,omitempty"`
27+
}
28+
29+
// EnterpriseCustomPropertyValuesRequest represents the request to update custom property values for organizations within an enterprise.
30+
type EnterpriseCustomPropertyValuesRequest struct {
31+
// The names of organizations that the custom property values will be applied to.
32+
// OrganizationLogin specifies the organization name when updating multiple organizations.
33+
OrganizationLogin []string `json:"organization_login"`
34+
// List of custom property names and associated values to apply to the organizations.
35+
Properties []*CustomPropertyValue `json:"properties"`
36+
}
37+
38+
// GetOrganizationCustomPropertySchema gets all organization custom property definitions that are defined on an enterprise.
39+
//
40+
// 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
41+
//
42+
//meta:operation GET /enterprises/{enterprise}/org-properties/schema
43+
func (s *EnterpriseService) GetOrganizationCustomPropertySchema(ctx context.Context, enterprise string) (*EnterpriseCustomPropertySchema, *Response, error) {
44+
u := fmt.Sprintf("enterprises/%v/org-properties/schema", enterprise)
45+
46+
req, err := s.client.NewRequest("GET", u, nil)
47+
if err != nil {
48+
return nil, nil, err
49+
}
50+
51+
var schema *EnterpriseCustomPropertySchema
52+
resp, err := s.client.Do(ctx, req, &schema)
53+
if err != nil {
54+
return nil, resp, err
55+
}
56+
57+
return schema, resp, nil
58+
}
59+
60+
// CreateOrUpdateOrganizationCustomPropertySchema creates new or updates existing organization custom properties defined on an enterprise in a batch.
61+
//
62+
// 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
63+
//
64+
//meta:operation PATCH /enterprises/{enterprise}/org-properties/schema
65+
func (s *EnterpriseService) CreateOrUpdateOrganizationCustomPropertySchema(ctx context.Context, enterprise string, schema EnterpriseCustomPropertySchema) (*Response, error) {
66+
u := fmt.Sprintf("enterprises/%v/org-properties/schema", enterprise)
67+
req, err := s.client.NewRequest("PATCH", u, schema)
68+
if err != nil {
69+
return nil, err
70+
}
71+
72+
resp, err := s.client.Do(ctx, req, nil)
73+
if err != nil {
74+
return resp, err
75+
}
76+
77+
return resp, nil
78+
}
79+
80+
// GetOrganizationCustomProperty retrieves a specific organization custom property definition from an enterprise.
81+
//
82+
// 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
83+
//
84+
//meta:operation GET /enterprises/{enterprise}/org-properties/schema/{custom_property_name}
85+
func (s *EnterpriseService) GetOrganizationCustomProperty(ctx context.Context, enterprise, customPropertyName string) (*CustomProperty, *Response, error) {
86+
u := fmt.Sprintf("enterprises/%v/org-properties/schema/%v", enterprise, customPropertyName)
87+
88+
req, err := s.client.NewRequest("GET", u, nil)
89+
if err != nil {
90+
return nil, nil, err
91+
}
92+
93+
var property *CustomProperty
94+
resp, err := s.client.Do(ctx, req, &property)
95+
if err != nil {
96+
return nil, resp, err
97+
}
98+
99+
return property, resp, nil
100+
}
101+
102+
// CreateOrUpdateOrganizationCustomProperty creates a new or updates an existing organization custom property definition that is defined on an enterprise.
103+
//
104+
// 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
105+
//
106+
//meta:operation PUT /enterprises/{enterprise}/org-properties/schema/{custom_property_name}
107+
func (s *EnterpriseService) CreateOrUpdateOrganizationCustomProperty(ctx context.Context, enterprise, customPropertyName string, property CustomProperty) (*Response, error) {
108+
u := fmt.Sprintf("enterprises/%v/org-properties/schema/%v", enterprise, customPropertyName)
109+
req, err := s.client.NewRequest("PUT", u, property)
110+
if err != nil {
111+
return nil, err
112+
}
113+
114+
resp, err := s.client.Do(ctx, req, nil)
115+
if err != nil {
116+
return resp, err
117+
}
118+
119+
return resp, nil
120+
}
121+
122+
// DeleteOrganizationCustomProperty removes an organization custom property definition that is defined on an enterprise.
123+
//
124+
// 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
125+
//
126+
//meta:operation DELETE /enterprises/{enterprise}/org-properties/schema/{custom_property_name}
127+
func (s *EnterpriseService) DeleteOrganizationCustomProperty(ctx context.Context, enterprise, customPropertyName string) (*Response, error) {
128+
u := fmt.Sprintf("enterprises/%v/org-properties/schema/%v", enterprise, customPropertyName)
129+
req, err := s.client.NewRequest("DELETE", u, nil)
130+
if err != nil {
131+
return nil, err
132+
}
133+
134+
resp, err := s.client.Do(ctx, req, nil)
135+
if err != nil {
136+
return resp, err
137+
}
138+
139+
return resp, nil
140+
}
141+
142+
// ListOrganizationCustomPropertyValues lists enterprise organizations with all of their custom property values.
143+
// Returns a list of organizations and their custom property values defined in the enterprise.
144+
//
145+
// 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
146+
//
147+
//meta:operation GET /enterprises/{enterprise}/org-properties/values
148+
func (s *EnterpriseService) ListOrganizationCustomPropertyValues(ctx context.Context, enterprise string, opts *ListOptions) ([]*EnterpriseCustomPropertiesValues, *Response, error) {
149+
u := fmt.Sprintf("enterprises/%v/org-properties/values", enterprise)
150+
151+
u, err := addOptions(u, opts)
152+
if err != nil {
153+
return nil, nil, err
154+
}
155+
156+
req, err := s.client.NewRequest("GET", u, nil)
157+
if err != nil {
158+
return nil, nil, err
159+
}
160+
161+
var values []*EnterpriseCustomPropertiesValues
162+
resp, err := s.client.Do(ctx, req, &values)
163+
if err != nil {
164+
return nil, resp, err
165+
}
166+
167+
return values, resp, nil
168+
}
169+
170+
// CreateOrUpdateOrganizationCustomPropertyValues creates or updates custom property values for organizations in an enterprise.
171+
// To remove a custom property value from an organization, set the property value to null.
172+
//
173+
// 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
174+
//
175+
//meta:operation PATCH /enterprises/{enterprise}/org-properties/values
176+
func (s *EnterpriseService) CreateOrUpdateOrganizationCustomPropertyValues(ctx context.Context, enterprise string, values EnterpriseCustomPropertyValuesRequest) (*Response, error) {
177+
u := fmt.Sprintf("enterprises/%v/org-properties/values", enterprise)
178+
req, err := s.client.NewRequest("PATCH", u, values)
179+
if err != nil {
180+
return nil, err
181+
}
182+
183+
resp, err := s.client.Do(ctx, req, nil)
184+
if err != nil {
185+
return resp, err
186+
}
187+
188+
return resp, nil
189+
}

0 commit comments

Comments
 (0)