8000 feat: Add enterprise custom properties by stevehipwell · Pull Request #3382 · google/go-github · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: Add enterprise custom properties #3382

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -481,6 +481,7 @@ SoundCloud, Ltd.
Sridhar Mocherla <srmocher@microsoft.com>
SriVignessh Pss <sriknowledge@gmail.com>
Stefan Sedich <stefan.sedich@gmail.com>
Steve Hipwell <steve.hipwell@gmail.com>
Steve Teuber <github@steveteuber.com>
Stian Eikeland <stian@eikeland.se>
Suhaib Mujahid <suhaibmujahid@gmail.com>
Expand Down
121 changes: 121 additions & 0 deletions github/enterprise_properties.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,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)
}
Loading
Loading
0