Repository: google/go-github
Pull request #3188 (2024-06-11 23:21:37)

Add role name to RepositoryPermissionLevel
Fixes: #3189.

I am currently using this API to fetch what role does a user have on a repository. AFAICS, RepositoryPermissionLevel struct is missing role_name which is provided by the API (https://docs.github.com/en/rest/collaborators/collaborators?apiVersion=2022-11-28#get-repository-permissions-for-a-user). Due, to this I am unable to use the library. This PR introduces the field within the RepositoryPermissionLevel struct

google-cla[bot]: Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this [failed invocation](https://github.com/google/go-github/pull/3188/checks?check_run_id=26102985623) of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.
gmlewis: It looks like this might be a duplicate of #3186.

Please run step 4 found in CONTRIBUTING.md and push the auto-generated changes to this PR. Then, once the CLA is signed, we can merge.
codecov[bot]: ## [Codecov](https://app.codecov.io/gh/google/go-github/pull/3188?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Project coverage is 92.90%. 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 [(`0c487c6`)](https://app.codecov.io/gh/google/go-github/commit/0c487c6c4be377bb2ba10d57d841366c133376c7?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google).
> Report is 70 commits behind head on master.


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


```diff
@@            Coverage Diff             @@
##           master    #3188      +/-   ##
==========================================
- Coverage   97.72%   92.90%   -4.82%     
==========================================
  Files         153      171      +18     
  Lines       13390    11548    -1842     
==========================================
- Hits        13085    10729    -2356     
- Misses        215      726     +511     
- Partials       90       93       +3     
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/google/go-github/pull/3188?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).


Patch:
diff --git a/github/github-accessors.go b/github/github-accessors.go
index 98985def..5a69f27f 100644
--- a/github/github-accessors.go
+++ b/github/github-accessors.go
@@ -20094,6 +20094,14 @@ func (r *RepositoryPermissionLevel) GetPermission() string {
 	return *r.Permission
 }
 
+// GetRoleName returns the RoleName field if it's non-nil, zero value otherwise.
+func (r *RepositoryPermissionLevel) GetRoleName() string {
+	if r == nil || r.RoleName == nil {
+		return ""
+	}
+	return *r.RoleName
+}
+
 // GetUser returns the User field.
 func (r *RepositoryPermissionLevel) GetUser() *User {
 	if r == nil {
diff --git a/github/repos_collaborators.go b/github/repos_collaborators.go
index 15a4e77a..d6c98535 100644
--- a/github/repos_collaborators.go
+++ b/github/repos_collaborators.go
@@ -99,6 +99,8 @@ type RepositoryPermissionLevel struct {
 	Permission *string `json:"permission,omitempty"`
 
 	User *User `json:"user,omitempty"`
+
+	RoleName *string `json:"role_name,omitempty"`
 }
 
 // GetPermissionLevel retrieves the specific permission level a collaborator has for a given repository.


Test patch:
diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go
index f123be8f..bfe3c61e 100644
--- a/github/github-accessors_test.go
+++ b/github/github-accessors_test.go
@@ -23327,6 +23327,16 @@ func TestRepositoryPermissionLevel_GetPermission(tt *testing.T) {
 	r.GetPermission()
 }
 
+func TestRepositoryPermissionLevel_GetRoleName(tt *testing.T) {
+	var zeroValue string
+	r := &RepositoryPermissionLevel{RoleName: &zeroValue}
+	r.GetRoleName()
+	r = &RepositoryPermissionLevel{}
+	r.GetRoleName()
+	r = nil
+	r.GetRoleName()
+}
+
 func TestRepositoryPermissionLevel_GetUser(tt *testing.T) {
 	r := &RepositoryPermissionLevel{}
 	r.GetUser()