From 5f7c8e15dd412f39b6b2e504ecfd59e962f33a43 Mon Sep 17 00:00:00 2001 From: Nikita Pivkin Date: Sun, 13 Aug 2023 17:44:01 +0700 Subject: [PATCH 1/2] feat: support for projects_v2 and projects_v2_item webhook events --- github/event.go | 4 + github/event_types.go | 71 +++++ github/event_types_test.go | 391 ++++++++++++++++++++++++++ github/github-accessors.go | 296 +++++++++++++++++++ github/github-accessors_test.go | 328 +++++++++++++++++++++ github/messages.go | 2 + github/messages_test.go | 8 + github/repos_hooks_deliveries_test.go | 2 + 8 files changed, 1102 insertions(+) diff --git a/github/event.go b/github/event.go index 2349cb77600..46c85a323ed 100644 --- a/github/event.go +++ b/github/event.go @@ -105,6 +105,10 @@ func (e *Event) ParsePayload() (payload interface{}, err error) { payload = &ProjectCardEvent{} case "ProjectColumnEvent": payload = &ProjectColumnEvent{} + case "ProjectV2Event": + payload = &ProjectV2Event{} + case "ProjectV2ItemEvent": + payload = &ProjectV2ItemEvent{} case "PublicEvent": payload = &PublicEvent{} case "PullRequestEvent": diff --git a/github/event_types.go b/github/event_types.go index a24134479c0..f3f634ab958 100644 --- a/github/event_types.go +++ b/github/event_types.go @@ -942,6 +942,77 @@ type ProjectColumnEvent struct { Installation *Installation `json:"installation,omitempty"` } +// ProjectV2Event is triggered when there is activity relating to an organization-level project. +// The Webhook event name is "projects_v2" +// +// GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#projects_v2 +type ProjectV2Event struct { + Action *string `json:"action,omitempty"` + ProjectsV2 *ProjectsV2 `json:"projects_v2,omitempty"` + + // The following fields are only populated by Webhook events. + Installation *Installation `json:"installation,omitempty"` + Org *Organization `json:"organization,omitempty"` + Sender *User `json:"sender,omitempty"` +} + +// ProjectsV2 represents a projects v2 project. +type ProjectsV2 struct { + ID *int64 `json:"id,omitempty"` + NodeID *string `json:"node_id,omitempty"` + Owner *User `json:"owner,omitempty"` + Creator *User `json:"creator,omitempty"` + Title *string `json:"title,omitempty"` + Description *string `json:"description,omitempty"` + Public *bool `json:"public,omitempty"` + ClosedAt *Timestamp `json:"closed_at,omitempty"` + CreatedAt *Timestamp `json:"created_at,omitempty"` + UpdatedAt *Timestamp `json:"updated_at,omitempty"` + DeletedAt *Timestamp `json:"deleted_at,omitempty"` + Number *int `json:"number,omitempty"` + ShortDescription *string `json:"short_description,omitempty"` + DeletedBy *User `json:"deleted_by,omitempty"` +} + +// ProjectV2ItemEvent triggered when there is activity relating to an item on an organization-level project. +// The Webhook event name is "projects_v2_item" +// +// GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#projects_v2_item +type ProjectV2ItemEvent struct { + Action *string `json:"action,omitempty"` + Changes *ProjectV2ItemChange `json:"changes,omitempty"` + ProjectV2Item *ProjectV2Item `json:"projects_v2_item,omitempty"` + + // The following fields are only populated by Webhook events. + Installation *Installation `json:"installation,omitempty"` + Org *Organization `json:"organization,omitempty"` + Sender *User `json:"sender,omitempty"` +} + +// ProjectV2ItemChange represents a project v2 item change. +type ProjectV2ItemChange struct { + ArchivedAt *ArchivedAt `json:"archived_at,omitempty"` +} + +// ArchivedAt represents an archiving date change. +type ArchivedAt struct { + From *Timestamp `json:"from,omitempty"` + To *Timestamp `json:"to,omitempty"` +} + +// ProjectsV2 represents an item belonging to a project. +type ProjectV2Item struct { + ID *int64 `json:"id,omitempty"` + NodeID *string `json:"node_id,omitempty"` + ProjectNodeID *string `json:"project_node_id,omitempty"` + ContentNodeID *string `json:"content_node_id,omitempty"` + ContentType *string `json:"content_type,omitempty"` + Creator *User `json:"creator,omitempty"` + CreatedAt *Timestamp `json:"created_at,omitempty"` + UpdatedAt *Timestamp `json:"updated_at,omitempty"` + ArchivedAt *Timestamp `json:"archived_at,omitempty"` +} + // PublicEvent is triggered when a private repository is open sourced. // According to GitHub: "Without a doubt: the best GitHub event." // The Webhook event name is "public". diff --git a/github/event_types_test.go b/github/event_types_test.go index 8d6a8b95b16..2c4bc47a7b5 100644 --- a/github/event_types_test.go +++ b/github/event_types_test.go @@ -14092,6 +14092,397 @@ func TestProjectColumnEvent_Marshal(t *testing.T) { testJSONMarshal(t, u, want) } +func TestProjectV2Event_Marshal(t *testing.T) { + testJSONMarshal(t, &ProjectV2Event{}, "{}") + + u := &ProjectV2Event{ + Action: String("a"), + ProjectsV2: &ProjectsV2{ + ID: Int64(1), + NodeID: String("nid"), + Owner: &User{ + Login: String("l"), + ID: Int64(1), + NodeID: String("n"), + URL: String("u"), + ReposURL: String("r"), + EventsURL: String("e"), + AvatarURL: String("a"), + }, + Creator: &User{ + Login: String("l"), + ID: Int64(1), + NodeID: String("n"), + URL: String("u"), + ReposURL: String("r"), + EventsURL: String("e"), + AvatarURL: String("a"), + }, + Title: String("t"), + Description: String("d"), + Public: Bool(true), + ClosedAt: &Timestamp{referenceTime}, + CreatedAt: &Timestamp{referenceTime}, + UpdatedAt: &Timestamp{referenceTime}, + DeletedAt: &Timestamp{referenceTime}, + Number: Int(1), + ShortDescription: String("sd"), + DeletedBy: &User{ + Login: String("l"), + ID: Int64(1), + NodeID: String("n"), + URL: String("u"), + ReposURL: String("r"), + EventsURL: String("e"), + AvatarURL: String("a"), + }, + }, + Org: &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"), + URL: String("u"), + ReposURL: String("r"), + EventsURL: String("e"), + AvatarURL: String("a"), + }, + Installation: &Installation{ + ID: Int64(1), + NodeID: String("nid"), + AppID: Int64(1), + AppSlug: String("as"), + TargetID: Int64(1), + Account: &User{ + Login: String("l"), + ID: Int64(1), + URL: String("u"), + AvatarURL: String("a"), + GravatarID: String("g"), + Name: String("n"), + Company: String("c"), + Blog: String("b"), + Location: String("l"), + Email: String("e"), + Hireable: Bool(true), + Bio: String("b"), + TwitterUsername: String("t"), + PublicRepos: Int(1), + Followers: Int(1), + Following: Int(1), + CreatedAt: &Timestamp{referenceTime}, + SuspendedAt: &Timestamp{referenceTime}, + }, + }, + } + + want := `{ + "action": "a", + "projects_v2": { + "id": 1, + "node_id": "nid", + "owner": { + "login": "l", + "id": 1, + "node_id": "n", + "avatar_url": "a", + "url": "u", + "events_url": "e", + "repos_url": "r" + }, + "creator": { + "login": "l", + "id": 1, + "node_id": "n", + "avatar_url": "a", + "url": "u", + "events_url": "e", + "repos_url": "r" + }, + "title": "t", + "description": "d", + "public": true, + "closed_at": ` + referenceTimeStr + `, + "created_at": ` + referenceTimeStr + `, + "updated_at": ` + referenceTimeStr + `, + "deleted_at": ` + referenceTimeStr + `, + "number": 1, + "short_description": "sd", + "deleted_by": { + "login": "l", + "id": 1, + "node_id": "n", + "avatar_url": "a", + "url": "u", + "events_url": "e", + "repos_url": "r" + } + }, + "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" + }, + "installation": { + "id": 1, + "node_id": "nid", + "app_id": 1, + "app_slug": "as", + "target_id": 1, + "account": { + "login": "l", + "id": 1, + "avatar_url": "a", + "gravatar_id": "g", + "name": "n", + "company": "c", + "blog": "b", + "location": "l", + "email": "e", + "hireable": true, + "bio": "b", + "twitter_username": "t", + "public_repos": 1, + "followers": 1, + "following": 1, + "created_at": ` + referenceTimeStr + `, + "suspended_at": ` + referenceTimeStr + `, + "url": "u" + } + } + }` + + testJSONMarshal(t, u, want) + +} + +func TestProjectV2ItemEvent_Marshal(t *testing.T) { + testJSONMarshal(t, &ProjectV2ItemEvent{}, "{}") + + u := &ProjectV2ItemEvent{ + Action: String("a"), + Changes: &ProjectV2ItemChange{ + ArchivedAt: &ArchivedAt{ + From: &Timestamp{referenceTime}, + To: &Timestamp{referenceTime}, + }, + }, + ProjectV2Item: &ProjectV2Item{ + ID: Int64(1), + NodeID: String("nid"), + ProjectNodeID: String("pnid"), + ContentNodeID: String("cnid"), + ContentType: String("ct"), + Creator: &User{ + Login: String("l"), + ID: Int64(1), + NodeID: String("n"), + URL: String("u"), + ReposURL: String("r"), + EventsURL: String("e"), + AvatarURL: String("a"), + }, + CreatedAt: &Timestamp{referenceTime}, + UpdatedAt: &Timestamp{referenceTime}, + ArchivedAt: &Timestamp{referenceTime}, + }, + Org: &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"), + URL: String("u"), + ReposURL: String("r"), + EventsURL: String("e"), + AvatarURL: String("a"), + }, + Installation: &Installation{ + ID: Int64(1), + NodeID: String("nid"), + AppID: Int64(1), + AppSlug: String("as"), + TargetID: Int64(1), + Account: &User{ + Login: String("l"), + ID: Int64(1), + URL: String("u"), + AvatarURL: String("a"), + GravatarID: String("g"), + Name: String("n"), + Company: String("c"), + Blog: String("b"), + Location: String("l"), + Email: String("e"), + Hireable: Bool(true), + Bio: String("b"), + TwitterUsername: String("t"), + PublicRepos: Int(1), + Followers: Int(1), + Following: Int(1), + CreatedAt: &Timestamp{referenceTime}, + SuspendedAt: &Timestamp{referenceTime}, + }, + }, + } + + want := `{ + "action": "a", + "changes": { + "archived_at": { + "from": ` + referenceTimeStr + `, + "to": ` + referenceTimeStr + ` + } + }, + "projects_v2_item": { + "id": 1, + "node_id": "nid", + "project_node_id": "pnid", + "content_node_id": "cnid", + "content_type": "ct", + "creator": { + "login": "l", + "id": 1, + "node_id": "n", + "avatar_url": "a", + "url": "u", + "events_url": "e", + "repos_url": "r" + }, + "created_at": ` + referenceTimeStr + `, + "updated_at": ` + referenceTimeStr + `, + "archived_at": ` + referenceTimeStr + ` + }, + "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" + }, + "installation": { + "id": 1, + "node_id": "nid", + "app_id": 1, + "app_slug": "as", + "target_id": 1, + "account": { + "login": "l", + "id": 1, + "avatar_url": "a", + "gravatar_id": "g", + "name": "n", + "company": "c", + "blog": "b", + "location": "l", + "email": "e", + "hireable": true, + "bio": "b", + "twitter_username": "t", + "public_repos": 1, + "followers": 1, + "following": 1, + "created_at": ` + referenceTimeStr + `, + "suspended_at": ` + referenceTimeStr + `, + "url": "u" + } + } + }` + + testJSONMarshal(t, u, want) +} + func TestPullRequestEvent_Marshal(t *testing.T) { testJSONMarshal(t, &PullRequestEvent{}, "{}") diff --git a/github/github-accessors.go b/github/github-accessors.go index 3f665ede5cb..171adbe06ef 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -854,6 +854,22 @@ func (a *AppConfig) GetWebhookSecret() string { return *a.WebhookSecret } +// GetFrom returns the From field if it's non-nil, zero value otherwise. +func (a *ArchivedAt) GetFrom() Timestamp { + if a == nil || a.From == nil { + return Timestamp{} + } + return *a.From +} + +// GetTo returns the To field if it's non-nil, zero value otherwise. +func (a *ArchivedAt) GetTo() Timestamp { + if a == nil || a.To == nil { + return Timestamp{} + } + return *a.To +} + // GetArchiveDownloadURL returns the ArchiveDownloadURL field if it's non-nil, zero value otherwise. func (a *Artifact) GetArchiveDownloadURL() string { if a == nil || a.ArchiveDownloadURL == nil { @@ -14374,6 +14390,286 @@ func (p *ProjectPermissionLevel) GetUser() *User { return p.User } +// GetClosedAt returns the ClosedAt field if it's non-nil, zero value otherwise. +func (p *ProjectsV2) GetClosedAt() Timestamp { + if p == nil || p.ClosedAt == nil { + return Timestamp{} + } + return *p.ClosedAt +} + +// GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise. +func (p *ProjectsV2) GetCreatedAt() Timestamp { + if p == nil || p.CreatedAt == nil { + return Timestamp{} + } + return *p.CreatedAt +} + +// GetCreator returns the Creator field. +func (p *ProjectsV2) GetCreator() *User { + if p == nil { + return nil + } + return p.Creator +} + +// GetDeletedAt returns the DeletedAt field if it's non-nil, zero value otherwise. +func (p *ProjectsV2) GetDeletedAt() Timestamp { + if p == nil || p.DeletedAt == nil { + return Timestamp{} + } + return *p.DeletedAt +} + +// GetDeletedBy returns the DeletedBy field. +func (p *ProjectsV2) GetDeletedBy() *User { + if p == nil { + return nil + } + return p.DeletedBy +} + +// GetDescription returns the Description field if it's non-nil, zero value otherwise. +func (p *ProjectsV2) GetDescription() string { + if p == nil || p.Description == nil { + return "" + } + return *p.Description +} + +// GetID returns the ID field if it's non-nil, zero value otherwise. +func (p *ProjectsV2) GetID() int64 { + if p == nil || p.ID == nil { + return 0 + } + return *p.ID +} + +// GetNodeID returns the NodeID field if it's non-nil, zero value otherwise. +func (p *ProjectsV2) GetNodeID() string { + if p == nil || p.NodeID == nil { + return "" + } + return *p.NodeID +} + +// GetNumber returns the Number field if it's non-nil, zero value otherwise. +func (p *ProjectsV2) GetNumber() int { + if p == nil || p.Number == nil { + return 0 + } + return *p.Number +} + +// GetOwner returns the Owner field. +func (p *ProjectsV2) GetOwner() *User { + if p == nil { + return nil + } + return p.Owner +} + +// GetPublic returns the Public field if it's non-nil, zero value otherwise. +func (p *ProjectsV2) GetPublic() bool { + if p == nil || p.Public == nil { + return false + } + return *p.Public +} + +// GetShortDescription returns the ShortDescription field if it's non-nil, zero value otherwise. +func (p *ProjectsV2) GetShortDescription() string { + if p == nil || p.ShortDescription == nil { + return "" + } + return *p.ShortDescription +} + +// GetTitle returns the Title field if it's non-nil, zero value otherwise. +func (p *ProjectsV2) GetTitle() string { + if p == nil || p.Title == nil { + return "" + } + return *p.Title +} + +// GetUpdatedAt returns the UpdatedAt field if it's non-nil, zero value otherwise. +func (p *ProjectsV2) GetUpdatedAt() Timestamp { + if p == nil || p.UpdatedAt == nil { + return Timestamp{} + } + return *p.UpdatedAt +} + +// GetAction returns the Action field if it's non-nil, zero value otherwise. +func (p *ProjectV2Event) GetAction() string { + if p == nil || p.Action == nil { + return "" + } + return *p.Action +} + +// GetInstallation returns the Installation field. +func (p *ProjectV2Event) GetInstallation() *Installation { + if p == nil { + return nil + } + return p.Installation +} + +// GetOrg returns the Org field. +func (p *ProjectV2Event) GetOrg() *Organization { + if p == nil { + return nil + } + return p.Org +} + +// GetProjectsV2 returns the ProjectsV2 field. +func (p *ProjectV2Event) GetProjectsV2() *ProjectsV2 { + if p == nil { + return nil + } + return p.ProjectsV2 +} + +// GetSender returns the Sender field. +func (p *ProjectV2Event) GetSender() *User { + if p == nil { + return nil + } + return p.Sender +} + +// GetArchivedAt returns the ArchivedAt field if it's non-nil, zero value otherwise. +func (p *ProjectV2Item) GetArchivedAt() Timestamp { + if p == nil || p.ArchivedAt == nil { + return Timestamp{} + } + return *p.ArchivedAt +} + +// GetContentNodeID returns the ContentNodeID field if it's non-nil, zero value otherwise. +func (p *ProjectV2Item) GetContentNodeID() string { + if p == nil || p.ContentNodeID == nil { + return "" + } + return *p.ContentNodeID +} + +// GetContentType returns the ContentType field if it's non-nil, zero value otherwise. +func (p *ProjectV2Item) GetContentType() string { + if p == nil || p.ContentType == nil { + return "" + } + return *p.ContentType +} + +// GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise. +func (p *ProjectV2Item) GetCreatedAt() Timestamp { + if p == nil || p.CreatedAt == nil { + return Timestamp{} + } + return *p.CreatedAt +} + +// GetCreator returns the Creator field. +func (p *ProjectV2Item) GetCreator() *User { + if p == nil { + return nil + } + return p.Creator +} + +// GetID returns the ID field if it's non-nil, zero value otherwise. +func (p *ProjectV2Item) GetID() int64 { + if p == nil || p.ID == nil { + return 0 + } + return *p.ID +} + +// GetNodeID returns the NodeID field if it's non-nil, zero value otherwise. +func (p *ProjectV2Item) GetNodeID() string { + if p == nil || p.NodeID == nil { + return "" + } + return *p.NodeID +} + +// GetProjectNodeID returns the ProjectNodeID field if it's non-nil, zero value otherwise. +func (p *ProjectV2Item) GetProjectNodeID() string { + if p == nil || p.ProjectNodeID == nil { + return "" + } + return *p.ProjectNodeID +} + +// GetUpdatedAt returns the UpdatedAt field if it's non-nil, zero value otherwise. +func (p *ProjectV2Item) GetUpdatedAt() Timestamp { + if p == nil || p.UpdatedAt == nil { + return Timestamp{} + } + return *p.UpdatedAt +} + +// GetArchivedAt returns the ArchivedAt field. +func (p *ProjectV2ItemChange) GetArchivedAt() *ArchivedAt { + if p == nil { + return nil + } + return p.ArchivedAt +} + +// GetAction returns the Action field if it's non-nil, zero value otherwise. +func (p *ProjectV2ItemEvent) GetAction() string { + if p == nil || p.Action == nil { + return "" + } + return *p.Action +} + +// GetChanges returns the Changes field. +func (p *ProjectV2ItemEvent) GetChanges() *ProjectV2ItemChange { + if p == nil { + return nil + } + return p.Changes +} + +// GetInstallation returns the Installation field. +func (p *ProjectV2ItemEvent) GetInstallation() *Installation { + if p == nil { + return nil + } + return p.Installation +} + +// GetOrg returns the Org field. +func (p *ProjectV2ItemEvent) GetOrg() *Organization { + if p == nil { + return nil + } + return p.Org +} + +// GetProjectV2Item returns the ProjectV2Item field. +func (p *ProjectV2ItemEvent) GetProjectV2Item() *ProjectV2Item { + if p == nil { + return nil + } + return p.ProjectV2Item +} + +// GetSender returns the Sender field. +func (p *ProjectV2ItemEvent) GetSender() *User { + if p == nil { + return nil + } + return p.Sender +} + // GetAllowDeletions returns the AllowDeletions field. func (p *Protection) GetAllowDeletions() *AllowDeletions { if p == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 712d8fc94dd..5b76bc3e7c9 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -996,6 +996,26 @@ func TestAppConfig_GetWebhookSecret(tt *testing.T) { a.GetWebhookSecret() } +func TestArchivedAt_GetFrom(tt *testing.T) { + var zeroValue Timestamp + a := &ArchivedAt{From: &zeroValue} + a.GetFrom() + a = &ArchivedAt{} + a.GetFrom() + a = nil + a.GetFrom() +} + +func TestArchivedAt_GetTo(tt *testing.T) { + var zeroValue Timestamp + a := &ArchivedAt{To: &zeroValue} + a.GetTo() + a = &ArchivedAt{} + a.GetTo() + a = nil + a.GetTo() +} + func TestArtifact_GetArchiveDownloadURL(tt *testing.T) { var zeroValue string a := &Artifact{ArchiveDownloadURL: &zeroValue} @@ -16804,6 +16824,314 @@ func TestProjectPermissionLevel_GetUser(tt *testing.T) { p.GetUser() } +func TestProjectsV2_GetClosedAt(tt *testing.T) { + var zeroValue Timestamp + p := &ProjectsV2{ClosedAt: &zeroValue} + p.GetClosedAt() + p = &ProjectsV2{} + p.GetClosedAt() + p = nil + p.GetClosedAt() +} + +func TestProjectsV2_GetCreatedAt(tt *testing.T) { + var zeroValue Timestamp + p := &ProjectsV2{CreatedAt: &zeroValue} + p.GetCreatedAt() + p = &ProjectsV2{} + p.GetCreatedAt() + p = nil + p.GetCreatedAt() +} + +func TestProjectsV2_GetCreator(tt *testing.T) { + p := &ProjectsV2{} + p.GetCreator() + p = nil + p.GetCreator() +} + +func TestProjectsV2_GetDeletedAt(tt *testing.T) { + var zeroValue Timestamp + p := &ProjectsV2{DeletedAt: &zeroValue} + p.GetDeletedAt() + p = &ProjectsV2{} + p.GetDeletedAt() + p = nil + p.GetDeletedAt() +} + +func TestProjectsV2_GetDeletedBy(tt *testing.T) { + p := &ProjectsV2{} + p.GetDeletedBy() + p = nil + p.GetDeletedBy() +} + +func TestProjectsV2_GetDescription(tt *testing.T) { + var zeroValue string + p := &ProjectsV2{Description: &zeroValue} + p.GetDescription() + p = &ProjectsV2{} + p.GetDescription() + p = nil + p.GetDescription() +} + +func TestProjectsV2_GetID(tt *testing.T) { + var zeroValue int64 + p := &ProjectsV2{ID: &zeroValue} + p.GetID() + p = &ProjectsV2{} + p.GetID() + p = nil + p.GetID() +} + +func TestProjectsV2_GetNodeID(tt *testing.T) { + var zeroValue string + p := &ProjectsV2{NodeID: &zeroValue} + p.GetNodeID() + p = &ProjectsV2{} + p.GetNodeID() + p = nil + p.GetNodeID() +} + +func TestProjectsV2_GetNumber(tt *testing.T) { + var zeroValue int + p := &ProjectsV2{Number: &zeroValue} + p.GetNumber() + p = &ProjectsV2{} + p.GetNumber() + p = nil + p.GetNumber() +} + +func TestProjectsV2_GetOwner(tt *testing.T) { + p := &ProjectsV2{} + p.GetOwner() + p = nil + p.GetOwner() +} + +func TestProjectsV2_GetPublic(tt *testing.T) { + var zeroValue bool + p := &ProjectsV2{Public: &zeroValue} + p.GetPublic() + p = &ProjectsV2{} + p.GetPublic() + p = nil + p.GetPublic() +} + +func TestProjectsV2_GetShortDescription(tt *testing.T) { + var zeroValue string + p := &ProjectsV2{ShortDescription: &zeroValue} + p.GetShortDescription() + p = &ProjectsV2{} + p.GetShortDescription() + p = nil + p.GetShortDescription() +} + +func TestProjectsV2_GetTitle(tt *testing.T) { + var zeroValue string + p := &ProjectsV2{Title: &zeroValue} + p.GetTitle() + p = &ProjectsV2{} + p.GetTitle() + p = nil + p.GetTitle() +} + +func TestProjectsV2_GetUpdatedAt(tt *testing.T) { + var zeroValue Timestamp + p := &ProjectsV2{UpdatedAt: &zeroValue} + p.GetUpdatedAt() + p = &ProjectsV2{} + p.GetUpdatedAt() + p = nil + p.GetUpdatedAt() +} + +func TestProjectV2Event_GetAction(tt *testing.T) { + var zeroValue string + p := &ProjectV2Event{Action: &zeroValue} + p.GetAction() + p = &ProjectV2Event{} + p.GetAction() + p = nil + p.GetAction() +} + +func TestProjectV2Event_GetInstallation(tt *testing.T) { + p := &ProjectV2Event{} + p.GetInstallation() + p = nil + p.GetInstallation() +} + +func TestProjectV2Event_GetOrg(tt *testing.T) { + p := &ProjectV2Event{} + p.GetOrg() + p = nil + p.GetOrg() +} + +func TestProjectV2Event_GetProjectsV2(tt *testing.T) { + p := &ProjectV2Event{} + p.GetProjectsV2() + p = nil + p.GetProjectsV2() +} + +func TestProjectV2Event_GetSender(tt *testing.T) { + p := &ProjectV2Event{} + p.GetSender() + p = nil + p.GetSender() +} + +func TestProjectV2Item_GetArchivedAt(tt *testing.T) { + var zeroValue Timestamp + p := &ProjectV2Item{ArchivedAt: &zeroValue} + p.GetArchivedAt() + p = &ProjectV2Item{} + p.GetArchivedAt() + p = nil + p.GetArchivedAt() +} + +func TestProjectV2Item_GetContentNodeID(tt *testing.T) { + var zeroValue string + p := &ProjectV2Item{ContentNodeID: &zeroValue} + p.GetContentNodeID() + p = &ProjectV2Item{} + p.GetContentNodeID() + p = nil + p.GetContentNodeID() +} + +func TestProjectV2Item_GetContentType(tt *testing.T) { + var zeroValue string + p := &ProjectV2Item{ContentType: &zeroValue} + p.GetContentType() + p = &ProjectV2Item{} + p.GetContentType() + p = nil + p.GetContentType() +} + +func TestProjectV2Item_GetCreatedAt(tt *testing.T) { + var zeroValue Timestamp + p := &ProjectV2Item{CreatedAt: &zeroValue} + p.GetCreatedAt() + p = &ProjectV2Item{} + p.GetCreatedAt() + p = nil + p.GetCreatedAt() +} + +func TestProjectV2Item_GetCreator(tt *testing.T) { + p := &ProjectV2Item{} + p.GetCreator() + p = nil + p.GetCreator() +} + +func TestProjectV2Item_GetID(tt *testing.T) { + var zeroValue int64 + p := &ProjectV2Item{ID: &zeroValue} + p.GetID() + p = &ProjectV2Item{} + p.GetID() + p = nil + p.GetID() +} + +func TestProjectV2Item_GetNodeID(tt *testing.T) { + var zeroValue string + p := &ProjectV2Item{NodeID: &zeroValue} + p.GetNodeID() + p = &ProjectV2Item{} + p.GetNodeID() + p = nil + p.GetNodeID() +} + +func TestProjectV2Item_GetProjectNodeID(tt *testing.T) { + var zeroValue string + p := &ProjectV2Item{ProjectNodeID: &zeroValue} + p.GetProjectNodeID() + p = &ProjectV2Item{} + p.GetProjectNodeID() + p = nil + p.GetProjectNodeID() +} + +func TestProjectV2Item_GetUpdatedAt(tt *testing.T) { + var zeroValue Timestamp + p := &ProjectV2Item{UpdatedAt: &zeroValue} + p.GetUpdatedAt() + p = &ProjectV2Item{} + p.GetUpdatedAt() + p = nil + p.GetUpdatedAt() +} + +func TestProjectV2ItemChange_GetArchivedAt(tt *testing.T) { + p := &ProjectV2ItemChange{} + p.GetArchivedAt() + p = nil + p.GetArchivedAt() +} + +func TestProjectV2ItemEvent_GetAction(tt *testing.T) { + var zeroValue string + p := &ProjectV2ItemEvent{Action: &zeroValue} + p.GetAction() + p = &ProjectV2ItemEvent{} + p.GetAction() + p = nil + p.GetAction() +} + +func TestProjectV2ItemEvent_GetChanges(tt *testing.T) { + p := &ProjectV2ItemEvent{} + p.GetChanges() + p = nil + p.GetChanges() +} + +func TestProjectV2ItemEvent_GetInstallation(tt *testing.T) { + p := &ProjectV2ItemEvent{} + p.GetInstallation() + p = nil + p.GetInstallation() +} + +func TestProjectV2ItemEvent_GetOrg(tt *testing.T) { + p := &ProjectV2ItemEvent{} + p.GetOrg() + p = nil + p.GetOrg() +} + +func TestProjectV2ItemEvent_GetProjectV2Item(tt *testing.T) { + p := &ProjectV2ItemEvent{} + p.GetProjectV2Item() + p = nil + p.GetProjectV2Item() +} + +func TestProjectV2ItemEvent_GetSender(tt *testing.T) { + p := &ProjectV2ItemEvent{} + p.GetSender() + p = nil + p.GetSender() +} + func TestProtection_GetAllowDeletions(tt *testing.T) { p := &Protection{} p.GetAllowDeletions() diff --git a/github/messages.go b/github/messages.go index 929587d337f..401f69ea48c 100644 --- a/github/messages.go +++ b/github/messages.go @@ -82,6 +82,8 @@ var ( "project": "ProjectEvent", "project_card": "ProjectCardEvent", "project_column": "ProjectColumnEvent", + "projects_v2": "ProjectV2Event", + "projects_v2_item": "ProjectV2ItemEvent", "public": "PublicEvent", "pull_request": "PullRequestEvent", "pull_request_review": "PullRequestReviewEvent", diff --git a/github/messages_test.go b/github/messages_test.go index 8ee38eb346b..a3fd3c8630e 100644 --- a/github/messages_test.go +++ b/github/messages_test.go @@ -404,6 +404,14 @@ func TestParseWebHook(t *testing.T) { payload: &ProjectColumnEvent{}, messageType: "project_column", }, + { + payload: &ProjectV2Event{}, + messageType: "projects_v2", + }, + { + payload: &ProjectV2ItemEvent{}, + messageType: "projects_v2_item", + }, { payload: &PublicEvent{}, messageType: "public", diff --git a/github/repos_hooks_deliveries_test.go b/github/repos_hooks_deliveries_test.go index d1dda365194..8bb3e7c03f9 100644 --- a/github/repos_hooks_deliveries_test.go +++ b/github/repos_hooks_deliveries_test.go @@ -176,6 +176,8 @@ var hookDeliveryPayloadTypeToStruct = map[string]interface{}{ "project": &ProjectEvent{}, "project_card": &ProjectCardEvent{}, "project_column": &ProjectColumnEvent{}, + "projects_v2": &ProjectV2Event{}, + "projects_v2_item": &ProjectV2ItemEvent{}, "public": &PublicEvent{}, "pull_request": &PullRequestEvent{}, "pull_request_review": &PullRequestReviewEvent{}, From 1ecdb378c24f332a819a2835a58e38cd0875f301 Mon Sep 17 00:00:00 2001 From: Nikita Pivkin Date: Sun, 13 Aug 2023 23:22:59 +0700 Subject: [PATCH 2/2] fix after review --- github/event_types.go | 6 +++--- github/event_types_test.go | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/github/event_types.go b/github/event_types.go index f3f634ab958..81ca6a002e3 100644 --- a/github/event_types.go +++ b/github/event_types.go @@ -943,7 +943,7 @@ type ProjectColumnEvent struct { } // ProjectV2Event is triggered when there is activity relating to an organization-level project. -// The Webhook event name is "projects_v2" +// The Webhook event name is "projects_v2". // // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#projects_v2 type ProjectV2Event struct { @@ -974,8 +974,8 @@ type ProjectsV2 struct { DeletedBy *User `json:"deleted_by,omitempty"` } -// ProjectV2ItemEvent triggered when there is activity relating to an item on an organization-level project. -// The Webhook event name is "projects_v2_item" +// ProjectV2ItemEvent is triggered when there is activity relating to an item on an organization-level project. +// The Webhook event name is "projects_v2_item". // // GitHub API docs: https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#projects_v2_item type ProjectV2ItemEvent struct { diff --git a/github/event_types_test.go b/github/event_types_test.go index 2c4bc47a7b5..2b89d430521 100644 --- a/github/event_types_test.go +++ b/github/event_types_test.go @@ -14300,7 +14300,6 @@ func TestProjectV2Event_Marshal(t *testing.T) { }` testJSONMarshal(t, u, want) - } func TestProjectV2ItemEvent_Marshal(t *testing.T) {