Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add payload for discussion_comment event #1781

Merged
merged 1 commit into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 36 additions & 2 deletions src/main/java/org/kohsuke/github/GHEventPayload.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href=
* "https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#discussion">
Expand Down Expand Up @@ -1673,6 +1673,40 @@ public GHLabel getLabel() {
}
}

/**
* A discussion comment was created, deleted, or edited.
*
* @see <a href=
* "https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#discussion_comment">
* discussion event</a>
*/
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.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package org.kohsuke.github;

import java.io.IOException;
import java.net.URL;

/**
* A discussion comment in the repository.
* <p>
* This is different from Teams discussions (see {@link GHDiscussion}).
* <p>
* 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 <a href="https://docs.github.com/en/graphql/guides/using-the-graphql-api-for-discussions#discussion">The GraphQL
* API for Discussions</a>
*/
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;
}
}
70 changes: 70 additions & 0 deletions src/test/java/org/kohsuke/github/GHEventPayloadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Loading