diff --git a/github/repos_properties.go b/github/repos_properties.go index 5a8626c453..5b12bc8b30 100644 --- a/github/repos_properties.go +++ b/github/repos_properties.go @@ -31,3 +31,30 @@ func (s *RepositoriesService) GetAllCustomPropertyValues(ctx context.Context, or return customPropertyValues, resp, nil } + +// CreateOrUpdateCustomProperties creates new or updates existing custom property values for a repository. +// +// GitHub API docs: https://docs.github.com/rest/repos/custom-properties#create-or-update-custom-property-values-for-a-repository +// +//meta:operation PATCH /repos/{owner}/{repo}/properties/values +func (s *RepositoriesService) CreateOrUpdateCustomProperties(ctx context.Context, org, repo string, customPropertyValues []*CustomPropertyValue) (*Response, error) { + u := fmt.Sprintf("repos/%v/%v/properties/values", org, repo) + + params := struct { + Properties []*CustomPropertyValue `json:"properties"` + }{ + Properties: customPropertyValues, + } + + req, err := s.client.NewRequest("PATCH", u, params) + if err != nil { + return nil, err + } + + resp, err := s.client.Do(ctx, req, nil) + if err != nil { + return resp, err + } + + return resp, nil +} diff --git a/github/repos_properties_test.go b/github/repos_properties_test.go index ee231a138c..5ce05c26d7 100644 --- a/github/repos_properties_test.go +++ b/github/repos_properties_test.go @@ -63,3 +63,31 @@ func TestRepositoriesService_GetAllCustomPropertyValues(t *testing.T) { return resp, err }) } + +func TestRepositoriesService_CreateOrUpdateCustomProperties(t *testing.T) { + client, mux, _, teardown := setup() + defer teardown() + + mux.HandleFunc("/repos/usr/r/properties/values", func(w http.ResponseWriter, r *http.Request) { + testMethod(t, r, "PATCH") + w.WriteHeader(http.StatusNoContent) + }) + + ctx := context.Background() + RepoCustomProperty := []*CustomPropertyValue{ + { + PropertyName: "environment", + Value: String("production"), + }, + } + _, err := client.Repositories.CreateOrUpdateCustomProperties(ctx, "usr", "r", RepoCustomProperty) + if err != nil { + t.Errorf("Repositories.CreateOrUpdateCustomProperties returned error: %v", err) + } + + const methodName = "CreateOrUpdateCustomProperties" + + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + return client.Repositories.CreateOrUpdateCustomProperties(ctx, "usr", "r", RepoCustomProperty) + }) +}