diff --git a/github/event_types.go b/github/event_types.go index f63c8040336..122a7da995c 100644 --- a/github/event_types.go +++ b/github/event_types.go @@ -230,12 +230,13 @@ type GollumEvent struct { Installation *Installation `json:"installation,omitempty"` } -// EditChange represents the changes when an issue, pull request, or comment has -// been edited. +// EditChange represents the changes when an issue, pull request, comment, +// or repository has been edited. type EditChange struct { Title *EditTitle `json:"title,omitempty"` Body *EditBody `json:"body,omitempty"` Base *EditBase `json:"base,omitempty"` + Repo *EditRepo `json:"repository,omitempty"` } // EditTitle represents a pull-request title change. @@ -259,6 +260,16 @@ type EditRef struct { From *string `json:"from,omitempty"` } +// EditRepo represents a change of repository name. +type EditRepo struct { + Name *RepoName `json:"name,omitempty"` +} + +// RepoName represents a change of repository name. +type RepoName struct { + From *string `json:"from,omitempty"` +} + // EditSHA represents a sha change of a pull-request. type EditSHA struct { From *string `json:"from,omitempty"` @@ -938,6 +949,7 @@ type RepositoryEvent struct { Repo *Repository `json:"repository,omitempty"` // The following fields are only populated by Webhook events. + Changes *EditChange `json:"changes,omitempty"` Org *Organization `json:"organization,omitempty"` Sender *User `json:"sender,omitempty"` Installation *Installation `json:"installation,omitempty"` diff --git a/github/event_types_test.go b/github/event_types_test.go index d7113b5594f..bb5dd40d5dd 100644 --- a/github/event_types_test.go +++ b/github/event_types_test.go @@ -82,6 +82,28 @@ func TestEditChange_Marshal_BaseChange(t *testing.T) { testJSONMarshal(t, u, want) } +func TestEditChange_Marshal_Repo(t *testing.T) { + testJSONMarshal(t, &EditChange{}, "{}") + + u := &EditChange{ + Repo: &EditRepo{ + Name: &RepoName{ + From: String("old-repo-name"), + }, + }, + } + + want := `{ + "repository": { + "name": { + "from": "old-repo-name" + } + } + }` + + 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 166e2ad50c3..189e68b33bf 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -4100,6 +4100,14 @@ func (e *EditChange) GetBody() *EditBody { return e.Body } +// GetRepo returns the Repo field. +func (e *EditChange) GetRepo() *EditRepo { + if e == nil { + return nil + } + return e.Repo +} + // GetTitle returns the Title field. func (e *EditChange) GetTitle() *EditTitle { if e == nil { @@ -4116,6 +4124,14 @@ func (e *EditRef) GetFrom() string { return *e.From } +// GetName returns the Name field. +func (e *EditRepo) GetName() *RepoName { + if e == nil { + return nil + } + return e.Name +} + // GetFrom returns the From field if it's non-nil, zero value otherwise. func (e *EditSHA) GetFrom() string { if e == nil || e.From == nil { @@ -13196,6 +13212,14 @@ func (r *RenameOrgResponse) GetURL() string { return *r.URL } +// GetFrom returns the From field if it's non-nil, zero value otherwise. +func (r *RepoName) GetFrom() string { + if r == nil || r.From == nil { + return "" + } + return *r.From +} + // GetIncompleteResults returns the IncompleteResults field if it's non-nil, zero value otherwise. func (r *RepositoriesSearchResult) GetIncompleteResults() bool { if r == nil || r.IncompleteResults == nil { @@ -14332,6 +14356,14 @@ func (r *RepositoryEvent) GetAction() string { return *r.Action } +// GetChanges returns the Changes field. +func (r *RepositoryEvent) GetChanges() *EditChange { + if r == nil { + return nil + } + return r.Changes +} + // GetInstallation returns the Installation field. func (r *RepositoryEvent) GetInstallation() *Installation { if r == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index fa4dc56c397..69ed4030668 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -4796,6 +4796,13 @@ func TestEditChange_GetBody(tt *testing.T) { e.GetBody() } +func TestEditChange_GetRepo(tt *testing.T) { + e := &EditChange{} + e.GetRepo() + e = nil + e.GetRepo() +} + func TestEditChange_GetTitle(tt *testing.T) { e := &EditChange{} e.GetTitle() @@ -4813,6 +4820,13 @@ func TestEditRef_GetFrom(tt *testing.T) { e.GetFrom() } +func TestEditRepo_GetName(tt *testing.T) { + e := &EditRepo{} + e.GetName() + e = nil + e.GetName() +} + func TestEditSHA_GetFrom(tt *testing.T) { var zeroValue string e := &EditSHA{From: &zeroValue} @@ -15374,6 +15388,16 @@ func TestRenameOrgResponse_GetURL(tt *testing.T) { r.GetURL() } +func TestRepoName_GetFrom(tt *testing.T) { + var zeroValue string + r := &RepoName{From: &zeroValue} + r.GetFrom() + r = &RepoName{} + r.GetFrom() + r = nil + r.GetFrom() +} + func TestRepositoriesSearchResult_GetIncompleteResults(tt *testing.T) { var zeroValue bool r := &RepositoriesSearchResult{IncompleteResults: &zeroValue} @@ -16731,6 +16755,13 @@ func TestRepositoryEvent_GetAction(tt *testing.T) { r.GetAction() } +func TestRepositoryEvent_GetChanges(tt *testing.T) { + r := &RepositoryEvent{} + r.GetChanges() + r = nil + r.GetChanges() +} + func TestRepositoryEvent_GetInstallation(tt *testing.T) { r := &RepositoryEvent{} r.GetInstallation()