From b7da56bf8abac2c30835a315dd3b5c1e27099e9f Mon Sep 17 00:00:00 2001 From: Iain Steers Date: Thu, 3 Feb 2022 16:16:06 +0000 Subject: [PATCH 1/2] Add Repo Org fields to DeployKeyEvent --- github/event_types.go | 8 ++++++++ github/github-accessors.go | 24 ++++++++++++++++++++++++ github/github-accessors_test.go | 21 +++++++++++++++++++++ 3 files changed, 53 insertions(+) diff --git a/github/event_types.go b/github/event_types.go index 6a806c4a1e..c238288340 100644 --- a/github/event_types.go +++ b/github/event_types.go @@ -145,7 +145,15 @@ type DeployKeyEvent struct { // The deploy key resource. Key *Key `json:"key,omitempty"` + // The Repository where the event occurred + Repo *Repository `json:"repository,omitempty"` + + // The following field is only present when the webhook is triggered on + // a repository belonging to an organization. + Organization *Organization `json:"organization,omitempty"` + // The following fields are only populated by Webhook events. + Sender *User `json:"sender,omitempty"` Installation *Installation `json:"installation,omitempty"` } diff --git a/github/github-accessors.go b/github/github-accessors.go index 96cfbc5924..4bc74e5753 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -3444,6 +3444,30 @@ func (d *DeployKeyEvent) GetKey() *Key { return d.Key } +// GetOrganization returns the Organization field. +func (d *DeployKeyEvent) GetOrganization() *Organization { + if d == nil { + return nil + } + return d.Organization +} + +// GetRepo returns the Repo field. +func (d *DeployKeyEvent) GetRepo() *Repository { + if d == nil { + return nil + } + return d.Repo +} + +// GetSender returns the Sender field. +func (d *DeployKeyEvent) GetSender() *User { + if d == nil { + return nil + } + return d.Sender +} + // GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise. func (d *Deployment) GetCreatedAt() Timestamp { if d == nil || d.CreatedAt == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 4aa6d6df9f..3c480f4eb2 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -4027,6 +4027,27 @@ func TestDeployKeyEvent_GetKey(tt *testing.T) { d.GetKey() } +func TestDeployKeyEvent_GetOrganization(tt *testing.T) { + d := &DeployKeyEvent{} + d.GetOrganization() + d = nil + d.GetOrganization() +} + +func TestDeployKeyEvent_GetRepo(tt *testing.T) { + d := &DeployKeyEvent{} + d.GetRepo() + d = nil + d.GetRepo() +} + +func TestDeployKeyEvent_GetSender(tt *testing.T) { + d := &DeployKeyEvent{} + d.GetSender() + d = nil + d.GetSender() +} + func TestDeployment_GetCreatedAt(tt *testing.T) { var zeroValue Timestamp d := &Deployment{CreatedAt: &zeroValue} From e73028944e5bd42d840c13caf375af872317e0be Mon Sep 17 00:00:00 2001 From: Iain Steers Date: Thu, 3 Feb 2022 16:16:51 +0000 Subject: [PATCH 2/2] Expand DeployKeyEvent marshal test --- github/event_types_test.go | 72 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/github/event_types_test.go b/github/event_types_test.go index 221d20c5d5..67cc1171a8 100644 --- a/github/event_types_test.go +++ b/github/event_types_test.go @@ -10220,6 +10220,42 @@ func TestDeployKeyEvent_Marshal(t *testing.T) { Verified: Bool(false), CreatedAt: &Timestamp{referenceTime}, }, + Repo: &Repository{ + ID: Int64(1), + URL: String("s"), + Name: String("n"), + }, + Organization: &Organization{ + BillingEmail: String("be"), + Blog: String("b"), + Company: String("c"), + Email: String("e"), + TwitterUsername: String("tu"), + Location: String("loc"), + Name: String("n"), + Description: String("d"), + IsVerified: Bool(true), + HasOrganizationProjects: Bool(true), + HasRepositoryProjects: Bool(true), + DefaultRepoPermission: String("drp"), + MembersCanCreateRepos: Bool(true), + MembersCanCreateInternalRepos: Bool(true), + MembersCanCreatePrivateRepos: Bool(true), + MembersCanCreatePublicRepos: Bool(false), + MembersAllowedRepositoryCreationType: String("marct"), + MembersCanCreatePages: Bool(true), + MembersCanCreatePublicPages: Bool(false), + MembersCanCreatePrivatePages: Bool(true), + }, + Sender: &User{ + Login: String("l"), + ID: Int64(1), + NodeID: String("n"), + AvatarURL: String("a"), + URL: String("u"), + EventsURL: String("e"), + ReposURL: String("r"), + }, } want := `{ @@ -10232,6 +10268,42 @@ func TestDeployKeyEvent_Marshal(t *testing.T) { "read_only": false, "verified": false, "created_at": ` + referenceTimeStr + ` + }, + "repository": { + "id": 1, + "name": "n", + "url": "s" + }, + "organization": { + "name": "n", + "company": "c", + "blog": "b", + "location": "loc", + "email": "e", + "twitter_username": "tu", + "description": "d", + "billing_email": "be", + "is_verified": true, + "has_organization_projects": true, + "has_repository_projects": true, + "default_repository_permission": "drp", + "members_can_create_repositories": true, + "members_can_create_public_repositories": false, + "members_can_create_private_repositories": true, + "members_can_create_internal_repositories": true, + "members_allowed_repository_creation_type": "marct", + "members_can_create_pages": true, + "members_can_create_public_pages": false, + "members_can_create_private_pages": true + }, + "sender": { + "login": "l", + "id": 1, + "node_id": "n", + "avatar_url": "a", + "url": "u", + "events_url": "e", + "repos_url": "r" } }`