-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
extract github pull request merge message
- Loading branch information
1 parent
0551549
commit a82560d
Showing
3 changed files
with
76 additions
and
0 deletions.
There are no files selected for viewing
23 changes: 23 additions & 0 deletions
23
src/main/java/cholog/discord/message/GithubPullRequestMergeMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
src/test/java/cholog/discord/message/GithubPullRequestMergeMessageTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
); | ||
} | ||
} |