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 GetAllCustomPropertyValues for repositories #3020

Merged
merged 2 commits into from
Dec 17, 2023
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
33 changes: 33 additions & 0 deletions github/repos_properties.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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
liaodaniel marked this conversation as resolved.
Show resolved Hide resolved

import (
"context"
"fmt"
)

// 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)

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