Skip to content

Commit

Permalink
adding method to create or update github custom property value for re…
Browse files Browse the repository at this point in the history
…positories
  • Loading branch information
ganeshkumarsv committed Mar 20, 2024
1 parent dbf91ee commit 3fe0a72
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
22 changes: 22 additions & 0 deletions github/repos_properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,25 @@ func (s *RepositoriesService) GetAllCustomPropertyValues(ctx context.Context, or

return customPropertyValues, resp, nil
}

// CreateOrUpdateRepoCustomPropertyValues creates or updates custom property values for a repository.
//
// GitHub API docs: https://docs.github.com/en/rest/repos/custom-properties?apiVersion=2022-11-28#create-or-update-custom-property-values-for-a-repository
//
//meta:operation PATCH /repos/{owner}/{repo}/properties/values
func (s *RepositoriesService) CreateOrUpdateRepoCustomPropertyValues(ctx context.Context, org, repo string, properties []*CustomPropertyValue) (*Response, error) {
u := fmt.Sprintf("repos/%v/%v/properties/values", org, repo)

params := struct {
Properties []*CustomPropertyValue `json:"properties"`
}{
Properties: properties,
}

req, err := s.client.NewRequest("PATCH", u, params)
if err != nil {
return nil, err
}

return s.client.Do(ctx, req, nil)
}
27 changes: 27 additions & 0 deletions github/repos_properties_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,30 @@ func TestRepositoriesService_GetAllCustomPropertyValues(t *testing.T) {
return resp, err
})
}

func TestCreateOrUpdateRepoCustomPropertyValues(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, "PATCH")
testBody(t, r, `'{"properties":[{"property_name":"environment","value":"production"},{"property_name":"service","value":"web"},{"property_name":"team","value":"octocat"}]}'`+"\n")
})

ctx := context.Background()
_, err := client.Repositories.CreateOrUpdateRepoCustomPropertyValues(ctx, "o", "repo", []*CustomPropertyValue{
{
PropertyName: "service",
Value: String("string"),
},
})
if err != nil {
t.Errorf("Repositories.CreateOrUpdateRepoCustomPropertyValues returned error: %v", err)
}

const methodName = "CreateOrUpdateRepoCustomPropertyValues"

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
return client.Repositories.CreateOrUpdateRepoCustomPropertyValues(ctx, "o", "", nil)
})
}

0 comments on commit 3fe0a72

Please sign in to comment.