Skip to content

Commit

Permalink
extract github pull request merge message
Browse files Browse the repository at this point in the history
  • Loading branch information
jaeyeonling committed Jul 10, 2024
1 parent 0551549 commit a82560d
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package cholog.discord.message;

import cholog.github.PullRequestUrl;

import java.util.Arrays;
import java.util.List;

public class GithubPullRequestMergeMessage {

private final String rawMessage;

public GithubPullRequestMergeMessage(final String rawMessage) {
this.rawMessage = rawMessage;
}

public List<PullRequestUrl> extractUrls() {
return Arrays.stream(rawMessage.split("\\s+"))
.map(String::trim)
.filter(it -> it.startsWith("http"))
.map(PullRequestUrl::new)
.toList();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ public void onEvent(final MessageReceivedEvent event) {
.map(String::trim)
.filter(it -> it.startsWith("http"))
.toList();
if (urls.isEmpty()) {
log.debug("No URLs found in message [message={}]", message);
return;
}

final var fails = new HashMap<String, String>();
for (final String url : urls) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
package cholog.discord.message;

import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertAll;

class GithubPullRequestMergeMessageTest {

@Test
void extractUrls_lastComment() {
final var message = new GithubPullRequestMergeMessage("""
https://github.com/next-step/java-lotto-clean-playground/pull/35
https://github.com/next-step/java-lotto-clean-playground/pull/37
https://github.com/next-step/java-lotto-clean-playground/pull/39
https://github.com/next-step/java-lotto-clean-playground/pull/40
머지 요청드립니다!""");

final var extractUrls = message.extractUrls();

assertAll(
() -> assertThat(extractUrls).hasSize(4),
() -> assertThat(extractUrls.getFirst().pullNumber()).isEqualTo(35),
() -> assertThat(extractUrls.getLast().pullNumber()).isEqualTo(40)
);
}

@Test
void extractUrls_firstComment() {
final var message = new GithubPullRequestMergeMessage("""
머지요청드립니다 (자동차) :chologe:\s
https://github.com/next-step/java-racingcar-simple-playground/pull/30
https://github.com/next-step/java-racingcar-simple-playground/pull/44
https://github.com/next-step/java-racingcar-simple-playground/pull/45
https://github.com/next-step/java-racingcar-simple-playground/pull/46
https://github.com/next-step/java-racingcar-simple-playground/pull/48
https://github.com/next-step/java-racingcar-simple-playground/pull/49
""");

final var extractUrls = message.extractUrls();

assertAll(
() -> assertThat(extractUrls).hasSize(6),
() -> assertThat(extractUrls.getFirst().pullNumber()).isEqualTo(30),
() -> assertThat(extractUrls.getLast().pullNumber()).isEqualTo(49)
);
}
}

0 comments on commit a82560d

Please sign in to comment.