Repository: google/go-github
Pull request #2386 (2022-06-16 14:54:19)

add rolename field to user struct
As a follow on from [this PR](https://github.com/google/go-github/pull/2379) - I also need to be able to access the `role_name` returned from the `Repositories.ListCollaborators` endpoint, and therefore have raised this PR to include the field in the user 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/2386/checks?check_run_id=6920804154) 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.
codecov[bot]: # [Codecov](https://codecov.io/gh/google/go-github/pull/2386?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) Report
> Merging [#2386](https://codecov.io/gh/google/go-github/pull/2386?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (7d99f0c) into [master](https://codecov.io/gh/google/go-github/commit/74c45994d78744a7e202b477c2b26bf5ca47bd52?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (74c4599) will **not change** coverage.
> The diff coverage is `n/a`.

```diff
@@           Coverage Diff           @@
##           master    #2386   +/-   ##
=======================================
  Coverage   98.06%   98.06%           
=======================================
  Files         119      119           
  Lines       10545    10545           
=======================================
  Hits        10341    10341           
  Misses        140      140           
  Partials       64       64           
```


| [Impacted Files](https://codecov.io/gh/google/go-github/pull/2386?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) | Coverage Δ | |
|---|---|---|
| [github/users.go](https://codecov.io/gh/google/go-github/pull/2386/diff?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google#diff-Z2l0aHViL3VzZXJzLmdv) | `94.17% <ø> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/google/go-github/pull/2386?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/google/go-github/pull/2386?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google). Last update [74c4599...7d99f0c](https://codecov.io/gh/google/go-github/pull/2386?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?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 01fc3ceb..6131fad9 100644
--- a/github/github-accessors.go
+++ b/github/github-accessors.go
@@ -18774,6 +18774,14 @@ func (u *User) GetReposURL() string {
 	return *u.ReposURL
 }
 
+// GetRoleName returns the RoleName field if it's non-nil, zero value otherwise.
+func (u *User) GetRoleName() string {
+	if u == nil || u.RoleName == nil {
+		return ""
+	}
+	return *u.RoleName
+}
+
 // GetSiteAdmin returns the SiteAdmin field if it's non-nil, zero value otherwise.
 func (u *User) GetSiteAdmin() bool {
 	if u == nil || u.SiteAdmin == nil {
diff --git a/github/users.go b/github/users.go
index e694e054..d40d23e9 100644
--- a/github/users.go
+++ b/github/users.go
@@ -66,9 +66,10 @@ type User struct {
 	// See: search.go and https://docs.github.com/en/rest/search/#text-match-metadata
 	TextMatches []*TextMatch `json:"text_matches,omitempty"`
 
-	// Permissions identifies the permissions that a user has on a given
-	// repository. This is only populated when calling Repositories.ListCollaborators.
+	// Permissions and RoleName identify the permissions and role that a user has on a given
+	// repository. These are only populated when calling Repositories.ListCollaborators.
 	Permissions map[string]bool `json:"permissions,omitempty"`
+	RoleName    *string         `json:"role_name,omitempty"`
 }
 
 func (u User) String() string {


Test patch:
diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go
index dc827e65..27ad0c81 100644
--- a/github/github-accessors_test.go
+++ b/github/github-accessors_test.go
@@ -21914,6 +21914,16 @@ func TestUser_GetReposURL(tt *testing.T) {
 	u.GetReposURL()
 }
 
+func TestUser_GetRoleName(tt *testing.T) {
+	var zeroValue string
+	u := &User{RoleName: &zeroValue}
+	u.GetRoleName()
+	u = &User{}
+	u.GetRoleName()
+	u = nil
+	u.GetRoleName()
+}
+
 func TestUser_GetSiteAdmin(tt *testing.T) {
 	var zeroValue bool
 	u := &User{SiteAdmin: &zeroValue}
diff --git a/github/github-stringify_test.go b/github/github-stringify_test.go
index 9c9e3a0a..fa7599d3 100644
--- a/github/github-stringify_test.go
+++ b/github/github-stringify_test.go
@@ -1904,8 +1904,9 @@ func TestUser_String(t *testing.T) {
 		ReposURL:                String(""),
 		StarredURL:              String(""),
 		SubscriptionsURL:        String(""),
+		RoleName:                String(""),
 	}
-	want := `github.User{Login:"", ID:0, NodeID:"", AvatarURL:"", HTMLURL:"", GravatarID:"", Name:"", Company:"", Blog:"", Location:"", Email:"", Hireable:false, Bio:"", TwitterUsername:"", PublicRepos:0, PublicGists:0, Followers:0, Following:0, CreatedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, UpdatedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, SuspendedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, Type:"", SiteAdmin:false, TotalPrivateRepos:0, OwnedPrivateRepos:0, PrivateGists:0, DiskUsage:0, Collaborators:0, TwoFactorAuthentication:false, Plan:github.Plan{}, LdapDn:"", URL:"", EventsURL:"", FollowingURL:"", FollowersURL:"", GistsURL:"", OrganizationsURL:"", ReceivedEventsURL:"", ReposURL:"", StarredURL:"", SubscriptionsURL:""}`
+	want := `github.User{Login:"", ID:0, NodeID:"", AvatarURL:"", HTMLURL:"", GravatarID:"", Name:"", Company:"", Blog:"", Location:"", Email:"", Hireable:false, Bio:"", TwitterUsername:"", PublicRepos:0, PublicGists:0, Followers:0, Following:0, CreatedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, UpdatedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, SuspendedAt:github.Timestamp{0001-01-01 00:00:00 +0000 UTC}, Type:"", SiteAdmin:false, TotalPrivateRepos:0, OwnedPrivateRepos:0, PrivateGists:0, DiskUsage:0, Collaborators:0, TwoFactorAuthentication:false, Plan:github.Plan{}, LdapDn:"", URL:"", EventsURL:"", FollowingURL:"", FollowersURL:"", GistsURL:"", OrganizationsURL:"", ReceivedEventsURL:"", ReposURL:"", StarredURL:"", SubscriptionsURL:"", RoleName:""}`
 	if got := v.String(); got != want {
 		t.Errorf("User.String = %v, want %v", got, want)
 	}