github.com/google/go-github/v74@v74.0.0/github/repos_properties.go (about)

     1  // Copyright 2023 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  // GetAllCustomPropertyValues gets all custom property values that are set for a repository.
    14  //
    15  // GitHub API docs: https://docs.github.com/rest/repos/custom-properties#get-all-custom-property-values-for-a-repository
    16  //
    17  //meta:operation GET /repos/{owner}/{repo}/properties/values
    18  func (s *RepositoriesService) GetAllCustomPropertyValues(ctx context.Context, org, repo string) ([]*CustomPropertyValue, *Response, error) {
    19  	u := fmt.Sprintf("repos/%v/%v/properties/values", org, repo)
    20  
    21  	req, err := s.client.NewRequest("GET", u, nil)
    22  	if err != nil {
    23  		return nil, nil, err
    24  	}
    25  
    26  	var customPropertyValues []*CustomPropertyValue
    27  	resp, err := s.client.Do(ctx, req, &customPropertyValues)
    28  	if err != nil {
    29  		return nil, resp, err
    30  	}
    31  
    32  	return customPropertyValues, resp, nil
    33  }
    34  
    35  // CreateOrUpdateCustomProperties creates new or updates existing custom property values for a repository.
    36  //
    37  // GitHub API docs: https://docs.github.com/rest/repos/custom-properties#create-or-update-custom-property-values-for-a-repository
    38  //
    39  //meta:operation PATCH /repos/{owner}/{repo}/properties/values
    40  func (s *RepositoriesService) CreateOrUpdateCustomProperties(ctx context.Context, org, repo string, customPropertyValues []*CustomPropertyValue) (*Response, error) {
    41  	u := fmt.Sprintf("repos/%v/%v/properties/values", org, repo)
    42  
    43  	params := struct {
    44  		Properties []*CustomPropertyValue `json:"properties"`
    45  	}{
    46  		Properties: customPropertyValues,
    47  	}
    48  
    49  	req, err := s.client.NewRequest("PATCH", u, params)
    50  	if err != nil {
    51  		return nil, err
    52  	}
    53  
    54  	resp, err := s.client.Do(ctx, req, nil)
    55  	if err != nil {
    56  		return resp, err
    57  	}
    58  
    59  	return resp, nil
    60  }