Skip to content

Commit 005e6c8

Browse files
authored
Add GetAllCustomPropertyValues for repositories (#3020)
Fixes: #3014.
1 parent 6d3dfc6 commit 005e6c8

File tree

2 files changed

+98
-0
lines changed

2 files changed

+98
-0
lines changed

github/repos_properties.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright 2023 The go-github AUTHORS. All rights reserved.
2+
//
3+
// Use of this source code is governed by a BSD-style
4+
// license that can be found in the LICENSE file.
5+
6+
package github
7+
8+
import (
9+
"context"
10+
"fmt"
11+
)
12+
13+
// GetAllCustomPropertyValues gets all custom property values that are set for a repository.
14+
//
15+
// GitHub API docs: https://docs.github.com/rest/repos/custom-properties#get-all-custom-property-values-for-a-repository
16+
//
17+
//meta:operation GET /repos/{owner}/{repo}/properties/values
18+
func (s *RepositoriesService) GetAllCustomPropertyValues(ctx context.Context, org, repo string) ([]*CustomPropertyValue, *Response, error) {
19+
u := fmt.Sprintf("repos/%v/%v/properties/values", org, repo)
20+
21+
req, err := s.client.NewRequest("GET", u, nil)
22+
if err != nil {
23+
return nil, nil, err
24+
}
25+
26+
var customPropertyValues []*CustomPropertyValue
27+
resp, err := s.client.Do(ctx, req, &customPropertyValues)
28+
if err != nil {
29+
return nil, resp, err
30+
}
31+
32+
return customPropertyValues, resp, nil
33+
}

github/repos_properties_test.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright 2023 The go-github AUTHORS. All rights reserved.
2+
//
3+
// Use of this source code is governed by a BSD-style
4+
// license that can be found in the LICENSE file.
5+
6+
package github
7+
8+
import (
9+
"context"
10+
"fmt"
11+
"net/http"
12+
"testing"
13+
14+
"github.com/google/go-cmp/cmp"
15+
)
16+
17+
func TestRepositoriesService_GetAllCustomPropertyValues(t *testing.T) {
18+
client, mux, _, teardown := setup()
19+
defer teardown()
20+
21+
mux.HandleFunc("/repos/o/r/properties/values", func(w http.ResponseWriter, r *http.Request) {
22+
testMethod(t, r, "GET")
23+
fmt.Fprint(w, `[
24+
{
25+
"property_name": "environment",
26+
"value": "production"
27+
},
28+
{
29+
"property_name": "service",
30+
"value": "web"
31+
}
32+
]`)
33+
})
34+
35+
ctx := context.Background()
36+
customPropertyValues, _, err := client.Repositories.GetAllCustomPropertyValues(ctx, "o", "r")
37+
if err != nil {
38+
t.Errorf("Repositories.GetAllCustomPropertyValues returned error: %v", err)
39+
}
40+
41+
want := []*CustomPropertyValue{
42+
{
43+
PropertyName: "environment",
44+
Value: String("production"),
45+
},
46+
{
47+
PropertyName: "service",
48+
Value: String("web"),
49+
},
50+
}
51+
52+
if !cmp.Equal(customPropertyValues, want) {
53+
t.Errorf("Repositories.GetAllCustomPropertyValues returned %+v, want %+v", customPropertyValues, want)
54+
}
55+
56+
const methodName = "GetAllCustomPropertyValues"
57+
58+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
59+
got, resp, err := client.Repositories.GetAllCustomPropertyValues(ctx, "o", "r")
60+
if got != nil {
61+
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
62+
}
63+
return resp, err
64+
})
65+
}

0 commit comments

Comments
 (0)