Skip to content

Commit

Permalink
Merge pull request #1264 from amihaiemil/1262
Browse files Browse the repository at this point in the history
#1262 handle only created comment from Github
  • Loading branch information
amihaiemil committed Oct 30, 2021
2 parents 9d2dd94 + 3c96674 commit 6c094af
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 28 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 NEW_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.NEW_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 @@ -106,7 +106,7 @@ public String type() {
).getString("noteable_type", "");
if("Issue".equalsIgnoreCase(noteableType)
|| "MergeRequest".equalsIgnoreCase(noteableType)) {
resolved = Type.ISSUE_COMMENT;
resolved = Type.NEW_COMMENT;
} else {
resolved = this.type;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public void resolve(final Event event) {
case Event.Type.ASSIGNED_TASKS:
this.projectManager.assignedTasks(event);
break;
case Event.Type.ISSUE_COMMENT:
case Event.Type.NEW_COMMENT:
this.projectManager.comment(event);
break;
case Event.Type.REPO_RENAMED:
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.NEW_COMMENT)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ public void typeIssueCommentForIssueComment() {
);
MatcherAssert.assertThat(
gitlabEvent.type(),
Matchers.equalTo(Event.Type.ISSUE_COMMENT)
Matchers.equalTo(Event.Type.NEW_COMMENT)
);
}

Expand All @@ -251,7 +251,7 @@ public void typeIssueCommentForMergeRequestComment() {
);
MatcherAssert.assertThat(
gitlabEvent.type(),
Matchers.equalTo(Event.Type.ISSUE_COMMENT)
Matchers.equalTo(Event.Type.NEW_COMMENT)
);
}

Expand Down

0 comments on commit 6c094af

Please sign in to comment.