diff --git a/github/event_types.go b/github/event_types.go index 71dfd2d0a02..2340a60156f 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/event_types_test.go b/github/event_types_test.go index a2628b85378..cdbaee5542b 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.go b/github/github-accessors.go index 1473c56f5ca..eea7518cbab 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 { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 52a0e5b9020..5b2054bfeb4 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}