forked from google/go-github
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add GetAllCustomPropertyValues for repositories (google#3020)
Fixes: google#3014.
- Loading branch information
1 parent
25e042b
commit 6e03d4e
Showing
2 changed files
with
98 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
||
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
}) | ||
} |