Skip to content

Commit 5b30e46

Browse files
authored
Add payload for discussion_comment event (#1781)
1 parent fa675f3 commit 5b30e46

File tree

4 files changed

+428
-2
lines changed

4 files changed

+428
-2
lines changed

src/main/java/org/kohsuke/github/GHEventPayload.java

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1639,8 +1639,8 @@ public GHLabelChanges getChanges() {
16391639
}
16401640

16411641
/**
1642-
* A discussion was created, edited, deleted, pinned, unpinned, locked, unlocked, transferred, category_changed,
1643-
* answered, or unanswered.
1642+
* A discussion was closed, reopened, created, edited, deleted, pinned, unpinned, locked, unlocked, transferred,
1643+
* category_changed, answered, or unanswered.
16441644
*
16451645
* @see <a href=
16461646
* "https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#discussion">
@@ -1673,6 +1673,40 @@ public GHLabel getLabel() {
16731673
}
16741674
}
16751675

1676+
/**
1677+
* A discussion comment was created, deleted, or edited.
1678+
*
1679+
* @see <a href=
1680+
* "https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#discussion_comment">
1681+
* discussion event</a>
1682+
*/
1683+
public static class DiscussionComment extends GHEventPayload {
1684+
1685+
private GHRepositoryDiscussion discussion;
1686+
1687+
private GHRepositoryDiscussionComment comment;
1688+
1689+
/**
1690+
* Gets discussion.
1691+
*
1692+
* @return the discussion
1693+
*/
1694+
@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected")
1695+
public GHRepositoryDiscussion getDiscussion() {
1696+
return discussion;
1697+
}
1698+
1699+
/**
1700+
* Gets discussion comment.
1701+
*
1702+
* @return the discussion
1703+
*/
1704+
@SuppressFBWarnings(value = { "EI_EXPOSE_REP" }, justification = "Expected")
1705+
public GHRepositoryDiscussionComment getComment() {
1706+
return comment;
1707+
}
1708+
}
1709+
16761710
/**
16771711
* A star was created or deleted on a repository.
16781712
*
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
package org.kohsuke.github;
2+
3+
import java.io.IOException;
4+
import java.net.URL;
5+
6+
/**
7+
* A discussion comment in the repository.
8+
* <p>
9+
* This is different from Teams discussions (see {@link GHDiscussion}).
10+
* <p>
11+
* The discussion_comment event exposes the GraphQL object (more or less - the ids are handled differently for instance)
12+
* directly. The new Discussions API is only available through GraphQL so for now you cannot execute any actions on this
13+
* object.
14+
*
15+
* @author Guillaume Smet
16+
* @see <a href="https://docs.github.com/en/graphql/guides/using-the-graphql-api-for-discussions#discussion">The GraphQL
17+
* API for Discussions</a>
18+
*/
19+
public class GHRepositoryDiscussionComment extends GHObject {
20+
21+
private String htmlUrl;
22+
23+
private Long parentId;
24+
private int childCommentCount;
25+
26+
private GHUser user;
27+
private GHCommentAuthorAssociation authorAssociation;
28+
private String body;
29+
30+
/**
31+
* Gets the html url.
32+
*
33+
* @return the html url
34+
*/
35+
public URL getHtmlUrl() {
36+
return GitHubClient.parseURL(htmlUrl);
37+
}
38+
39+
/**
40+
* Gets the parent comment id.
41+
*
42+
* @return the parent comment id
43+
*/
44+
public Long getParentId() {
45+
return parentId;
46+
}
47+
48+
/**
49+
* Gets the number of child comments.
50+
*
51+
* @return the number of child comments
52+
*/
53+
public int getChildCommentCount() {
54+
return childCommentCount;
55+
}
56+
57+
/**
58+
* Gets the user.
59+
*
60+
* @return the user
61+
* @throws IOException
62+
* Signals that an I/O exception has occurred.
63+
*/
64+
public GHUser getUser() throws IOException {
65+
return root().intern(user);
66+
}
67+
68+
/**
69+
* Gets the author association.
70+
*
71+
* @return the author association
72+
*/
73+
public GHCommentAuthorAssociation getAuthorAssociation() {
74+
return authorAssociation;
75+
}
76+
77+
/**
78+
* Gets the body.
79+
*
80+
* @return the body
81+
*/
82+
public String getBody() {
83+
return body;
84+
}
85+
}

src/test/java/org/kohsuke/github/GHEventPayloadTest.java

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1423,6 +1423,76 @@ public void discussion_labeled() throws Exception {
14231423
assertThat(label.getDescription(), is(nullValue()));
14241424
}
14251425

1426+
/**
1427+
* Discussion comment created.
1428+
*
1429+
* @throws Exception
1430+
* the exception
1431+
*/
1432+
@Test
1433+
public void discussion_comment_created() throws Exception {
1434+
final GHEventPayload.DiscussionComment discussionCommentPayload = GitHub.offline()
1435+
.parseEventPayload(payload.asReader(), GHEventPayload.DiscussionComment.class);
1436+
1437+
assertThat(discussionCommentPayload.getAction(), is("created"));
1438+
assertThat(discussionCommentPayload.getRepository().getFullName(), is("gsmet/quarkus-bot-java-playground"));
1439+
assertThat(discussionCommentPayload.getSender().getLogin(), is("gsmet"));
1440+
1441+
GHRepositoryDiscussion discussion = discussionCommentPayload.getDiscussion();
1442+
1443+
GHRepositoryDiscussion.Category category = discussion.getCategory();
1444+
1445+
assertThat(category.getId(), is(33522033L));
1446+
assertThat(category.getNodeId(), is("DIC_kwDOEq3cwc4B_4Fx"));
1447+
assertThat(category.getEmoji(), is(":pray:"));
1448+
assertThat(category.getName(), is("Q&A"));
1449+
assertThat(category.getDescription(), is("Ask the community for help"));
1450+
assertThat(category.getCreatedAt().getTime(), is(1636991431000L));
1451+
assertThat(category.getUpdatedAt().getTime(), is(1636991431000L));
1452+
assertThat(category.getSlug(), is("q-a"));
1453+
assertThat(category.isAnswerable(), is(true));
1454+
1455+
assertThat(discussion.getAnswerHtmlUrl(), is(nullValue()));
1456+
assertThat(discussion.getAnswerChosenAt(), is(nullValue()));
1457+
assertThat(discussion.getAnswerChosenBy(), is(nullValue()));
1458+
1459+
assertThat(discussion.getHtmlUrl().toString(),
1460+
is("https://github.com/gsmet/quarkus-bot-java-playground/discussions/162"));
1461+
assertThat(discussion.getId(), is(6090566L));
1462+
assertThat(discussion.getNodeId(), is("D_kwDOEq3cwc4AXO9G"));
1463+
assertThat(discussion.getNumber(), is(162));
1464+
assertThat(discussion.getTitle(), is("New test question"));
1465+
1466+
assertThat(discussion.getUser().getLogin(), is("gsmet"));
1467+
assertThat(discussion.getUser().getId(), is(1279749L));
1468+
assertThat(discussion.getUser().getNodeId(), is("MDQ6VXNlcjEyNzk3NDk="));
1469+
1470+
assertThat(discussion.getState(), is(GHRepositoryDiscussion.State.OPEN));
1471+
assertThat(discussion.isLocked(), is(false));
1472+
assertThat(discussion.getComments(), is(1));
1473+
assertThat(discussion.getCreatedAt().getTime(), is(1705586390000L));
1474+
assertThat(discussion.getUpdatedAt().getTime(), is(1705586399000L));
1475+
assertThat(discussion.getAuthorAssociation(), is(GHCommentAuthorAssociation.OWNER));
1476+
assertThat(discussion.getActiveLockReason(), is(nullValue()));
1477+
assertThat(discussion.getBody(), is("Test question"));
1478+
1479+
GHRepositoryDiscussionComment comment = discussionCommentPayload.getComment();
1480+
1481+
assertThat(comment.getHtmlUrl().toString(),
1482+
is("https://github.com/gsmet/quarkus-bot-java-playground/discussions/162#discussioncomment-8169669"));
1483+
assertThat(comment.getId(), is(8169669L));
1484+
assertThat(comment.getNodeId(), is("DC_kwDOEq3cwc4AfKjF"));
1485+
assertThat(comment.getAuthorAssociation(), is(GHCommentAuthorAssociation.OWNER));
1486+
assertThat(comment.getCreatedAt().getTime(), is(1705586398000L));
1487+
assertThat(comment.getUpdatedAt().getTime(), is(1705586399000L));
1488+
assertThat(comment.getBody(), is("Test comment."));
1489+
assertThat(comment.getUser().getLogin(), is("gsmet"));
1490+
assertThat(comment.getUser().getId(), is(1279749L));
1491+
assertThat(comment.getUser().getNodeId(), is("MDQ6VXNlcjEyNzk3NDk="));
1492+
assertThat(comment.getParentId(), is(nullValue()));
1493+
assertThat(comment.getChildCommentCount(), is(0));
1494+
}
1495+
14261496
/**
14271497
* Starred.
14281498
*

0 commit comments

Comments
 (0)