Skip to content
New issue

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

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

Already on GitHub? # to your account

Add CreateOrUpdateRepoCustomPropertyValues #3109

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
27 changes: 27 additions & 0 deletions github/repos_properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
28 changes: 28 additions & 0 deletions github/repos_properties_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
}
Loading