Repository: google/go-github
Pull request #1773 (2021-01-07 17:14:42)

Adding name and email fields to Repository.Contributor
According to the [documentation](https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#list-repository-contributors) for ListContributors:

> To improve performance, only the first 500 author email addresses in the repository link to GitHub users. The rest will appear as anonymous contributors without associated GitHub user information.

Anonymous user results are returned from the API like this:

```
{
    "email": "email@email.com",
    "name": "First Last",
    "type": "Anonymous",
    "contributions": 109
}
```

Both name and email are only returned for anonymous users and are not currently mapped in the [contributor](https://github.com/google/go-github/blob/master/github/repos.go#L517) struct. This PR adds those two fields to the struct and accessors.

gmlewis: Thank you, @breathingdust .  Did you run `go generate ./...` as described in CONTRIBUTING.md, or did you manually edit the auto-generated files (which appears to be the case)?

If the latter, could you please run `go generate ./...` and commit the results to the PR?
codecov[bot]: # [Codecov](https://codecov.io/gh/google/go-github/pull/1773?src=pr&el=h1) Report
> Merging [#1773](https://codecov.io/gh/google/go-github/pull/1773?src=pr&el=desc) (ba9d964) into [master](https://codecov.io/gh/google/go-github/commit/7081b5fe343920a77bb5601a68df93bcb6662663?el=desc) (7081b5f) will **not change** coverage.
> The diff coverage is `n/a`.

[![Impacted file tree graph](https://codecov.io/gh/google/go-github/pull/1773/graphs/tree.svg?width=650&height=150&src=pr&token=EgYjGjZlI0)](https://codecov.io/gh/google/go-github/pull/1773?src=pr&el=tree)

```diff
@@           Coverage Diff           @@
##           master    #1773   +/-   ##
=======================================
  Coverage   97.53%   97.53%           
=======================================
  Files          98       98           
  Lines        6373     6373           
=======================================
  Hits         6216     6216           
  Misses         85       85           
  Partials       72       72           
```


| [Impacted Files](https://codecov.io/gh/google/go-github/pull/1773?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [github/repos.go](https://codecov.io/gh/google/go-github/pull/1773/diff?src=pr&el=tree#diff-Z2l0aHViL3JlcG9zLmdv) | `98.72% <ø> (ø)` | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/google/go-github/pull/1773?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/google/go-github/pull/1773?src=pr&el=footer). Last update [7081b5f...ba9d964](https://codecov.io/gh/google/go-github/pull/1773?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

breathingdust: My bad @gmlewis, I ran `go generate` but neglected to include the generated files. Fixed.

Patch:
diff --git a/github/github-accessors.go b/github/github-accessors.go
index 6d4d1737..78082ffe 100644
--- a/github/github-accessors.go
+++ b/github/github-accessors.go
@@ -2100,6 +2100,14 @@ func (c *Contributor) GetContributions() int {
 	return *c.Contributions
 }
 
+// GetEmail returns the Email field if it's non-nil, zero value otherwise.
+func (c *Contributor) GetEmail() string {
+	if c == nil || c.Email == nil {
+		return ""
+	}
+	return *c.Email
+}
+
 // GetEventsURL returns the EventsURL field if it's non-nil, zero value otherwise.
 func (c *Contributor) GetEventsURL() string {
 	if c == nil || c.EventsURL == nil {
@@ -2164,6 +2172,14 @@ func (c *Contributor) GetLogin() string {
 	return *c.Login
 }
 
+// GetName returns the Name field if it's non-nil, zero value otherwise.
+func (c *Contributor) GetName() string {
+	if c == nil || c.Name == nil {
+		return ""
+	}
+	return *c.Name
+}
+
 // GetNodeID returns the NodeID field if it's non-nil, zero value otherwise.
 func (c *Contributor) GetNodeID() string {
 	if c == nil || c.NodeID == nil {
diff --git a/github/repos.go b/github/repos.go
index 18510d58..c8770d95 100644
--- a/github/repos.go
+++ b/github/repos.go
@@ -534,6 +534,8 @@ type Contributor struct {
 	Type              *string `json:"type,omitempty"`
 	SiteAdmin         *bool   `json:"site_admin,omitempty"`
 	Contributions     *int    `json:"contributions,omitempty"`
+	Name              *string `json:"name,omitempty"`
+	Email             *string `json:"email,omitempty"`
 }
 
 // ListContributorsOptions specifies the optional parameters to the


Test patch:
diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go
index d33dce60..e2a139be 100644
--- a/github/github-accessors_test.go
+++ b/github/github-accessors_test.go
@@ -2419,6 +2419,16 @@ func TestContributor_GetContributions(tt *testing.T) {
 	c.GetContributions()
 }
 
+func TestContributor_GetEmail(tt *testing.T) {
+	var zeroValue string
+	c := &Contributor{Email: &zeroValue}
+	c.GetEmail()
+	c = &Contributor{}
+	c.GetEmail()
+	c = nil
+	c.GetEmail()
+}
+
 func TestContributor_GetEventsURL(tt *testing.T) {
 	var zeroValue string
 	c := &Contributor{EventsURL: &zeroValue}
@@ -2499,6 +2509,16 @@ func TestContributor_GetLogin(tt *testing.T) {
 	c.GetLogin()
 }
 
+func TestContributor_GetName(tt *testing.T) {
+	var zeroValue string
+	c := &Contributor{Name: &zeroValue}
+	c.GetName()
+	c = &Contributor{}
+	c.GetName()
+	c = nil
+	c.GetName()
+}
+
 func TestContributor_GetNodeID(tt *testing.T) {
 	var zeroValue string
 	c := &Contributor{NodeID: &zeroValue}