From 58baa10b56932ef99c96a6646aee658f1e3b3250 Mon Sep 17 00:00:00 2001 From: Apurwa Jadhav Date: Sat, 25 Feb 2023 08:18:49 -0800 Subject: [PATCH 1/2] Add DicussionCommentEvent Webhook google#2497 This commit has changes to enable support to receive DiscussionComment Webhook Event, to fix google#2497 Changes include: * Addition of event type for this type of event DiscussionCommentEvent * Changes for identification and mapping of DiscussionCommentEvent * Addition / Modification of relevant tests * Addition of files created by go generate --- github/event.go | 2 + github/event_types.go | 33 ++ github/event_types_test.go | 415 ++++++++++++++++++++++++++ github/github-accessors.go | 160 ++++++++++ github/github-accessors_test.go | 176 +++++++++++ github/messages.go | 1 + github/messages_test.go | 4 + github/repos_hooks_deliveries_test.go | 1 + 8 files changed, 792 insertions(+) diff --git a/github/event.go b/github/event.go index 44c5f46f9b0..1aabf13bade 100644 --- a/github/event.go +++ b/github/event.go @@ -53,6 +53,8 @@ func (e *Event) ParsePayload() (payload interface{}, err error) { payload = &DeploymentStatusEvent{} case "DiscussionEvent": payload = &DiscussionEvent{} + case "DiscussionCommentEvent": + payload = &DiscussionCommentEvent{} case "ForkEvent": payload = &ForkEvent{} case "GitHubAppAuthorizationEvent": diff --git a/github/event_types.go b/github/event_types.go index 50c7b567bcf..a83178ee0f9 100644 --- a/github/event_types.go +++ b/github/event_types.go @@ -189,6 +189,39 @@ type DeploymentStatusEvent struct { Installation *Installation `json:"installation,omitempty"` } +// DiscussionCommentEvent represents a webhook event for a comment on discussion. +// The Webhook event name is "discussion_comment". +// +// GitHub API docs: https://docs.github.com/webhooks-and-events/webhooks/webhook-events-and-payloads#discussion_comment +type DiscussionCommentEvent struct { + // Action is the action that was performed on the comment. + // Possible values are: "created", "edited", "deleted". ** check what all can be added + Action *string `json:"action,omitempty"` + Discussion *Discussion `json:"discussion,omitempty"` + Comment *CommentDiscussion `json:"comment,omitempty"` + Repo *Repository `json:"repository,omitempty"` + Org *Organization `json:"organization,omitempty"` + Sender *User `json:"sender,omitempty"` + Installation *Installation `json:"installation,omitempty"` +} + +// CommentDiscussion represents a comment in a GitHub DiscussionCommentEvent. +type CommentDiscussion struct { + AuthorAssociation *string `json:"author_association,omitempty"` + Body *string `json:"body,omitempty"` + ChildCommentCount *int `json:"child_comment_count,omitempty"` + CreatedAt *Timestamp `json:"created_at,omitempty"` + DiscussionID *int64 `json:"discussion_id,omitempty"` + HTMLURL *string `json:"html_url,omitempty"` + ID *int64 `json:"id,omitempty"` + NodeID *string `json:"node_id,omitempty"` + ParentID *int64 `json:"parent_id,omitempty"` + Reaction *Reactions `json:"reactions,omitempty"` + RepositoryURL *string `json:"repository_url,omitempty"` + UpdatedAt *Timestamp `json:"updated_at,omitempty"` + User *User `json:"user,omitempty"` +} + // DiscussionEvent represents a webhook event for a discussion. // The Webhook event name is "discussion". // diff --git a/github/event_types_test.go b/github/event_types_test.go index fdc0809e694..16b3b4d09f5 100644 --- a/github/event_types_test.go +++ b/github/event_types_test.go @@ -5740,6 +5740,421 @@ func TestDeploymentStatusEvent_Marshal(t *testing.T) { testJSONMarshal(t, u, want) } +func TestDiscussionCommentEvent_Marshal(t *testing.T) { + testJSONMarshal(t, &DiscussionCommentEvent{}, "{}") + + u := &DiscussionCommentEvent{ + Comment: &CommentDiscussion{ + AuthorAssociation: String("aa"), + Body: String("bo"), + ChildCommentCount: Int(1), + CreatedAt: &Timestamp{referenceTime}, + DiscussionID: Int64(1), + HTMLURL: String("hurl"), + ID: Int64(1), + NodeID: String("nid"), + ParentID: Int64(1), + Reaction: &Reactions{ + TotalCount: Int(1), + PlusOne: Int(1), + MinusOne: Int(1), + Laugh: Int(1), + Confused: Int(1), + Heart: Int(1), + Hooray: Int(1), + Rocket: Int(1), + Eyes: Int(1), + URL: String("url"), + }, + RepositoryURL: String("rurl"), + UpdatedAt: &Timestamp{referenceTime}, + User: &User{ + Login: String("l"), + ID: Int64(1), + NodeID: String("n"), + URL: String("u"), + ReposURL: String("r"), + EventsURL: String("e"), + AvatarURL: String("a"), + }, + }, + Discussion: &Discussion{ + RepositoryURL: String("rurl"), + DiscussionCategory: &DiscussionCategory{ + ID: Int64(1), + NodeID: String("nid"), + RepositoryID: Int64(1), + Emoji: String("emoji"), + Name: String("name"), + Description: String("description"), + CreatedAt: &Timestamp{referenceTime}, + UpdatedAt: &Timestamp{referenceTime}, + Slug: String("slug"), + IsAnswerable: Bool(false), + }, + HTMLURL: String("hurl"), + ID: Int64(1), + NodeID: String("nurl"), + Number: Int(1), + Title: String("title"), + User: &User{ + Login: String("l"), + ID: Int64(1), + NodeID: String("n"), + URL: String("u"), + ReposURL: String("r"), + EventsURL: String("e"), + AvatarURL: String("a"), + }, + State: String("st"), + Locked: Bool(false), + Comments: Int(1), + CreatedAt: &Timestamp{referenceTime}, + UpdatedAt: &Timestamp{referenceTime}, + AuthorAssociation: String("aa"), + Body: String("bo"), + }, + Repo: &Repository{ + ID: Int64(1), + URL: String("s"), + Name: String("n"), + }, + 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}, + }, + AccessTokensURL: String("atu"), + RepositoriesURL: String("ru"), + HTMLURL: String("hu"), + TargetType: String("tt"), + SingleFileName: String("sfn"), + RepositorySelection: String("rs"), + Events: []string{"e"}, + SingleFilePaths: []string{"s"}, + Permissions: &InstallationPermissions{ + Actions: String("a"), + Administration: String("ad"), + Checks: String("c"), + Contents: String("co"), + ContentReferences: String("cr"), + Deployments: String("d"), + Environments: String("e"), + Issues: String("i"), + Metadata: String("md"), + Members: String("m"), + OrganizationAdministration: String("oa"), + OrganizationHooks: String("oh"), + OrganizationPlan: String("op"), + OrganizationPreReceiveHooks: String("opr"), + OrganizationProjects: String("op"), + OrganizationSecrets: String("os"), + OrganizationSelfHostedRunners: String("osh"), + OrganizationUserBlocking: String("oub"), + Packages: String("pkg"), + Pages: String("pg"), + PullRequests: String("pr"), + RepositoryHooks: String("rh"), + RepositoryProjects: String("rp"), + RepositoryPreReceiveHooks: String("rprh"), + Secrets: String("s"), + SecretScanningAlerts: String("ssa"), + SecurityEvents: String("se"), + SingleFile: String("sf"), + Statuses: String("s"), + TeamDiscussions: String("td"), + VulnerabilityAlerts: String("va"), + Workflows: String("w"), + }, + CreatedAt: &Timestamp{referenceTime}, + UpdatedAt: &Timestamp{referenceTime}, + HasMultipleSingleFiles: Bool(false), + SuspendedBy: &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}, + }, + SuspendedAt: &Timestamp{referenceTime}, + }, + } + + want := `{ + "comment": { + "author_association": "aa", + "body": "bo", + "child_comment_count": 1, + "created_at": ` + referenceTimeStr + `, + "discussion_id": 1, + "html_url": "hurl", + "id": 1, + "node_id": "nid", + "parent_id": 1, + "reactions": { + "total_count": 1, + "+1": 1, + "-1": 1, + "laugh": 1, + "confused": 1, + "heart": 1, + "hooray": 1, + "rocket": 1, + "eyes": 1, + "url": "url" + }, + "repository_url": "rurl", + "updated_at": ` + referenceTimeStr + `, + "user": { + "login": "l", + "id": 1, + "node_id": "n", + "avatar_url": "a", + "url": "u", + "events_url": "e", + "repos_url": "r" + } + }, + "discussion": { + "repository_url": "rurl", + "category": { + "id": 1, + "node_id": "nid", + "repository_id": 1, + "emoji": "emoji", + "name": "name", + "description": "description", + "created_at": ` + referenceTimeStr + `, + "updated_at": ` + referenceTimeStr + `, + "slug": "slug", + "is_answerable": false + }, + "html_url": "hurl", + "id": 1, + "node_id": "nurl", + "number": 1, + "title": "title", + "user": { + "login": "l", + "id": 1, + "node_id": "n", + "avatar_url": "a", + "url": "u", + "events_url": "e", + "repos_url": "r" + }, + "state": "st", + "locked": false, + "comments": 1, + "created_at": ` + referenceTimeStr + `, + "updated_at": ` + referenceTimeStr + `, + "author_association": "aa", + "body": "bo" + }, + "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" + }, + "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" + }, + "access_tokens_url": "atu", + "repositories_url": "ru", + "html_url": "hu", + "target_type": "tt", + "single_file_name": "sfn", + "repository_selection": "rs", + "events": [ + "e" + ], + "single_file_paths": [ + "s" + ], + "permissions": { + "actions": "a", + "administration": "ad", + "checks": "c", + "contents": "co", + "content_references": "cr", + "deployments": "d", + "environments": "e", + "issues": "i", + "metadata": "md", + "members": "m", + "organization_administration": "oa", + "organization_hooks": "oh", + "organization_plan": "op", + "organization_pre_receive_hooks": "opr", + "organization_projects": "op", + "organization_secrets": "os", + "organization_self_hosted_runners": "osh", + "organization_user_blocking": "oub", + "packages": "pkg", + "pages": "pg", + "pull_requests": "pr", + "repository_hooks": "rh", + "repository_projects": "rp", + "repository_pre_receive_hooks": "rprh", + "secrets": "s", + "secret_scanning_alerts": "ssa", + "security_events": "se", + "single_file": "sf", + "statuses": "s", + "team_discussions": "td", + "vulnerability_alerts": "va", + "workflows": "w" + }, + "created_at": ` + referenceTimeStr + `, + "updated_at": ` + referenceTimeStr + `, + "has_multiple_single_files": false, + "suspended_by": { + "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" + }, + "suspended_at": ` + referenceTimeStr + ` + } + }` + + testJSONMarshal(t, u, want) +} + + func TestDiscussionEvent_Marshal(t *testing.T) { testJSONMarshal(t, &DiscussionEvent{}, "{}") diff --git a/github/github-accessors.go b/github/github-accessors.go index a7d800e20a9..49cfef3ce22 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -2854,6 +2854,110 @@ func (c *Comment) GetCreatedAt() Timestamp { return *c.CreatedAt } +// GetAuthorAssociation returns the AuthorAssociation field if it's non-nil, zero value otherwise. +func (c *CommentDiscussion) GetAuthorAssociation() string { + if c == nil || c.AuthorAssociation == nil { + return "" + } + return *c.AuthorAssociation +} + +// GetBody returns the Body field if it's non-nil, zero value otherwise. +func (c *CommentDiscussion) GetBody() string { + if c == nil || c.Body == nil { + return "" + } + return *c.Body +} + +// GetChildCommentCount returns the ChildCommentCount field if it's non-nil, zero value otherwise. +func (c *CommentDiscussion) GetChildCommentCount() int { + if c == nil || c.ChildCommentCount == nil { + return 0 + } + return *c.ChildCommentCount +} + +// GetCreatedAt returns the CreatedAt field if it's non-nil, zero value otherwise. +func (c *CommentDiscussion) GetCreatedAt() Timestamp { + if c == nil || c.CreatedAt == nil { + return Timestamp{} + } + return *c.CreatedAt +} + +// GetDiscussionID returns the DiscussionID field if it's non-nil, zero value otherwise. +func (c *CommentDiscussion) GetDiscussionID() int64 { + if c == nil || c.DiscussionID == nil { + return 0 + } + return *c.DiscussionID +} + +// GetHTMLURL returns the HTMLURL field if it's non-nil, zero value otherwise. +func (c *CommentDiscussion) GetHTMLURL() string { + if c == nil || c.HTMLURL == nil { + return "" + } + return *c.HTMLURL +} + +// GetID returns the ID field if it's non-nil, zero value otherwise. +func (c *CommentDiscussion) GetID() int64 { + if c == nil || c.ID == nil { + return 0 + } + return *c.ID +} + +// GetNodeID returns the NodeID field if it's non-nil, zero value otherwise. +func (c *CommentDiscussion) GetNodeID() string { + if c == nil || c.NodeID == nil { + return "" + } + return *c.NodeID +} + +// GetParentID returns the ParentID field if it's non-nil, zero value otherwise. +func (c *CommentDiscussion) GetParentID() int64 { + if c == nil || c.ParentID == nil { + return 0 + } + return *c.ParentID +} + +// GetReaction returns the Reaction field. +func (c *CommentDiscussion) GetReaction() *Reactions { + if c == nil { + return nil + } + return c.Reaction +} + +// GetRepositoryURL returns the RepositoryURL field if it's non-nil, zero value otherwise. +func (c *CommentDiscussion) GetRepositoryURL() string { + if c == nil || c.RepositoryURL == nil { + return "" + } + return *c.RepositoryURL +} + +// GetUpdatedAt returns the UpdatedAt field if it's non-nil, zero value otherwise. +func (c *CommentDiscussion) GetUpdatedAt() Timestamp { + if c == nil || c.UpdatedAt == nil { + return Timestamp{} + } + return *c.UpdatedAt +} + +// GetUser returns the User field. +func (c *CommentDiscussion) GetUser() *User { + if c == nil { + return nil + } + return c.User +} + // GetTotalCommitComments returns the TotalCommitComments field if it's non-nil, zero value otherwise. func (c *CommentStats) GetTotalCommitComments() int { if c == nil || c.TotalCommitComments == nil { @@ -5046,6 +5150,62 @@ func (d *DiscussionComment) GetURL() string { return *d.URL } +// GetAction returns the Action field if it's non-nil, zero value otherwise. +func (d *DiscussionCommentEvent) GetAction() string { + if d == nil || d.Action == nil { + return "" + } + return *d.Action +} + +// GetComment returns the Comment field. +func (d *DiscussionCommentEvent) GetComment() *CommentDiscussion { + if d == nil { + return nil + } + return d.Comment +} + +// GetDiscussion returns the Discussion field. +func (d *DiscussionCommentEvent) GetDiscussion() *Discussion { + if d == nil { + return nil + } + return d.Discussion +} + +// GetInstallation returns the Installation field. +func (d *DiscussionCommentEvent) GetInstallation() *Installation { + if d == nil { + return nil + } + return d.Installation +} + +// GetOrg returns the Org field. +func (d *DiscussionCommentEvent) GetOrg() *Organization { + if d == nil { + return nil + } + return d.Org +} + +// GetRepo returns the Repo field. +func (d *DiscussionCommentEvent) GetRepo() *Repository { + if d == nil { + return nil + } + return d.Repo +} + +// GetSender returns the Sender field. +func (d *DiscussionCommentEvent) GetSender() *User { + if d == nil { + return nil + } + return d.Sender +} + // GetAction returns the Action field if it's non-nil, zero value otherwise. func (d *DiscussionEvent) GetAction() string { if d == nil || d.Action == nil { diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index 2bd40a94be4..cd7991afe66 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -3373,6 +3373,130 @@ func TestComment_GetCreatedAt(tt *testing.T) { c.GetCreatedAt() } +func TestCommentDiscussion_GetAuthorAssociation(tt *testing.T) { + var zeroValue string + c := &CommentDiscussion{AuthorAssociation: &zeroValue} + c.GetAuthorAssociation() + c = &CommentDiscussion{} + c.GetAuthorAssociation() + c = nil + c.GetAuthorAssociation() +} + +func TestCommentDiscussion_GetBody(tt *testing.T) { + var zeroValue string + c := &CommentDiscussion{Body: &zeroValue} + c.GetBody() + c = &CommentDiscussion{} + c.GetBody() + c = nil + c.GetBody() +} + +func TestCommentDiscussion_GetChildCommentCount(tt *testing.T) { + var zeroValue int + c := &CommentDiscussion{ChildCommentCount: &zeroValue} + c.GetChildCommentCount() + c = &CommentDiscussion{} + c.GetChildCommentCount() + c = nil + c.GetChildCommentCount() +} + +func TestCommentDiscussion_GetCreatedAt(tt *testing.T) { + var zeroValue Timestamp + c := &CommentDiscussion{CreatedAt: &zeroValue} + c.GetCreatedAt() + c = &CommentDiscussion{} + c.GetCreatedAt() + c = nil + c.GetCreatedAt() +} + +func TestCommentDiscussion_GetDiscussionID(tt *testing.T) { + var zeroValue int64 + c := &CommentDiscussion{DiscussionID: &zeroValue} + c.GetDiscussionID() + c = &CommentDiscussion{} + c.GetDiscussionID() + c = nil + c.GetDiscussionID() +} + +func TestCommentDiscussion_GetHTMLURL(tt *testing.T) { + var zeroValue string + c := &CommentDiscussion{HTMLURL: &zeroValue} + c.GetHTMLURL() + c = &CommentDiscussion{} + c.GetHTMLURL() + c = nil + c.GetHTMLURL() +} + +func TestCommentDiscussion_GetID(tt *testing.T) { + var zeroValue int64 + c := &CommentDiscussion{ID: &zeroValue} + c.GetID() + c = &CommentDiscussion{} + c.GetID() + c = nil + c.GetID() +} + +func TestCommentDiscussion_GetNodeID(tt *testing.T) { + var zeroValue string + c := &CommentDiscussion{NodeID: &zeroValue} + c.GetNodeID() + c = &CommentDiscussion{} + c.GetNodeID() + c = nil + c.GetNodeID() +} + +func TestCommentDiscussion_GetParentID(tt *testing.T) { + var zeroValue int64 + c := &CommentDiscussion{ParentID: &zeroValue} + c.GetParentID() + c = &CommentDiscussion{} + c.GetParentID() + c = nil + c.GetParentID() +} + +func TestCommentDiscussion_GetReaction(tt *testing.T) { + c := &CommentDiscussion{} + c.GetReaction() + c = nil + c.GetReaction() +} + +func TestCommentDiscussion_GetRepositoryURL(tt *testing.T) { + var zeroValue string + c := &CommentDiscussion{RepositoryURL: &zeroValue} + c.GetRepositoryURL() + c = &CommentDiscussion{} + c.GetRepositoryURL() + c = nil + c.GetRepositoryURL() +} + +func TestCommentDiscussion_GetUpdatedAt(tt *testing.T) { + var zeroValue Timestamp + c := &CommentDiscussion{UpdatedAt: &zeroValue} + c.GetUpdatedAt() + c = &CommentDiscussion{} + c.GetUpdatedAt() + c = nil + c.GetUpdatedAt() +} + +func TestCommentDiscussion_GetUser(tt *testing.T) { + c := &CommentDiscussion{} + c.GetUser() + c = nil + c.GetUser() +} + func TestCommentStats_GetTotalCommitComments(tt *testing.T) { var zeroValue int c := &CommentStats{TotalCommitComments: &zeroValue} @@ -5921,6 +6045,58 @@ func TestDiscussionComment_GetURL(tt *testing.T) { d.GetURL() } +func TestDiscussionCommentEvent_GetAction(tt *testing.T) { + var zeroValue string + d := &DiscussionCommentEvent{Action: &zeroValue} + d.GetAction() + d = &DiscussionCommentEvent{} + d.GetAction() + d = nil + d.GetAction() +} + +func TestDiscussionCommentEvent_GetComment(tt *testing.T) { + d := &DiscussionCommentEvent{} + d.GetComment() + d = nil + d.GetComment() +} + +func TestDiscussionCommentEvent_GetDiscussion(tt *testing.T) { + d := &DiscussionCommentEvent{} + d.GetDiscussion() + d = nil + d.GetDiscussion() +} + +func TestDiscussionCommentEvent_GetInstallation(tt *testing.T) { + d := &DiscussionCommentEvent{} + d.GetInstallation() + d = nil + d.GetInstallation() +} + +func TestDiscussionCommentEvent_GetOrg(tt *testing.T) { + d := &DiscussionCommentEvent{} + d.GetOrg() + d = nil + d.GetOrg() +} + +func TestDiscussionCommentEvent_GetRepo(tt *testing.T) { + d := &DiscussionCommentEvent{} + d.GetRepo() + d = nil + d.GetRepo() +} + +func TestDiscussionCommentEvent_GetSender(tt *testing.T) { + d := &DiscussionCommentEvent{} + d.GetSender() + d = nil + d.GetSender() +} + func TestDiscussionEvent_GetAction(tt *testing.T) { var zeroValue string d := &DiscussionEvent{Action: &zeroValue} diff --git a/github/messages.go b/github/messages.go index ceac6d9bc40..c98addcb138 100644 --- a/github/messages.go +++ b/github/messages.go @@ -56,6 +56,7 @@ var ( "deployment": "DeploymentEvent", "deployment_status": "DeploymentStatusEvent", "discussion": "DiscussionEvent", + "discussion_comment": "DiscussionCommentEvent", "fork": "ForkEvent", "github_app_authorization": "GitHubAppAuthorizationEvent", "gollum": "GollumEvent", diff --git a/github/messages_test.go b/github/messages_test.go index 9819ddbe616..ab53ecbec7d 100644 --- a/github/messages_test.go +++ b/github/messages_test.go @@ -305,6 +305,10 @@ func TestParseWebHook(t *testing.T) { payload: &DeploymentStatusEvent{}, messageType: "deployment_status", }, + { + payload: &DiscussionCommentEvent{}, + messageType: "discussion_comment", + }, { payload: &DiscussionEvent{}, messageType: "discussion", diff --git a/github/repos_hooks_deliveries_test.go b/github/repos_hooks_deliveries_test.go index 44b0f89abb6..360db490ba4 100644 --- a/github/repos_hooks_deliveries_test.go +++ b/github/repos_hooks_deliveries_test.go @@ -153,6 +153,7 @@ var hookDeliveryPayloadTypeToStruct = map[string]interface{}{ "deploy_key": &DeployKeyEvent{}, "deployment": &DeploymentEvent{}, "deployment_status": &DeploymentStatusEvent{}, + "discussion_comment": &DiscussionCommentEvent{}, "discussion": &DiscussionEvent{}, "fork": &ForkEvent{}, "github_app_authorization": &GitHubAppAuthorizationEvent{}, From 23a17188d87fab146c97126b9ae3381be7c3ab4e Mon Sep 17 00:00:00 2001 From: Apurwa Jadhav Date: Sat, 25 Feb 2023 18:29:51 -0800 Subject: [PATCH 2/2] Ran go fmt to fix the lint error. Changed Reaction type to Reactions. --- github/event_types.go | 40 +++++++++++++-------------- github/event_types_test.go | 11 ++++---- github/github-accessors.go | 6 ++-- github/github-accessors_test.go | 6 ++-- github/messages.go | 2 +- github/messages_test.go | 2 +- github/repos_hooks_deliveries_test.go | 2 +- 7 files changed, 34 insertions(+), 35 deletions(-) diff --git a/github/event_types.go b/github/event_types.go index a83178ee0f9..598d98d48c3 100644 --- a/github/event_types.go +++ b/github/event_types.go @@ -196,30 +196,30 @@ type DeploymentStatusEvent struct { type DiscussionCommentEvent struct { // Action is the action that was performed on the comment. // Possible values are: "created", "edited", "deleted". ** check what all can be added - Action *string `json:"action,omitempty"` - Discussion *Discussion `json:"discussion,omitempty"` - Comment *CommentDiscussion `json:"comment,omitempty"` - Repo *Repository `json:"repository,omitempty"` - Org *Organization `json:"organization,omitempty"` - Sender *User `json:"sender,omitempty"` - Installation *Installation `json:"installation,omitempty"` + Action *string `json:"action,omitempty"` + Discussion *Discussion `json:"discussion,omitempty"` + Comment *CommentDiscussion `json:"comment,omitempty"` + Repo *Repository `json:"repository,omitempty"` + Org *Organization `json:"organization,omitempty"` + Sender *User `json:"sender,omitempty"` + Installation *Installation `json:"installation,omitempty"` } // CommentDiscussion represents a comment in a GitHub DiscussionCommentEvent. type CommentDiscussion struct { - AuthorAssociation *string `json:"author_association,omitempty"` - Body *string `json:"body,omitempty"` - ChildCommentCount *int `json:"child_comment_count,omitempty"` - CreatedAt *Timestamp `json:"created_at,omitempty"` - DiscussionID *int64 `json:"discussion_id,omitempty"` - HTMLURL *string `json:"html_url,omitempty"` - ID *int64 `json:"id,omitempty"` - NodeID *string `json:"node_id,omitempty"` - ParentID *int64 `json:"parent_id,omitempty"` - Reaction *Reactions `json:"reactions,omitempty"` - RepositoryURL *string `json:"repository_url,omitempty"` - UpdatedAt *Timestamp `json:"updated_at,omitempty"` - User *User `json:"user,omitempty"` + AuthorAssociation *string `json:"author_association,omitempty"` + Body *string `json:"body,omitempty"` + ChildCommentCount *int `json:"child_comment_count,omitempty"` + CreatedAt *Timestamp `json:"created_at,omitempty"` + DiscussionID *int64 `json:"discussion_id,omitempty"` + HTMLURL *string `json:"html_url,omitempty"` + ID *int64 `json:"id,omitempty"` + NodeID *string `json:"node_id,omitempty"` + ParentID *int64 `json:"parent_id,omitempty"` + Reactions *Reactions `json:"reactions,omitempty"` + RepositoryURL *string `json:"repository_url,omitempty"` + UpdatedAt *Timestamp `json:"updated_at,omitempty"` + User *User `json:"user,omitempty"` } // DiscussionEvent represents a webhook event for a discussion. diff --git a/github/event_types_test.go b/github/event_types_test.go index 16b3b4d09f5..7c84146f460 100644 --- a/github/event_types_test.go +++ b/github/event_types_test.go @@ -5751,10 +5751,10 @@ func TestDiscussionCommentEvent_Marshal(t *testing.T) { CreatedAt: &Timestamp{referenceTime}, DiscussionID: Int64(1), HTMLURL: String("hurl"), - ID: Int64(1), - NodeID: String("nid"), + ID: Int64(1), + NodeID: String("nid"), ParentID: Int64(1), - Reaction: &Reactions{ + Reactions: &Reactions{ TotalCount: Int(1), PlusOne: Int(1), MinusOne: Int(1), @@ -5766,8 +5766,8 @@ func TestDiscussionCommentEvent_Marshal(t *testing.T) { Eyes: Int(1), URL: String("url"), }, - RepositoryURL: String("rurl"), - UpdatedAt: &Timestamp{referenceTime}, + RepositoryURL: String("rurl"), + UpdatedAt: &Timestamp{referenceTime}, User: &User{ Login: String("l"), ID: Int64(1), @@ -6154,7 +6154,6 @@ func TestDiscussionCommentEvent_Marshal(t *testing.T) { testJSONMarshal(t, u, want) } - func TestDiscussionEvent_Marshal(t *testing.T) { testJSONMarshal(t, &DiscussionEvent{}, "{}") diff --git a/github/github-accessors.go b/github/github-accessors.go index 49cfef3ce22..eba1036f6c2 100644 --- a/github/github-accessors.go +++ b/github/github-accessors.go @@ -2926,12 +2926,12 @@ func (c *CommentDiscussion) GetParentID() int64 { return *c.ParentID } -// GetReaction returns the Reaction field. -func (c *CommentDiscussion) GetReaction() *Reactions { +// GetReactions returns the Reactions field. +func (c *CommentDiscussion) GetReactions() *Reactions { if c == nil { return nil } - return c.Reaction + return c.Reactions } // GetRepositoryURL returns the RepositoryURL field if it's non-nil, zero value otherwise. diff --git a/github/github-accessors_test.go b/github/github-accessors_test.go index cd7991afe66..044a45bd486 100644 --- a/github/github-accessors_test.go +++ b/github/github-accessors_test.go @@ -3463,11 +3463,11 @@ func TestCommentDiscussion_GetParentID(tt *testing.T) { c.GetParentID() } -func TestCommentDiscussion_GetReaction(tt *testing.T) { +func TestCommentDiscussion_GetReactions(tt *testing.T) { c := &CommentDiscussion{} - c.GetReaction() + c.GetReactions() c = nil - c.GetReaction() + c.GetReactions() } func TestCommentDiscussion_GetRepositoryURL(tt *testing.T) { diff --git a/github/messages.go b/github/messages.go index c98addcb138..0943b9e9870 100644 --- a/github/messages.go +++ b/github/messages.go @@ -56,7 +56,7 @@ var ( "deployment": "DeploymentEvent", "deployment_status": "DeploymentStatusEvent", "discussion": "DiscussionEvent", - "discussion_comment": "DiscussionCommentEvent", + "discussion_comment": "DiscussionCommentEvent", "fork": "ForkEvent", "github_app_authorization": "GitHubAppAuthorizationEvent", "gollum": "GollumEvent", diff --git a/github/messages_test.go b/github/messages_test.go index ab53ecbec7d..ee374104ce0 100644 --- a/github/messages_test.go +++ b/github/messages_test.go @@ -306,7 +306,7 @@ func TestParseWebHook(t *testing.T) { messageType: "deployment_status", }, { - payload: &DiscussionCommentEvent{}, + payload: &DiscussionCommentEvent{}, messageType: "discussion_comment", }, { diff --git a/github/repos_hooks_deliveries_test.go b/github/repos_hooks_deliveries_test.go index 360db490ba4..ef453996a90 100644 --- a/github/repos_hooks_deliveries_test.go +++ b/github/repos_hooks_deliveries_test.go @@ -153,7 +153,7 @@ var hookDeliveryPayloadTypeToStruct = map[string]interface{}{ "deploy_key": &DeployKeyEvent{}, "deployment": &DeploymentEvent{}, "deployment_status": &DeploymentStatusEvent{}, - "discussion_comment": &DiscussionCommentEvent{}, + "discussion_comment": &DiscussionCommentEvent{}, "discussion": &DiscussionEvent{}, "fork": &ForkEvent{}, "github_app_authorization": &GitHubAppAuthorizationEvent{},