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 #3105

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
16 changes: 11 additions & 5 deletions github/repos_properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions github/repos_properties_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, `[
{
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
Expand Down