From e555328667b06a6213d00d8d668c8dd1d8c3e5cc Mon Sep 17 00:00:00 2001 From: Daniel Liao <10663736+liaodaniel@users.noreply.github.com> Date: Wed, 6 Dec 2023 10:07:32 +1100 Subject: [PATCH 1/2] Add repo GetAllCustomPropertyValues Signed-off-by: Daniel Liao <10663736+liaodaniel@users.noreply.github.com> --- github/repos_properties.go | 28 ++++++++++++++ github/repos_properties_test.go | 65 +++++++++++++++++++++++++++++++++ 2 files changed, 93 insertions(+) create mode 100644 github/repos_properties.go create mode 100644 github/repos_properties_test.go diff --git a/github/repos_properties.go b/github/repos_properties.go new file mode 100644 index 00000000000..66ec2b65ee4 --- /dev/null +++ b/github/repos_properties.go @@ -0,0 +1,28 @@ +package github + +import ( + "context" + "fmt" +) + +// GetAllCustomPropertyValues gets all custom properties 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 string, repo string) ([]*CustomPropertyValue, *Response, error) { + u := fmt.Sprintf("repos/%s/%s/properties/values", org, repo) + + req, err := s.client.NewRequest("GET", u, nil) + if err != nil { + return nil, nil, err + } + + var customPropertyValues []*CustomPropertyValue + resp, err := s.client.Do(ctx, req, &customPropertyValues) + if err != nil { + return nil, resp, err + } + + return customPropertyValues, resp, nil +} diff --git a/github/repos_properties_test.go b/github/repos_properties_test.go new file mode 100644 index 00000000000..ee231a138c6 --- /dev/null +++ b/github/repos_properties_test.go @@ -0,0 +1,65 @@ +// Copyright 2023 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github + +import ( + "context" + "fmt" + "net/http" + "testing" + + "github.com/google/go-cmp/cmp" +) + +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) { + testMethod(t, r, "GET") + fmt.Fprint(w, `[ + { + "property_name": "environment", + "value": "production" + }, + { + "property_name": "service", + "value": "web" + } + ]`) + }) + + ctx := context.Background() + customPropertyValues, _, err := client.Repositories.GetAllCustomPropertyValues(ctx, "o", "r") + if err != nil { + t.Errorf("Repositories.GetAllCustomPropertyValues returned error: %v", err) + } + + want := []*CustomPropertyValue{ + { + PropertyName: "environment", + Value: String("production"), + }, + { + PropertyName: "service", + Value: String("web"), + }, + } + + if !cmp.Equal(customPropertyValues, want) { + t.Errorf("Repositories.GetAllCustomPropertyValues returned %+v, want %+v", customPropertyValues, want) + } + + const methodName = "GetAllCustomPropertyValues" + + testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) { + got, resp, err := client.Repositories.GetAllCustomPropertyValues(ctx, "o", "r") + if got != nil { + t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got) + } + return resp, err + }) +} From 0c1372955c1b9d5acd86586116c566a51ec89ce1 Mon Sep 17 00:00:00 2001 From: Daniel Liao <10663736+liaodaniel@users.noreply.github.com> Date: Wed, 6 Dec 2023 16:19:40 +1100 Subject: [PATCH 2/2] Address PR comments Signed-off-by: Daniel Liao <10663736+liaodaniel@users.noreply.github.com> --- github/repos_properties.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/github/repos_properties.go b/github/repos_properties.go index 66ec2b65ee4..5a8626c4530 100644 --- a/github/repos_properties.go +++ b/github/repos_properties.go @@ -1,3 +1,8 @@ +// Copyright 2023 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + package github import ( @@ -5,13 +10,13 @@ import ( "fmt" ) -// GetAllCustomPropertyValues gets all custom properties values that are set for a repository. +// 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 string, repo string) ([]*CustomPropertyValue, *Response, error) { - u := fmt.Sprintf("repos/%s/%s/properties/values", org, repo) +func (s *RepositoriesService) GetAllCustomPropertyValues(ctx context.Context, org, repo string) ([]*CustomPropertyValue, *Response, error) { + u := fmt.Sprintf("repos/%v/%v/properties/values", org, repo) req, err := s.client.NewRequest("GET", u, nil) if err != nil {