Skip to content

Commit e85a74d

Browse files
Add CreateOrUpdateRepoCustomPropertyValues (#3109)
1 parent e75e456 commit e85a74d

File tree

2 files changed

+55
-0
lines changed

2 files changed

+55
-0
lines changed

github/repos_properties.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,30 @@ func (s *RepositoriesService) GetAllCustomPropertyValues(ctx context.Context, or
3131

3232
return customPropertyValues, resp, nil
3333
}
34+
35+
// CreateOrUpdateCustomProperties creates new or updates existing custom property values for a repository.
36+
//
37+
// GitHub API docs: https://docs.github.com/rest/repos/custom-properties#create-or-update-custom-property-values-for-a-repository
38+
//
39+
//meta:operation PATCH /repos/{owner}/{repo}/properties/values
40+
func (s *RepositoriesService) CreateOrUpdateCustomProperties(ctx context.Context, org, repo string, customPropertyValues []*CustomPropertyValue) (*Response, error) {
41+
u := fmt.Sprintf("repos/%v/%v/properties/values", org, repo)
42+
43+
params := struct {
44+
Properties []*CustomPropertyValue `json:"properties"`
45+
}{
46+
Properties: customPropertyValues,
47+
}
48+
49+
req, err := s.client.NewRequest("PATCH", u, params)
50+
if err != nil {
51+
return nil, err
52+
}
53+
54+
resp, err := s.client.Do(ctx, req, nil)
55+
if err != nil {
56+
return resp, err
57+
}
58+
59+
return resp, nil
60+
}

github/repos_properties_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,31 @@ func TestRepositoriesService_GetAllCustomPropertyValues(t *testing.T) {
6363
return resp, err
6464
})
6565
}
66+
67+
func TestRepositoriesService_CreateOrUpdateCustomProperties(t *testing.T) {
68+
client, mux, _, teardown := setup()
69+
defer teardown()
70+
71+
mux.HandleFunc("/repos/usr/r/properties/values", func(w http.ResponseWriter, r *http.Request) {
72+
testMethod(t, r, "PATCH")
73+
w.WriteHeader(http.StatusNoContent)
74+
})
75+
76+
ctx := context.Background()
77+
RepoCustomProperty := []*CustomPropertyValue{
78+
{
79+
PropertyName: "environment",
80+
Value: String("production"),
81+
},
82+
}
83+
_, err := client.Repositories.CreateOrUpdateCustomProperties(ctx, "usr", "r", RepoCustomProperty)
84+
if err != nil {
85+
t.Errorf("Repositories.CreateOrUpdateCustomProperties returned error: %v", err)
86+
}
87+
88+
const methodName = "CreateOrUpdateCustomProperties"
89+
90+
testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
91+
return client.Repositories.CreateOrUpdateCustomProperties(ctx, "usr", "r", RepoCustomProperty)
92+
})
93+
}

0 commit comments

Comments
 (0)