diff --git a/github/repos_properties.go b/github/repos_properties.go index 5b12bc8b30e..da396067519 100644 --- a/github/repos_properties.go +++ b/github/repos_properties.go @@ -10,13 +10,19 @@ import ( "fmt" ) +// RepoCustomProperty represents an organization custom property object, value can be string, array of strings or null +type RepoCustomProperty struct { + PropertyName string `json:"property_name"` + PropertyValue interface{} `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 // //meta:operation GET /repos/{owner}/{repo}/properties/values -func (s *RepositoriesService) GetAllCustomPropertyValues(ctx context.Context, org, repo string) ([]*CustomPropertyValue, *Response, error) { - u := fmt.Sprintf("repos/%v/%v/properties/values", org, repo) +func (s *RepositoriesService) GetAllCustomPropertyValues(ctx context.Context, owner, repo string) ([]*CustomPropertyValue, *Response, error) { + u := fmt.Sprintf("repos/%v/%v/properties/values", owner, repo) req, err := s.client.NewRequest("GET", u, nil) if err != nil { @@ -37,13 +43,13 @@ func (s *RepositoriesService) GetAllCustomPropertyValues(ctx context.Context, or // 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) { +func (s *RepositoriesService) CreateOrUpdateCustomProperties(ctx context.Context, org, repo string, customPropertyValues []*RepoCustomProperty) (*Response, error) { u := fmt.Sprintf("repos/%v/%v/properties/values", org, repo) params := struct { - Properties []*CustomPropertyValue `json:"properties"` + CustomPropertyValues []*RepoCustomProperty `json:"properties"` }{ - Properties: customPropertyValues, + CustomPropertyValues: customPropertyValues, } req, err := s.client.NewRequest("PATCH", u, params) diff --git a/github/repos_properties_test.go b/github/repos_properties_test.go index 5ce05c26d7b..372a4a6ba92 100644 --- a/github/repos_properties_test.go +++ b/github/repos_properties_test.go @@ -18,7 +18,7 @@ func TestRepositoriesService_GetAllCustomPropertyValues(t *testing.T) { client, mux, _, teardown := setup() defer teardown() - mux.HandleFunc("/repos/o/r/properties/values", func(w http.ResponseWriter, r *http.Request) { + mux.HandleFunc("/repos/usr/r/properties/values", func(w http.ResponseWriter, r *http.Request) { testMethod(t, r, "GET") fmt.Fprint(w, `[ { @@ -33,7 +33,7 @@ func TestRepositoriesService_GetAllCustomPropertyValues(t *testing.T) { }) ctx := context.Background() - customPropertyValues, _, err := client.Repositories.GetAllCustomPropertyValues(ctx, "o", "r") + customPropertyValues, _, err := client.Repositories.GetAllCustomPropertyValues(ctx, "usr", "r") if err != nil { t.Errorf("Repositories.GetAllCustomPropertyValues returned error: %v", err) } @@ -56,7 +56,7 @@ func TestRepositoriesService_GetAllCustomPropertyValues(t *testing.T) { const methodName = "GetAllCustomPropertyValues" testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { - got, resp, err := client.Repositories.GetAllCustomPropertyValues(ctx, "o", "r") + got, resp, err := client.Repositories.GetAllCustomPropertyValues(ctx, "usr", "r") if got != nil { t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) } @@ -74,10 +74,10 @@ func TestRepositoriesService_CreateOrUpdateCustomProperties(t *testing.T) { }) ctx := context.Background() - RepoCustomProperty := []*CustomPropertyValue{ + RepoCustomProperty := []*RepoCustomProperty{ { - PropertyName: "environment", - Value: String("production"), + PropertyName: "environment", + PropertyValue: "production", }, } _, err := client.Repositories.CreateOrUpdateCustomProperties(ctx, "usr", "r", RepoCustomProperty)