github.com/google/go-github/v68@v68.0.0/github/enterprise_properties.go (about)

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