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

#347 Add two properties for comment author name and email #348

Merged
merged 3 commits into from
Dec 28, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public class GitHubPRCause extends GitHubCause<GitHubPRCause> {

private String condRef;
private String state;
private String commentAuthorName;
private String commentAuthorEmail;
private String commentBody;
private String commentBodyMatch;

Expand Down Expand Up @@ -164,6 +166,8 @@ public GitHubPRCause(GitHubPRCause orig) {
withTriggerSenderName(orig.getTriggerSenderEmail());
withTriggerSenderEmail(orig.getTriggerSenderEmail());
withBody(orig.getBody());
withCommentAuthorName(orig.getCommentAuthorName());
withCommentAuthorEmail(orig.getCommentAuthorEmail());
withCommentBody(orig.getCommentBody());
withCommentBodyMatch(orig.getCommentBodyMatch());
withCommitAuthorName(orig.getCommitAuthorName());
Expand Down Expand Up @@ -282,6 +286,16 @@ public GitHubPRCause withCondRef(String condRef) {
return this;
}

public GitHubPRCause withCommentAuthorName(String commentAuthorName) {
this.commentAuthorName = commentAuthorName;
return this;
}

public GitHubPRCause withCommentAuthorEmail(String commentAuthorEmail) {
this.commentAuthorEmail = commentAuthorEmail;
return this;
}

public GitHubPRCause withCommentBody(String commentBody) {
this.commentBody = commentBody;
return this;
Expand Down Expand Up @@ -368,6 +382,20 @@ public String getCondRef() {
return condRef;
}

/**
* When trigger by comment, author of comment.
*/
public String getCommentAuthorName() {
return commentAuthorName;
}

/**
* When trigger by comment, author email of comment.
*/
public String getCommentAuthorEmail() {
return commentAuthorEmail;
}

/**
* When trigger by comment, body of comment.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ public enum GitHubPREnv implements GitHubEnv<GitHubPRCause> {
CAUSE_SKIP(GitHubPRCause::isSkip),
NUMBER((Function<GitHubPRCause, String>) c -> String.valueOf(c.getNumber())),
STATE(GitHubPRCause::getState),
COMMENT_AUTHOR_NAME(GitHubPRCause::getCommentAuthorName),
COMMENT_AUTHOR_EMAIL(GitHubPRCause::getCommentAuthorEmail),
COMMENT_BODY(GitHubPRCause::getCommentBody),
COMMENT_BODY_MATCH(GitHubPRCause::getCommentBodyMatch),
LABELS((Function<GitHubPRCause, String>) c -> String.join(",", c.getLabels()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ private GitHubPRCause checkComment(GitHubPRDecisionContext prDecisionContext,
LOG.trace("Event matches comment '{}'", body);
cause = prDecisionContext.newCause("Comment matches to criteria.", false);
cause.withCommentBody(body);
cause.withCommentAuthorName(issueComment.getUser().getName());
cause.withCommentAuthorEmail(issueComment.getUser().getEmail());
if (matcher.groupCount() > 0) {
cause.withCommentBodyMatch(matcher.group(1));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,12 @@
import static java.util.Collections.emptyList;
import static java.util.Collections.emptySet;
import static org.hamcrest.core.Is.is;
import static org.hamcrest.core.IsNull.notNullValue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Matchers.isNotNull;
import static org.mockito.Matchers.notNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

Expand Down Expand Up @@ -68,6 +67,10 @@ public class GitHubPRCommentEventTest {
@Mock
private GitHubPRTrigger trigger;

@Mock
private GHUser author;
@Mock
private GHUser author2;
@Mock
private GHIssueComment comment;
@Mock
Expand Down Expand Up @@ -118,6 +121,8 @@ public void testNullLocalCommentRemoteMatch() throws IOException {
.build()
);

assertEquals(cause.getCommentAuthorName(), "commentOwnerName");
assertEquals(cause.getCommentAuthorEmail(), "commentOwnerName@email.com");
assertThat(cause.getCommentBody(), is(body));
assertThat(cause.getCommentBodyMatch(), is("foo, bar"));
assertNotNull(cause);
Expand All @@ -135,8 +140,11 @@ public void firstCommentMatchSecondDont() throws IOException {
when(comment.getCreatedAt()).thenReturn(new Date());

final String body2 = "no matching in second comment";
when(comment2.getUser()).thenReturn(author2);
when(comment2.getBody()).thenReturn(body2);
when(comment2.getCreatedAt()).thenReturn(new Date());
when(author2.getName()).thenReturn("commentOwnerName2");
when(author2.getEmail()).thenReturn("commentOwner2@email.com");


final ArrayList<GHIssueComment> ghIssueComments = new ArrayList<>();
Expand All @@ -152,7 +160,11 @@ public void firstCommentMatchSecondDont() throws IOException {
.withListener(listener)
.build()
);
assertThat(cause, notNullValue());
assertEquals(cause.getCommentAuthorName(), "commentOwnerName");
assertEquals(cause.getCommentAuthorEmail(), "commentOwnerName@email.com");
assertNotEquals(cause.getCommentAuthorName(), "commentOwnerName2");
assertNotEquals(cause.getCommentAuthorEmail(), "commentOwner2@email.com");
Sapr0 marked this conversation as resolved.
Show resolved Hide resolved
assertNotNull(cause);
assertThat(cause.getCommentBody(), is(body));
assertThat(cause.getCommentBodyMatch(), is("foo, bar"));
}
Expand Down Expand Up @@ -196,6 +208,8 @@ public void testNullLocalPR() throws IOException {
.build()
); // localPR is null

assertEquals(cause.getCommentAuthorName(), "commentOwnerName");
assertEquals(cause.getCommentAuthorEmail(), "commentOwner@email.com");
assertThat(cause.getCommentBody(), is(body));
assertThat(cause.getCommentBodyMatch(), is("foo, bar"));
assertNotNull(cause);
Expand All @@ -209,6 +223,9 @@ private void commonExpectations(Set<String> localLabels) throws IOException {
when(repository.getIssue(anyInt())).thenReturn(issue);
when(repository.getOwnerName()).thenReturn("ownerName");
when(listener.getLogger()).thenReturn(logger);
when(comment.getUser()).thenReturn(author);
when(author.getName()).thenReturn("commentOwnerName");
when(author.getEmail()).thenReturn("commentOwner@email.com");
}

private void causeCreationExpectations() throws IOException {
Expand Down