Repository: google/go-github
Pull request #1462 (2020-03-17 16:03:37)

Added AuthorAssociation field in issue struct
This PR fixes
#1458 

codecov[bot]: # [Codecov](https://codecov.io/gh/google/go-github/pull/1462?src=pr&el=h1) Report
> Merging [#1462](https://codecov.io/gh/google/go-github/pull/1462?src=pr&el=desc) into [master](https://codecov.io/gh/google/go-github/commit/419f07c399bbced679719c419ae683618018556c?src=pr&el=desc) will **increase** coverage by `5.12%`.
> The diff coverage is `n/a`.

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

```diff
@@            Coverage Diff             @@
##           master    #1462      +/-   ##
==========================================
+ Coverage   68.01%   73.14%   +5.12%     
==========================================
  Files          94       94              
  Lines        8389     6758    -1631     
==========================================
- Hits         5706     4943     -763     
+ Misses       1821      953     -868     
  Partials      862      862
```


| [Impacted Files](https://codecov.io/gh/google/go-github/pull/1462?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [github/issues.go](https://codecov.io/gh/google/go-github/pull/1462/diff?src=pr&el=tree#diff-Z2l0aHViL2lzc3Vlcy5nbw==) | `79.77% <ø> (+4.77%)` | :arrow_up: |
| [github/github.go](https://codecov.io/gh/google/go-github/pull/1462/diff?src=pr&el=tree#diff-Z2l0aHViL2dpdGh1Yi5nbw==) | `89.74% <0%> (-0.03%)` | :arrow_down: |
| [github/repos\_traffic.go](https://codecov.io/gh/google/go-github/pull/1462/diff?src=pr&el=tree#diff-Z2l0aHViL3JlcG9zX3RyYWZmaWMuZ28=) | `100% <0%> (ø)` | :arrow_up: |
| [github/admin\_stats.go](https://codecov.io/gh/google/go-github/pull/1462/diff?src=pr&el=tree#diff-Z2l0aHViL2FkbWluX3N0YXRzLmdv) | `100% <0%> (ø)` | :arrow_up: |
| [github/admin.go](https://codecov.io/gh/google/go-github/pull/1462/diff?src=pr&el=tree#diff-Z2l0aHViL2FkbWluLmdv) | `100% <0%> (ø)` | :arrow_up: |
| [github/pulls\_reviewers.go](https://codecov.io/gh/google/go-github/pull/1462/diff?src=pr&el=tree#diff-Z2l0aHViL3B1bGxzX3Jldmlld2Vycy5nbw==) | `100% <0%> (ø)` | :arrow_up: |
| [github/activity.go](https://codecov.io/gh/google/go-github/pull/1462/diff?src=pr&el=tree#diff-Z2l0aHViL2FjdGl2aXR5Lmdv) | `100% <0%> (ø)` | :arrow_up: |
| [github/timestamp.go](https://codecov.io/gh/google/go-github/pull/1462/diff?src=pr&el=tree#diff-Z2l0aHViL3RpbWVzdGFtcC5nbw==) | `100% <0%> (ø)` | :arrow_up: |
| [github/strings.go](https://codecov.io/gh/google/go-github/pull/1462/diff?src=pr&el=tree#diff-Z2l0aHViL3N0cmluZ3MuZ28=) | `100% <0%> (ø)` | :arrow_up: |
| [github/git\_commits.go](https://codecov.io/gh/google/go-github/pull/1462/diff?src=pr&el=tree#diff-Z2l0aHViL2dpdF9jb21taXRzLmdv) | `91.3% <0%> (+1.3%)` | :arrow_up: |
| ... and [82 more](https://codecov.io/gh/google/go-github/pull/1462/diff?src=pr&el=tree-more) | |

------

[Continue to review full report at Codecov](https://codecov.io/gh/google/go-github/pull/1462?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/1462?src=pr&el=footer). Last update [419f07c...f8d1846](https://codecov.io/gh/google/go-github/pull/1462?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).

gmlewis: Can you please re-run `go generate ./...` to fix the tests that are failing?

Patch:
diff --git a/github/github-accessors.go b/github/github-accessors.go
index 69547c4f..519123cd 100644
--- a/github/github-accessors.go
+++ b/github/github-accessors.go
@@ -4484,6 +4484,14 @@ func (i *Issue) GetAssignee() *User {
 	return i.Assignee
 }
 
+// GetAuthorAssociation returns the AuthorAssociation field if it's non-nil, zero value otherwise.
+func (i *Issue) GetAuthorAssociation() string {
+	if i == nil || i.AuthorAssociation == nil {
+		return ""
+	}
+	return *i.AuthorAssociation
+}
+
 // GetBody returns the Body field if it's non-nil, zero value otherwise.
 func (i *Issue) GetBody() string {
 	if i == nil || i.Body == nil {
diff --git a/github/issues.go b/github/issues.go
index 71994070..b53a2603 100644
--- a/github/issues.go
+++ b/github/issues.go
@@ -26,32 +26,33 @@ type IssuesService service
 // this is an issue, and if PullRequestLinks is not nil, this is a pull request.
 // The IsPullRequest helper method can be used to check that.
 type Issue struct {
-	ID               *int64            `json:"id,omitempty"`
-	Number           *int              `json:"number,omitempty"`
-	State            *string           `json:"state,omitempty"`
-	Locked           *bool             `json:"locked,omitempty"`
-	Title            *string           `json:"title,omitempty"`
-	Body             *string           `json:"body,omitempty"`
-	User             *User             `json:"user,omitempty"`
-	Labels           []*Label          `json:"labels,omitempty"`
-	Assignee         *User             `json:"assignee,omitempty"`
-	Comments         *int              `json:"comments,omitempty"`
-	ClosedAt         *time.Time        `json:"closed_at,omitempty"`
-	CreatedAt        *time.Time        `json:"created_at,omitempty"`
-	UpdatedAt        *time.Time        `json:"updated_at,omitempty"`
-	ClosedBy         *User             `json:"closed_by,omitempty"`
-	URL              *string           `json:"url,omitempty"`
-	HTMLURL          *string           `json:"html_url,omitempty"`
-	CommentsURL      *string           `json:"comments_url,omitempty"`
-	EventsURL        *string           `json:"events_url,omitempty"`
-	LabelsURL        *string           `json:"labels_url,omitempty"`
-	RepositoryURL    *string           `json:"repository_url,omitempty"`
-	Milestone        *Milestone        `json:"milestone,omitempty"`
-	PullRequestLinks *PullRequestLinks `json:"pull_request,omitempty"`
-	Repository       *Repository       `json:"repository,omitempty"`
-	Reactions        *Reactions        `json:"reactions,omitempty"`
-	Assignees        []*User           `json:"assignees,omitempty"`
-	NodeID           *string           `json:"node_id,omitempty"`
+	ID                *int64            `json:"id,omitempty"`
+	Number            *int              `json:"number,omitempty"`
+	State             *string           `json:"state,omitempty"`
+	Locked            *bool             `json:"locked,omitempty"`
+	Title             *string           `json:"title,omitempty"`
+	Body              *string           `json:"body,omitempty"`
+	AuthorAssociation *string           `json:"author_association,omitempty"`
+	User              *User             `json:"user,omitempty"`
+	Labels            []*Label          `json:"labels,omitempty"`
+	Assignee          *User             `json:"assignee,omitempty"`
+	Comments          *int              `json:"comments,omitempty"`
+	ClosedAt          *time.Time        `json:"closed_at,omitempty"`
+	CreatedAt         *time.Time        `json:"created_at,omitempty"`
+	UpdatedAt         *time.Time        `json:"updated_at,omitempty"`
+	ClosedBy          *User             `json:"closed_by,omitempty"`
+	URL               *string           `json:"url,omitempty"`
+	HTMLURL           *string           `json:"html_url,omitempty"`
+	CommentsURL       *string           `json:"comments_url,omitempty"`
+	EventsURL         *string           `json:"events_url,omitempty"`
+	LabelsURL         *string           `json:"labels_url,omitempty"`
+	RepositoryURL     *string           `json:"repository_url,omitempty"`
+	Milestone         *Milestone        `json:"milestone,omitempty"`
+	PullRequestLinks  *PullRequestLinks `json:"pull_request,omitempty"`
+	Repository        *Repository       `json:"repository,omitempty"`
+	Reactions         *Reactions        `json:"reactions,omitempty"`
+	Assignees         []*User           `json:"assignees,omitempty"`
+	NodeID            *string           `json:"node_id,omitempty"`
 
 	// TextMatches is only populated from search results that request text matches
 	// See: search.go and https://developer.github.com/v3/search/#text-match-metadata


Test patch:
diff --git a/github/github-stringify_test.go b/github/github-stringify_test.go
index 375f3b6a..b85d3a62 100644
--- a/github/github-stringify_test.go
+++ b/github/github-stringify_test.go
@@ -599,30 +599,31 @@ func TestInvitation_String(t *testing.T) {
 
 func TestIssue_String(t *testing.T) {
 	v := Issue{
-		ID:               Int64(0),
-		Number:           Int(0),
-		State:            String(""),
-		Locked:           Bool(false),
-		Title:            String(""),
-		Body:             String(""),
-		User:             &User{},
-		Assignee:         &User{},
-		Comments:         Int(0),
-		ClosedBy:         &User{},
-		URL:              String(""),
-		HTMLURL:          String(""),
-		CommentsURL:      String(""),
-		EventsURL:        String(""),
-		LabelsURL:        String(""),
-		RepositoryURL:    String(""),
-		Milestone:        &Milestone{},
-		PullRequestLinks: &PullRequestLinks{},
-		Repository:       &Repository{},
-		Reactions:        &Reactions{},
-		NodeID:           String(""),
-		ActiveLockReason: String(""),
-	}
-	want := `github.Issue{ID:0, Number:0, State:"", Locked:false, Title:"", Body:"", User:github.User{}, Assignee:github.User{}, Comments:0, ClosedBy:github.User{}, URL:"", HTMLURL:"", CommentsURL:"", EventsURL:"", LabelsURL:"", RepositoryURL:"", Milestone:github.Milestone{}, PullRequestLinks:github.PullRequestLinks{}, Repository:github.Repository{}, Reactions:github.Reactions{}, NodeID:"", ActiveLockReason:""}`
+		ID:                Int64(0),
+		Number:            Int(0),
+		State:             String(""),
+		Locked:            Bool(false),
+		Title:             String(""),
+		Body:              String(""),
+		AuthorAssociation: String(""),
+		User:              &User{},
+		Assignee:          &User{},
+		Comments:          Int(0),
+		ClosedBy:          &User{},
+		URL:               String(""),
+		HTMLURL:           String(""),
+		CommentsURL:       String(""),
+		EventsURL:         String(""),
+		LabelsURL:         String(""),
+		RepositoryURL:     String(""),
+		Milestone:         &Milestone{},
+		PullRequestLinks:  &PullRequestLinks{},
+		Repository:        &Repository{},
+		Reactions:         &Reactions{},
+		NodeID:            String(""),
+		ActiveLockReason:  String(""),
+	}
+	want := `github.Issue{ID:0, Number:0, State:"", Locked:false, Title:"", Body:"", AuthorAssociation:"", User:github.User{}, Assignee:github.User{}, Comments:0, ClosedBy:github.User{}, URL:"", HTMLURL:"", CommentsURL:"", EventsURL:"", LabelsURL:"", RepositoryURL:"", Milestone:github.Milestone{}, PullRequestLinks:github.PullRequestLinks{}, Repository:github.Repository{}, Reactions:github.Reactions{}, NodeID:"", ActiveLockReason:""}`
 	if got := v.String(); got != want {
 		t.Errorf("Issue.String = %v, want %v", got, want)
 	}
diff --git a/github/issues_test.go b/github/issues_test.go
index 0a11935d..6792db02 100644
--- a/github/issues_test.go
+++ b/github/issues_test.go
@@ -159,7 +159,7 @@ func TestIssuesService_Get(t *testing.T) {
 	mux.HandleFunc("/repos/o/r/issues/1", func(w http.ResponseWriter, r *http.Request) {
 		testMethod(t, r, "GET")
 		testHeader(t, r, "Accept", strings.Join(wantAcceptHeaders, ", "))
-		fmt.Fprint(w, `{"number":1, "labels": [{"url": "u", "name": "n", "color": "c"}]}`)
+		fmt.Fprint(w, `{"number":1, "author_association": "MEMBER","labels": [{"url": "u", "name": "n", "color": "c"}]}`)
 	})
 
 	issue, _, err := client.Issues.Get(context.Background(), "o", "r", 1)
@@ -168,7 +168,8 @@ func TestIssuesService_Get(t *testing.T) {
 	}
 
 	want := &Issue{
-		Number: Int(1),
+		Number:            Int(1),
+		AuthorAssociation: String("MEMBER"),
 		Labels: []*Label{{
 			URL:   String("u"),
 			Name:  String("n"),