Skip to content

Commit

Permalink
#1262 handle only created comments from Github
Browse files Browse the repository at this point in the history
  • Loading branch information
amihaiemil committed Oct 30, 2021
1 parent 9d2dd94 commit cfe1fb2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 24 deletions.
2 changes: 1 addition & 1 deletion self-api/src/main/java/com/selfxdsd/api/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private Type(){}
/**
* Event for a comment.
*/
public static final String ISSUE_COMMENT = "issue_comment";
public static final String ISSUE_COMMENT = "comment_created";

/**
* Event for renaming a repo.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* @author Mihai Andronache (amihaiemil@gmail.com)
* @version $Id$
* @since 0.0.61
* @checkstyle CyclomaticComplexity (500 lines)
*/
final class GithubWebhookEvent implements Event {

Expand Down Expand Up @@ -87,6 +88,13 @@ public String type() {
} else {
resolved = type;
}
} else if ("issue_comment".equalsIgnoreCase(type)) {
final String act = event.getString("action");
if("created".equalsIgnoreCase(act)) {
resolved = Type.ISSUE_COMMENT;
} else {
resolved = type;
}
} else if("repository".equalsIgnoreCase(type)){
final String act = event.getString("action");
if("renamed".equalsIgnoreCase(act)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,29 +253,6 @@ public void returnsReopenedPullRequestType() {
);
}

/**
* GithubWebhookEvent can return label event type when
* an issue label is added, edited or deleted.
*/
@Test
public void returnsLabelType(){
final Project project = Mockito.mock(Project.class);
final Event event = new GithubWebhookEvent(
project, "label",
Json.createObjectBuilder()
.add("action", "created")
.add("label", Json.createObjectBuilder()
.add("name", "60min")
.build())
.build()
.toString()
);
MatcherAssert.assertThat(
event.type(),
Matchers.equalTo(Event.Type.LABEL)
);
}

/**
* GithubWebhookEvent can return its Issue.
*/
Expand Down Expand Up @@ -457,4 +434,20 @@ public void returnsNullCommitForNonPush() {
Matchers.nullValue()
);
}

/**
* GithubWebhookEvent can return the ISSUE_COMMENT type for a comment
* created action.
*/
@Test
public void returnsIssueCommentType() {
final Project project = Mockito.mock(Project.class);
final Event event = new GithubWebhookEvent(
project, "issue_comment", "{\"action\":\"created\"}"
);
MatcherAssert.assertThat(
event.type(),
Matchers.equalTo(Event.Type.ISSUE_COMMENT)
);
}
}

0 comments on commit cfe1fb2

Please sign in to comment.