Repository: google/go-github
Pull request #3109 (2024-03-23 22:18:11)

Add CreateOrUpdateRepoCustomPropertyValues
Adds method CreateOrUpdateRepoCustomPropertyValues

codecov[bot]: ## [Codecov](https://app.codecov.io/gh/google/go-github/pull/3109?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) Report
Attention: Patch coverage is `80.00000%` with `2 lines` in your changes are missing coverage. Please review.
> Project coverage is 92.86%. Comparing base [(`2b8c7fa`)](https://app.codecov.io/gh/google/go-github/commit/2b8c7fa86fcd1cb4a89a44c8e7b5a49fe4be8a45?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) to head [(`7ce3cbc`)](https://app.codecov.io/gh/google/go-github/pull/3109?dropdown=coverage&src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google).
> Report is 24 commits behind head on master.

| [Files](https://app.codecov.io/gh/google/go-github/pull/3109?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) | Patch % | Lines |
|---|---|---|
| [github/repos\_properties.go](https://app.codecov.io/gh/google/go-github/pull/3109?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google#diff-Z2l0aHViL3JlcG9zX3Byb3BlcnRpZXMuZ28=) | 80.00% | [1 Missing and 1 partial :warning: ](https://app.codecov.io/gh/google/go-github/pull/3109?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) |

<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master    #3109      +/-   ##
==========================================
- Coverage   97.72%   92.86%   -4.87%     
==========================================
  Files         153      170      +17     
  Lines       13390    11417    -1973     
==========================================
- Hits        13085    10602    -2483     
- Misses        215      724     +509     
- Partials       90       91       +1     
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/google/go-github/pull/3109?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google).

gmlewis: Thank you, @ganeshkumarsv !
I saw the commit titled "no idea what im doing" and thought I might help out...  In CONTRIBUTING.md, we have some helpful tips that should assist you.  Please let me know if you have any question, but it looks like you are on the right track.  You can also look at some of the other files for examples on code coverage. 
ganeshkumarsv: > Thank you, @ganeshkumarsv ! I saw the commit titled "no idea what im doing" and thought I might help out... In CONTRIBUTING.md, we have some helpful tips that should assist you. Please let me know if you have any question, but it looks like you are on the right track. You can also look at some of the other files for examples on code coverage.

Thanks for commenting @gmlewis. Running metadata.sh makes modification for a lot of URLs and erroring out. I don't see a way to update openapi configs only the one endpoint i'm updating. Any help appreciated. Thank you 🙇 
gmlewis: > Thanks for commenting @gmlewis. Running metadata.sh makes modification for a lot of URLs and erroring out. I don't see a way to update openapi configs only the one endpoint i'm updating. Any help appreciated. Thank you 🙇

You shouldn't have to deal with the metadata or OpenAPI stuff... you should only have to make sure your formatting has been fixed and the generator has been run, and you can revert any changes made to the metadata.
ganeshkumarsv: I tried running `go run github/gen-accessors.go` but it is not generating anything. Am i missing something?
ganeshkumarsv: I removed my changes from `openapi_operations.yaml` as u mentioned. The linter fails with the error `could not find operation "PATCH /repos/{owner}/{repo}/properties/values" in openapi_operations.yaml` 

Can I know how i can fix this error?
gmlewis: @ganeshkumarsv - now that #3104 is merged, please try to update this branch using `git merge master` and see if that solves the problems you were seeing before.
ganeshkumarsv: Thanks @gmlewis. I updated the branch and it fixed the linter. All the checks are passing now.
ganeshkumarsv: @liaodaniel I need one more approval to merge this PR. Can you please review? 🙇 

Patch:
diff --git a/github/repos_properties.go b/github/repos_properties.go
index 5a8626c4..5b12bc8b 100644
--- a/github/repos_properties.go
+++ b/github/repos_properties.go
@@ -31,3 +31,30 @@ func (s *RepositoriesService) GetAllCustomPropertyValues(ctx context.Context, or
 
 	return customPropertyValues, resp, nil
 }
+
+// CreateOrUpdateCustomProperties creates new or updates existing custom property values for a repository.
+//
+// GitHub API docs: https://docs.github.com/rest/repos/custom-properties#create-or-update-custom-property-values-for-a-repository
+//
+//meta:operation PATCH /repos/{owner}/{repo}/properties/values
+func (s *RepositoriesService) CreateOrUpdateCustomProperties(ctx context.Context, org, repo string, customPropertyValues []*CustomPropertyValue) (*Response, error) {
+	u := fmt.Sprintf("repos/%v/%v/properties/values", org, repo)
+
+	params := struct {
+		Properties []*CustomPropertyValue `json:"properties"`
+	}{
+		Properties: customPropertyValues,
+	}
+
+	req, err := s.client.NewRequest("PATCH", u, params)
+	if err != nil {
+		return nil, err
+	}
+
+	resp, err := s.client.Do(ctx, req, nil)
+	if err != nil {
+		return resp, err
+	}
+
+	return resp, nil
+}


Test patch:
diff --git a/github/repos_properties_test.go b/github/repos_properties_test.go
index ee231a13..5ce05c26 100644
--- a/github/repos_properties_test.go
+++ b/github/repos_properties_test.go
@@ -63,3 +63,31 @@ func TestRepositoriesService_GetAllCustomPropertyValues(t *testing.T) {
 		return resp, err
 	})
 }
+
+func TestRepositoriesService_CreateOrUpdateCustomProperties(t *testing.T) {
+	client, mux, _, teardown := setup()
+	defer teardown()
+
+	mux.HandleFunc("/repos/usr/r/properties/values", func(w http.ResponseWriter, r *http.Request) {
+		testMethod(t, r, "PATCH")
+		w.WriteHeader(http.StatusNoContent)
+	})
+
+	ctx := context.Background()
+	RepoCustomProperty := []*CustomPropertyValue{
+		{
+			PropertyName: "environment",
+			Value:        String("production"),
+		},
+	}
+	_, err := client.Repositories.CreateOrUpdateCustomProperties(ctx, "usr", "r", RepoCustomProperty)
+	if err != nil {
+		t.Errorf("Repositories.CreateOrUpdateCustomProperties returned error: %v", err)
+	}
+
+	const methodName = "CreateOrUpdateCustomProperties"
+
+	testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
+		return client.Repositories.CreateOrUpdateCustomProperties(ctx, "usr", "r", RepoCustomProperty)
+	})
+}