diff --git a/src/main/java/org/kohsuke/github/GHEventPayload.java b/src/main/java/org/kohsuke/github/GHEventPayload.java index b6549faadd..9413418af1 100644 --- a/src/main/java/org/kohsuke/github/GHEventPayload.java +++ b/src/main/java/org/kohsuke/github/GHEventPayload.java @@ -1639,8 +1639,8 @@ public GHLabelChanges getChanges() { } /** - * A discussion was created, edited, deleted, pinned, unpinned, locked, unlocked, transferred, category_changed, - * answered, or unanswered. + * A discussion was closed, reopened, created, edited, deleted, pinned, unpinned, locked, unlocked, transferred, + * category_changed, answered, or unanswered. * * @see @@ -1673,6 +1673,40 @@ public GHLabel getLabel() { } } + /** + * A discussion comment was created, deleted, or edited. + * + * @see + * discussion event + */ + public static class DiscussionComment extends GHEventPayload { + + private GHRepositoryDiscussion discussion; + + private GHRepositoryDiscussionComment comment; + + /** + * Gets discussion. + * + * @return the discussion + */ + @SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected") + public GHRepositoryDiscussion getDiscussion() { + return discussion; + } + + /** + * Gets discussion comment. + * + * @return the discussion + */ + @SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected") + public GHRepositoryDiscussionComment getComment() { + return comment; + } + } + /** * A star was created or deleted on a repository. * diff --git a/src/main/java/org/kohsuke/github/GHRepositoryDiscussionComment.java b/src/main/java/org/kohsuke/github/GHRepositoryDiscussionComment.java new file mode 100644 index 0000000000..e2dd604716 --- /dev/null +++ b/src/main/java/org/kohsuke/github/GHRepositoryDiscussionComment.java @@ -0,0 +1,85 @@ +package org.kohsuke.github; + +import java.io.IOException; +import java.net.URL; + +/** + * A discussion comment in the repository. + *

+ * This is different from Teams discussions (see {@link GHDiscussion}). + *

+ * The discussion_comment event exposes the GraphQL object (more or less - the ids are handled differently for instance) + * directly. The new Discussions API is only available through GraphQL so for now you cannot execute any actions on this + * object. + * + * @author Guillaume Smet + * @see The GraphQL + * API for Discussions + */ +public class GHRepositoryDiscussionComment extends GHObject { + + private String htmlUrl; + + private Long parentId; + private int childCommentCount; + + private GHUser user; + private GHCommentAuthorAssociation authorAssociation; + private String body; + + /** + * Gets the html url. + * + * @return the html url + */ + public URL getHtmlUrl() { + return GitHubClient.parseURL(htmlUrl); + } + + /** + * Gets the parent comment id. + * + * @return the parent comment id + */ + public Long getParentId() { + return parentId; + } + + /** + * Gets the number of child comments. + * + * @return the number of child comments + */ + public int getChildCommentCount() { + return childCommentCount; + } + + /** + * Gets the user. + * + * @return the user + * @throws IOException + * Signals that an I/O exception has occurred. + */ + public GHUser getUser() throws IOException { + return root().intern(user); + } + + /** + * Gets the author association. + * + * @return the author association + */ + public GHCommentAuthorAssociation getAuthorAssociation() { + return authorAssociation; + } + + /** + * Gets the body. + * + * @return the body + */ + public String getBody() { + return body; + } +} diff --git a/src/test/java/org/kohsuke/github/GHEventPayloadTest.java b/src/test/java/org/kohsuke/github/GHEventPayloadTest.java index 2400218a16..783fa06a6f 100644 --- a/src/test/java/org/kohsuke/github/GHEventPayloadTest.java +++ b/src/test/java/org/kohsuke/github/GHEventPayloadTest.java @@ -1423,6 +1423,76 @@ public void discussion_labeled() throws Exception { assertThat(label.getDescription(), is(nullValue())); } + /** + * Discussion comment created. + * + * @throws Exception + * the exception + */ + @Test + public void discussion_comment_created() throws Exception { + final GHEventPayload.DiscussionComment discussionCommentPayload = GitHub.offline() + .parseEventPayload(payload.asReader(), GHEventPayload.DiscussionComment.class); + + assertThat(discussionCommentPayload.getAction(), is("created")); + assertThat(discussionCommentPayload.getRepository().getFullName(), is("gsmet/quarkus-bot-java-playground")); + assertThat(discussionCommentPayload.getSender().getLogin(), is("gsmet")); + + GHRepositoryDiscussion discussion = discussionCommentPayload.getDiscussion(); + + GHRepositoryDiscussion.Category category = discussion.getCategory(); + + assertThat(category.getId(), is(33522033L)); + assertThat(category.getNodeId(), is("DIC_kwDOEq3cwc4B_4Fx")); + assertThat(category.getEmoji(), is(":pray:")); + assertThat(category.getName(), is("Q&A")); + assertThat(category.getDescription(), is("Ask the community for help")); + assertThat(category.getCreatedAt().getTime(), is(1636991431000L)); + assertThat(category.getUpdatedAt().getTime(), is(1636991431000L)); + assertThat(category.getSlug(), is("q-a")); + assertThat(category.isAnswerable(), is(true)); + + assertThat(discussion.getAnswerHtmlUrl(), is(nullValue())); + assertThat(discussion.getAnswerChosenAt(), is(nullValue())); + assertThat(discussion.getAnswerChosenBy(), is(nullValue())); + + assertThat(discussion.getHtmlUrl().toString(), + is("https://github.com/gsmet/quarkus-bot-java-playground/discussions/162")); + assertThat(discussion.getId(), is(6090566L)); + assertThat(discussion.getNodeId(), is("D_kwDOEq3cwc4AXO9G")); + assertThat(discussion.getNumber(), is(162)); + assertThat(discussion.getTitle(), is("New test question")); + + assertThat(discussion.getUser().getLogin(), is("gsmet")); + assertThat(discussion.getUser().getId(), is(1279749L)); + assertThat(discussion.getUser().getNodeId(), is("MDQ6VXNlcjEyNzk3NDk=")); + + assertThat(discussion.getState(), is(GHRepositoryDiscussion.State.OPEN)); + assertThat(discussion.isLocked(), is(false)); + assertThat(discussion.getComments(), is(1)); + assertThat(discussion.getCreatedAt().getTime(), is(1705586390000L)); + assertThat(discussion.getUpdatedAt().getTime(), is(1705586399000L)); + assertThat(discussion.getAuthorAssociation(), is(GHCommentAuthorAssociation.OWNER)); + assertThat(discussion.getActiveLockReason(), is(nullValue())); + assertThat(discussion.getBody(), is("Test question")); + + GHRepositoryDiscussionComment comment = discussionCommentPayload.getComment(); + + assertThat(comment.getHtmlUrl().toString(), + is("https://github.com/gsmet/quarkus-bot-java-playground/discussions/162#discussioncomment-8169669")); + assertThat(comment.getId(), is(8169669L)); + assertThat(comment.getNodeId(), is("DC_kwDOEq3cwc4AfKjF")); + assertThat(comment.getAuthorAssociation(), is(GHCommentAuthorAssociation.OWNER)); + assertThat(comment.getCreatedAt().getTime(), is(1705586398000L)); + assertThat(comment.getUpdatedAt().getTime(), is(1705586399000L)); + assertThat(comment.getBody(), is("Test comment.")); + assertThat(comment.getUser().getLogin(), is("gsmet")); + assertThat(comment.getUser().getId(), is(1279749L)); + assertThat(comment.getUser().getNodeId(), is("MDQ6VXNlcjEyNzk3NDk=")); + assertThat(comment.getParentId(), is(nullValue())); + assertThat(comment.getChildCommentCount(), is(0)); + } + /** * Starred. * diff --git a/src/test/resources/org/kohsuke/github/GHEventPayloadTest/discussion_comment_created.json b/src/test/resources/org/kohsuke/github/GHEventPayloadTest/discussion_comment_created.json new file mode 100644 index 0000000000..dbcffc7863 --- /dev/null +++ b/src/test/resources/org/kohsuke/github/GHEventPayloadTest/discussion_comment_created.json @@ -0,0 +1,237 @@ +{ + "action": "created", + "comment": { + "id": 8169669, + "node_id": "DC_kwDOEq3cwc4AfKjF", + "html_url": "https://github.com/gsmet/quarkus-bot-java-playground/discussions/162#discussioncomment-8169669", + "parent_id": null, + "child_comment_count": 0, + "repository_url": "gsmet/quarkus-bot-java-playground", + "discussion_id": 6090566, + "author_association": "OWNER", + "user": { + "login": "gsmet", + "id": 1279749, + "node_id": "MDQ6VXNlcjEyNzk3NDk=", + "avatar_url": "https://avatars.githubusercontent.com/u/1279749?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/gsmet", + "html_url": "https://github.com/gsmet", + "followers_url": "https://api.github.com/users/gsmet/followers", + "following_url": "https://api.github.com/users/gsmet/following{/other_user}", + "gists_url": "https://api.github.com/users/gsmet/gists{/gist_id}", + "starred_url": "https://api.github.com/users/gsmet/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/gsmet/subscriptions", + "organizations_url": "https://api.github.com/users/gsmet/orgs", + "repos_url": "https://api.github.com/users/gsmet/repos", + "events_url": "https://api.github.com/users/gsmet/events{/privacy}", + "received_events_url": "https://api.github.com/users/gsmet/received_events", + "type": "User", + "site_admin": false + }, + "created_at": "2024-01-18T13:59:58Z", + "updated_at": "2024-01-18T13:59:59Z", + "body": "Test comment.", + "reactions": { + "url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/issues/comments/8169669/reactions", + "total_count": 0, + "+1": 0, + "-1": 0, + "laugh": 0, + "hooray": 0, + "confused": 0, + "heart": 0, + "rocket": 0, + "eyes": 0 + } + }, + "discussion": { + "repository_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground", + "category": { + "id": 33522033, + "node_id": "DIC_kwDOEq3cwc4B_4Fx", + "repository_id": 313384129, + "emoji": ":pray:", + "name": "Q&A", + "description": "Ask the community for help", + "created_at": "2021-11-15T16:50:31.000+01:00", + "updated_at": "2021-11-15T16:50:31.000+01:00", + "slug": "q-a", + "is_answerable": true + }, + "answer_html_url": null, + "answer_chosen_at": null, + "answer_chosen_by": null, + "html_url": "https://github.com/gsmet/quarkus-bot-java-playground/discussions/162", + "id": 6090566, + "node_id": "D_kwDOEq3cwc4AXO9G", + "number": 162, + "title": "New test question", + "user": { + "login": "gsmet", + "id": 1279749, + "node_id": "MDQ6VXNlcjEyNzk3NDk=", + "avatar_url": "https://avatars.githubusercontent.com/u/1279749?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/gsmet", + "html_url": "https://github.com/gsmet", + "followers_url": "https://api.github.com/users/gsmet/followers", + "following_url": "https://api.github.com/users/gsmet/following{/other_user}", + "gists_url": "https://api.github.com/users/gsmet/gists{/gist_id}", + "starred_url": "https://api.github.com/users/gsmet/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/gsmet/subscriptions", + "organizations_url": "https://api.github.com/users/gsmet/orgs", + "repos_url": "https://api.github.com/users/gsmet/repos", + "events_url": "https://api.github.com/users/gsmet/events{/privacy}", + "received_events_url": "https://api.github.com/users/gsmet/received_events", + "type": "User", + "site_admin": false + }, + "state": "open", + "state_reason": null, + "locked": false, + "comments": 1, + "created_at": "2024-01-18T13:59:50Z", + "updated_at": "2024-01-18T13:59:59Z", + "author_association": "OWNER", + "active_lock_reason": null, + "body": "Test question", + "reactions": { + "url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/discussions/162/reactions", + "total_count": 0, + "+1": 0, + "-1": 0, + "laugh": 0, + "hooray": 0, + "confused": 0, + "heart": 0, + "rocket": 0, + "eyes": 0 + }, + "timeline_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/discussions/162/timeline" + }, + "repository": { + "id": 313384129, + "node_id": "MDEwOlJlcG9zaXRvcnkzMTMzODQxMjk=", + "name": "quarkus-bot-java-playground", + "full_name": "gsmet/quarkus-bot-java-playground", + "private": false, + "owner": { + "login": "gsmet", + "id": 1279749, + "node_id": "MDQ6VXNlcjEyNzk3NDk=", + "avatar_url": "https://avatars.githubusercontent.com/u/1279749?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/gsmet", + "html_url": "https://github.com/gsmet", + "followers_url": "https://api.github.com/users/gsmet/followers", + "following_url": "https://api.github.com/users/gsmet/following{/other_user}", + "gists_url": "https://api.github.com/users/gsmet/gists{/gist_id}", + "starred_url": "https://api.github.com/users/gsmet/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/gsmet/subscriptions", + "organizations_url": "https://api.github.com/users/gsmet/orgs", + "repos_url": "https://api.github.com/users/gsmet/repos", + "events_url": "https://api.github.com/users/gsmet/events{/privacy}", + "received_events_url": "https://api.github.com/users/gsmet/received_events", + "type": "User", + "site_admin": false + }, + "html_url": "https://github.com/gsmet/quarkus-bot-java-playground", + "description": null, + "fork": false, + "url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground", + "forks_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/forks", + "keys_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/keys{/key_id}", + "collaborators_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/collaborators{/collaborator}", + "teams_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/teams", + "hooks_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/hooks", + "issue_events_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/issues/events{/number}", + "events_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/events", + "assignees_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/assignees{/user}", + "branches_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/branches{/branch}", + "tags_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/tags", + "blobs_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/git/blobs{/sha}", + "git_tags_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/git/tags{/sha}", + "git_refs_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/git/refs{/sha}", + "trees_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/git/trees{/sha}", + "statuses_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/statuses/{sha}", + "languages_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/languages", + "stargazers_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/stargazers", + "contributors_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/contributors", + "subscribers_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/subscribers", + "subscription_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/subscription", + "commits_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/commits{/sha}", + "git_commits_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/git/commits{/sha}", + "comments_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/comments{/number}", + "issue_comment_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/issues/comments{/number}", + "contents_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/contents/{+path}", + "compare_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/compare/{base}...{head}", + "merges_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/merges", + "archive_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/{archive_format}{/ref}", + "downloads_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/downloads", + "issues_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/issues{/number}", + "pulls_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/pulls{/number}", + "milestones_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/milestones{/number}", + "notifications_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/notifications{?since,all,participating}", + "labels_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/labels{/name}", + "releases_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/releases{/id}", + "deployments_url": "https://api.github.com/repos/gsmet/quarkus-bot-java-playground/deployments", + "created_at": "2020-11-16T17:55:53Z", + "updated_at": "2022-05-31T17:24:36Z", + "pushed_at": "2023-11-16T15:25:35Z", + "git_url": "git://github.com/gsmet/quarkus-bot-java-playground.git", + "ssh_url": "git@github.com:gsmet/quarkus-bot-java-playground.git", + "clone_url": "https://github.com/gsmet/quarkus-bot-java-playground.git", + "svn_url": "https://github.com/gsmet/quarkus-bot-java-playground", + "homepage": null, + "size": 122, + "stargazers_count": 1, + "watchers_count": 1, + "language": "Java", + "has_issues": true, + "has_projects": true, + "has_downloads": true, + "has_wiki": true, + "has_pages": false, + "has_discussions": true, + "forks_count": 2, + "mirror_url": null, + "archived": false, + "disabled": false, + "open_issues_count": 6, + "license": null, + "allow_forking": true, + "is_template": false, + "web_commit_signoff_required": false, + "topics": [], + "visibility": "public", + "forks": 2, + "open_issues": 6, + "watchers": 1, + "default_branch": "main" + }, + "sender": { + "login": "gsmet", + "id": 1279749, + "node_id": "MDQ6VXNlcjEyNzk3NDk=", + "avatar_url": "https://avatars.githubusercontent.com/u/1279749?v=4", + "gravatar_id": "", + "url": "https://api.github.com/users/gsmet", + "html_url": "https://github.com/gsmet", + "followers_url": "https://api.github.com/users/gsmet/followers", + "following_url": "https://api.github.com/users/gsmet/following{/other_user}", + "gists_url": "https://api.github.com/users/gsmet/gists{/gist_id}", + "starred_url": "https://api.github.com/users/gsmet/starred{/owner}{/repo}", + "subscriptions_url": "https://api.github.com/users/gsmet/subscriptions", + "organizations_url": "https://api.github.com/users/gsmet/orgs", + "repos_url": "https://api.github.com/users/gsmet/repos", + "events_url": "https://api.github.com/users/gsmet/events{/privacy}", + "received_events_url": "https://api.github.com/users/gsmet/received_events", + "type": "User", + "site_admin": false + }, + "installation": { + "id": 13005535, + "node_id": "MDIzOkludGVncmF0aW9uSW5zdGFsbGF0aW9uMTMwMDU1MzU=" + } +} \ No newline at end of file