-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy pathenterprise_properties.go
121 lines (99 loc) · 4.33 KB
/
enterprise_properties.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
// Copyright 2024 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"
)
// GetAllCustomProperties gets all custom properties that are defined for the specified enterprise.
//
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/custom-properties#get-custom-properties-for-an-enterprise
//
//meta:operation GET /enterprises/{enterprise}/properties/schema
func (s *EnterpriseService) GetAllCustomProperties(ctx context.Context, enterprise string) ([]*CustomProperty, *Response, error) {
u := fmt.Sprintf("enterprises/%v/properties/schema", enterprise)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
var customProperties []*CustomProperty
resp, err := s.client.Do(ctx, req, &customProperties)
if err != nil {
return nil, resp, err
}
return customProperties, resp, nil
}
// CreateOrUpdateCustomProperties creates new or updates existing custom properties that are defined for the specified enterprise.
//
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/custom-properties#create-or-update-custom-properties-for-an-enterprise
//
//meta:operation PATCH /enterprises/{enterprise}/properties/schema
func (s *EnterpriseService) CreateOrUpdateCustomProperties(ctx context.Context, enterprise string, properties []*CustomProperty) ([]*CustomProperty, *Response, error) {
u := fmt.Sprintf("enterprises/%v/properties/schema", enterprise)
params := struct {
Properties []*CustomProperty `json:"properties"`
}{
Properties: properties,
}
req, err := s.client.NewRequest("PATCH", u, params)
if err != nil {
return nil, nil, err
}
var customProperties []*CustomProperty
resp, err := s.client.Do(ctx, req, &customProperties)
if err != nil {
return nil, resp, err
}
return customProperties, resp, nil
}
// GetCustomProperty gets a custom property that is defined for the specified enterprise.
//
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/custom-properties#get-a-custom-property-for-an-enterprise
//
//meta:operation GET /enterprises/{enterprise}/properties/schema/{custom_property_name}
func (s *EnterpriseService) GetCustomProperty(ctx context.Context, enterprise, customPropertyName string) (*CustomProperty, *Response, error) {
u := fmt.Sprintf("enterprises/%v/properties/schema/%v", enterprise, customPropertyName)
req, err := s.client.NewRequest("GET", u, nil)
if err != nil {
return nil, nil, err
}
var customProperty *CustomProperty
resp, err := s.client.Do(ctx, req, &customProperty)
if err != nil {
return nil, resp, err
}
return customProperty, resp, nil
}
// CreateOrUpdateCustomProperty creates a new or updates an existing custom property that is defined for the specified enterprise.
//
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/custom-properties#create-or-update-a-custom-property-for-an-enterprise
//
//meta:operation PUT /enterprises/{enterprise}/properties/schema/{custom_property_name}
func (s *EnterpriseService) CreateOrUpdateCustomProperty(ctx context.Context, enterprise, customPropertyName string, property *CustomProperty) (*CustomProperty, *Response, error) {
u := fmt.Sprintf("enterprises/%v/properties/schema/%v", enterprise, customPropertyName)
req, err := s.client.NewRequest("PUT", u, property)
if err != nil {
return nil, nil, err
}
var customProperty *CustomProperty
resp, err := s.client.Do(ctx, req, &customProperty)
if err != nil {
return nil, resp, err
}
return customProperty, resp, nil
}
// RemoveCustomProperty removes a custom property that is defined for the specified enterprise.
//
// GitHub API docs: https://docs.github.com/enterprise-cloud@latest/rest/enterprise-admin/custom-properties#remove-a-custom-property-for-an-enterprise
//
//meta:operation DELETE /enterprises/{enterprise}/properties/schema/{custom_property_name}
func (s *EnterpriseService) RemoveCustomProperty(ctx context.Context, enterprise, customPropertyName string) (*Response, error) {
u := fmt.Sprintf("enterprises/%v/properties/schema/%v", enterprise, customPropertyName)
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
return s.client.Do(ctx, req, nil)
}