Repository: google/go-github
Pull request #2750 (2023-04-12 21:17:15)

Add `Owner` to `EditChange` struct
Closes https://github.com/google/go-github/issues/2749

Let me know if you have a better idea for struct names.

codecov[bot]: ## [Codecov](https://codecov.io/gh/google/go-github/pull/2750?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) Report
> Merging [#2750](https://codecov.io/gh/google/go-github/pull/2750?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (980ddc6) into [master](https://codecov.io/gh/google/go-github/commit/683c2d7d7d40e2018285d356d0a45abaa5a9c286?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google) (683c2d7) will **not change** coverage.
> The diff coverage is `n/a`.

```diff
@@           Coverage Diff           @@
##           master    #2750   +/-   ##
=======================================
  Coverage   98.05%   98.05%           
=======================================
  Files         132      132           
  Lines       11628    11628           
=======================================
  Hits        11402    11402           
  Misses        154      154           
  Partials       72       72           
```


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

Help us with your feedback. Take ten seconds to tell us [how you rate us](https://about.codecov.io/nps?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google). Have a feature suggestion? [Share it here.](https://app.codecov.io/gh/feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=google)


Patch:
diff --git a/github/event_types.go b/github/event_types.go
index 71dfd2d0..2340a601 100644
--- a/github/event_types.go
+++ b/github/event_types.go
@@ -332,6 +332,7 @@ type EditChange struct {
 	Body  *EditBody  `json:"body,omitempty"`
 	Base  *EditBase  `json:"base,omitempty"`
 	Repo  *EditRepo  `json:"repository,omitempty"`
+	Owner *EditOwner `json:"owner,omitempty"`
 }
 
 // EditTitle represents a pull-request title change.
@@ -360,6 +361,17 @@ type EditRepo struct {
 	Name *RepoName `json:"name,omitempty"`
 }
 
+// EditOwner represents a change of repository ownership.
+type EditOwner struct {
+	OwnerInfo *OwnerInfo `json:"from,omitempty"`
+}
+
+// OwnerInfo represents the account info of the owner of the repo (could be User or Organization but both are User structs).
+type OwnerInfo struct {
+	User *User `json:"user,omitempty"`
+	Org  *User `json:"organization,omitempty"`
+}
+
 // RepoName represents a change of repository name.
 type RepoName struct {
 	From *string `json:"from,omitempty"`
diff --git a/github/github-accessors.go b/github/github-accessors.go
index 1473c56f..eea7518c 100644
--- a/github/github-accessors.go
+++ b/github/github-accessors.go
@@ -5470,6 +5470,14 @@ func (e *EditChange) GetBody() *EditBody {
 	return e.Body
 }
 
+// GetOwner returns the Owner field.
+func (e *EditChange) GetOwner() *EditOwner {
+	if e == nil {
+		return nil
+	}
+	return e.Owner
+}
+
 // GetRepo returns the Repo field.
 func (e *EditChange) GetRepo() *EditRepo {
 	if e == nil {
@@ -5486,6 +5494,14 @@ func (e *EditChange) GetTitle() *EditTitle {
 	return e.Title
 }
 
+// GetOwnerInfo returns the OwnerInfo field.
+func (e *EditOwner) GetOwnerInfo() *OwnerInfo {
+	if e == nil {
+		return nil
+	}
+	return e.OwnerInfo
+}
+
 // GetFrom returns the From field if it's non-nil, zero value otherwise.
 func (e *EditRef) GetFrom() string {
 	if e == nil || e.From == nil {
@@ -11230,6 +11246,22 @@ func (o *OrgStats) GetTotalTeams() int {
 	return *o.TotalTeams
 }
 
+// GetOrg returns the Org field.
+func (o *OwnerInfo) GetOrg() *User {
+	if o == nil {
+		return nil
+	}
+	return o.Org
+}
+
+// GetUser returns the User field.
+func (o *OwnerInfo) GetUser() *User {
+	if o == nil {
+		return nil
+	}
+	return o.User
+}
+
 // GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise.
 func (p *Package) GetCreatedAt() Timestamp {
 	if p == nil || p.CreatedAt == nil {


Test patch:
diff --git a/github/event_types_test.go b/github/event_types_test.go
index a2628b85..cdbaee55 100644
--- a/github/event_types_test.go
+++ b/github/event_types_test.go
@@ -104,6 +104,82 @@ func TestEditChange_Marshal_Repo(t *testing.T) {
 	testJSONMarshal(t, u, want)
 }
 
+func TestEditChange_Marshal_TransferFromUser(t *testing.T) {
+	testJSONMarshal(t, &EditChange{}, "{}")
+
+	u := &EditChange{
+		Owner: &EditOwner{
+			OwnerInfo: &OwnerInfo{
+				User: &User{
+					Login:     String("l"),
+					ID:        Int64(1),
+					NodeID:    String("n"),
+					URL:       String("u"),
+					ReposURL:  String("r"),
+					EventsURL: String("e"),
+					AvatarURL: String("a"),
+				},
+			},
+		},
+	}
+
+	want := `{
+		"owner": {
+			"from": {
+				"user": {
+					"login": "l",
+          			"id": 1,
+         		 	"node_id": "n",
+          			"avatar_url": "a",
+          			"url": "u",
+          			"repos_url": "r",
+          			"events_url": "e"
+				}
+			}
+		}
+	}`
+
+	testJSONMarshal(t, u, want)
+}
+
+func TestEditChange_Marshal_TransferFromOrg(t *testing.T) {
+	testJSONMarshal(t, &EditChange{}, "{}")
+
+	u := &EditChange{
+		Owner: &EditOwner{
+			OwnerInfo: &OwnerInfo{
+				Org: &User{
+					Login:     String("l"),
+					ID:        Int64(1),
+					NodeID:    String("n"),
+					URL:       String("u"),
+					ReposURL:  String("r"),
+					EventsURL: String("e"),
+					AvatarURL: String("a"),
+				},
+			},
+		},
+	}
+
+	want := `{
+		"owner": {
+			"from": {
+				"organization": {
+					"login": "l",
+          			"id": 1,
+         		 	"node_id": "n",
+          			"avatar_url": "a",
+          			"url": "u",
+          			"repos_url": "r",
+          			"events_url": "e"
+				}
+			}
+		}
+	}`
+
+	testJSONMarshal(t, u, want)
+}
+
 func TestProjectChange_Marshal_NameChange(t *testing.T) {
 	testJSONMarshal(t, &ProjectChange{}, "{}")
 
diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go
index 52a0e5b9..5b2054bf 100644
--- a/github/github-accessors_test.go
+++ b/github/github-accessors_test.go
@@ -6397,6 +6397,13 @@ func TestEditChange_GetBody(tt *testing.T) {
 	e.GetBody()
 }
 
+func TestEditChange_GetOwner(tt *testing.T) {
+	e := &EditChange{}
+	e.GetOwner()
+	e = nil
+	e.GetOwner()
+}
+
 func TestEditChange_GetRepo(tt *testing.T) {
 	e := &EditChange{}
 	e.GetRepo()
@@ -6411,6 +6418,13 @@ func TestEditChange_GetTitle(tt *testing.T) {
 	e.GetTitle()
 }
 
+func TestEditOwner_GetOwnerInfo(tt *testing.T) {
+	e := &EditOwner{}
+	e.GetOwnerInfo()
+	e = nil
+	e.GetOwnerInfo()
+}
+
 func TestEditRef_GetFrom(tt *testing.T) {
 	var zeroValue string
 	e := &EditRef{From: &zeroValue}
@@ -13177,6 +13191,20 @@ func TestOrgStats_GetTotalTeams(tt *testing.T) {
 	o.GetTotalTeams()
 }
 
+func TestOwnerInfo_GetOrg(tt *testing.T) {
+	o := &OwnerInfo{}
+	o.GetOrg()
+	o = nil
+	o.GetOrg()
+}
+
+func TestOwnerInfo_GetUser(tt *testing.T) {
+	o := &OwnerInfo{}
+	o.GetUser()
+	o = nil
+	o.GetUser()
+}
+
 func TestPackage_GetCreatedAt(tt *testing.T) {
 	var zeroValue Timestamp
 	p := &Package{CreatedAt: &zeroValue}