Skip to content
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

Add CreateOrUpdateCustomPropertyValues for repositories #3102

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
33 changes: 33 additions & 0 deletions github/repos_properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ import (
"fmt"
)

// CustomPropertyNonNullValue represents a custom property, with a non-null value.
type CustomPropertyNonNullValue struct {
PropertyName string `json:"property_name"`
Value string `json:"value"`
}

// GetAllCustomPropertyValues gets all custom property values that are set for a repository.
//
// GitHub API docs: https://docs.github.com/rest/repos/custom-properties#get-all-custom-property-values-for-a-repository
Expand All @@ -31,3 +37,30 @@ func (s *RepositoriesService) GetAllCustomPropertyValues(ctx context.Context, or

return customPropertyValues, resp, nil
}

// CreateOrUpdateCustomPropertyValues creates new or updates existing custom property values for a repository.
//
// GitHub API docs: https://docs.github.com/en/rest/repos/custom-properties#create-or-update-custom-property-values-for-a-repository
//
//meta:operation PATCH /repos/{owner}/{repo}/properties/values
func (s *RepositoriesService) CreateOrUpdateCustomPropertyValues(ctx context.Context, org, repo string, customPropertyValues []*CustomPropertyNonNullValue) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/properties/values", org, repo)

params := struct {
CustomPropertyValues []*CustomPropertyNonNullValue `json:"properties"`
}{
CustomPropertyValues: 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
}
29 changes: 29 additions & 0 deletions github/repos_properties_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,32 @@ func TestRepositoriesService_GetAllCustomPropertyValues(t *testing.T) {
return resp, err
})
}

func TestRepositoriesService_CreateOrUpdateCustomPropertyValues(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()

// No Content when custom property values are successfully created or updated, StatusCode: 204 (No Content)
mux.HandleFunc("/repos/o/r/properties/values", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PATCH")
w.WriteHeader(http.StatusNoContent)
})

ctx := context.Background()
customPropertyValues := []*CustomPropertyNonNullValue{
{
PropertyName: "environment",
Value: "production",
},
}
_, err := client.Repositories.CreateOrUpdateCustomPropertyValues(ctx, "o", "r", customPropertyValues)
if err != nil {
t.Errorf("Repositories.CreateOrUpdateCustomPropertyValues returned error: %v", err)
}

const methodName = "CreateOrUpdateCustomPropertyValues"

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
return client.Repositories.CreateOrUpdateCustomPropertyValues(ctx, "o", "r", customPropertyValues)
})
}
5 changes: 5 additions & 0 deletions openapi_operations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4606,6 +4606,11 @@ openapi_operations:
openapi_files:
- descriptions/api.github.com/api.github.com.json
- descriptions/ghec/ghec.json
- name: PATCH /repos/{owner}/{repo}/properties/values
documentation_url: https://docs.github.com/en/rest/repos/custom-properties#create-or-update-custom-property-values-for-a-repository
openapi_files:
- descriptions/api.github.com/api.github.com.json
- descriptions/ghec/ghec.json
- name: GET /repos/{owner}/{repo}/pulls
documentation_url: https://docs.github.com/rest/pulls/pulls#list-pull-requests
openapi_files:
Expand Down