-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Automatically generate JIRA issue links to Pull Request description b…
…ody.
- Loading branch information
1 parent
ffd0fce
commit c6880f5
Showing
17 changed files
with
551 additions
and
98 deletions.
There are no files selected for viewing
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
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
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
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
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
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
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
149 changes: 149 additions & 0 deletions
149
src/test/java/io/xstefank/wildfly/bot/PRAppendingMessage.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,149 @@ | ||
package io.xstefank.wildfly.bot; | ||
|
||
import io.quarkiverse.githubapp.testing.GitHubAppTest; | ||
import io.quarkus.test.junit.QuarkusTest; | ||
import io.xstefank.wildfly.bot.model.RuntimeConstants; | ||
import io.xstefank.wildfly.bot.utils.Action; | ||
import io.xstefank.wildfly.bot.utils.GitHubJson; | ||
import org.junit.jupiter.api.Test; | ||
import org.kohsuke.github.GHEvent; | ||
import org.mockito.Mockito; | ||
|
||
import java.io.IOException; | ||
|
||
import static io.quarkiverse.githubapp.testing.GitHubAppTesting.given; | ||
import static io.xstefank.wildfly.bot.helper.MockedGHPullRequestProcessor.mockCommits; | ||
import static io.xstefank.wildfly.bot.helper.MockedGHPullRequestProcessor.mockEmptyComments; | ||
import static io.xstefank.wildfly.bot.helper.MockedGHPullRequestProcessor.mockEmptyFileDetails; | ||
import static io.xstefank.wildfly.bot.helper.MockedGHPullRequestProcessor.processPullRequestMock; | ||
import static io.xstefank.wildfly.bot.util.Strings.blockQuoted; | ||
|
||
@QuarkusTest | ||
@GitHubAppTest | ||
public class PRAppendingMessage { | ||
|
||
private String wildflyConfigFile = """ | ||
wildfly: | ||
format: | ||
commit: | ||
enabled: false | ||
"""; | ||
|
||
private String appendedMessage = String.format(""" | ||
%s | ||
%s%%s%s""", RuntimeConstants.BOT_MESSAGE_HEADER, blockQuoted(RuntimeConstants.BOT_JIRA_LINKS_HEADER), RuntimeConstants.BOT_MESSAGE_FOOTER); | ||
|
||
@Test | ||
public void testEmptyBodyAppendMessage() throws IOException { | ||
GitHubJson githubJson = GitHubJson.builder("pr-template.json").action(Action.EDITED).title("WFLY-00000 title").body(null).build(); | ||
|
||
given().github(mocks -> { | ||
mocks.configFile(RuntimeConstants.CONFIG_FILE_NAME).fromString(wildflyConfigFile); | ||
processPullRequestMock(mocks.pullRequest(githubJson.pullRequest()), mockEmptyFileDetails(), mockEmptyComments(), mockCommits("WFLY-00000 commit")); | ||
}).when().payloadFromString(githubJson.jsonString()).event(GHEvent.PULL_REQUEST).then().github(mocks -> { | ||
StringBuilder sb = new StringBuilder(); | ||
Mockito.verify(mocks.pullRequest(githubJson.pullRequest())).setBody(String.format(appendedMessage, | ||
sb.append(blockQuoted(String.format(RuntimeConstants.BOT_JIRA_LINK_TEMPLATE, "WFLY-00000")).toString()))); | ||
}); | ||
|
||
} | ||
|
||
@Test | ||
public void testNonEmptyBodyAppendMessage() throws IOException { | ||
String body = """ | ||
This is my | ||
testing | ||
body, which | ||
should not be | ||
cleared."""; | ||
GitHubJson githubJson = GitHubJson.builder("pr-template.json").action(Action.EDITED).title("WFLY-00000 title").body(body).build(); | ||
|
||
given().github(mocks -> { | ||
mocks.configFile(RuntimeConstants.CONFIG_FILE_NAME).fromString(wildflyConfigFile); | ||
processPullRequestMock(mocks.pullRequest(githubJson.pullRequest()), mockEmptyFileDetails(), mockEmptyComments(), mockCommits("WFLY-00000 commit")); | ||
}).when().payloadFromString(githubJson.jsonString()).event(GHEvent.PULL_REQUEST).then().github(mocks -> { | ||
StringBuilder sb = new StringBuilder(); | ||
Mockito.verify(mocks.pullRequest(githubJson.pullRequest())).setBody(String.format(body + "\n\n" + appendedMessage, | ||
sb.append(blockQuoted(String.format(RuntimeConstants.BOT_JIRA_LINK_TEMPLATE, "WFLY-00000")).toString()))); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testEmptyBodyAppendMessageMultipleLinks() throws IOException { | ||
GitHubJson githubJson = GitHubJson.builder("pr-template.json").action(Action.EDITED).title("WFLY-00001 title").body(null).build(); | ||
|
||
given().github(mocks -> { | ||
mocks.configFile(RuntimeConstants.CONFIG_FILE_NAME).fromString(wildflyConfigFile); | ||
processPullRequestMock(mocks.pullRequest(githubJson.pullRequest()), mockEmptyFileDetails(), mockEmptyComments(), mockCommits("WFLY-00002 commit")); | ||
}).when().payloadFromString(githubJson.jsonString()).event(GHEvent.PULL_REQUEST).then().github(mocks -> { | ||
StringBuilder sb = new StringBuilder(); | ||
Mockito.verify(mocks.pullRequest(githubJson.pullRequest())).setBody(String.format(appendedMessage, | ||
sb.append(blockQuoted(String.format(RuntimeConstants.BOT_JIRA_LINK_TEMPLATE, "WFLY-00001"))) | ||
.append(blockQuoted(String.format(RuntimeConstants.BOT_JIRA_LINK_TEMPLATE, "WFLY-00002")).toString()))); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testNonEmptyBodyAppendMessageMultipleLinks() throws IOException { | ||
String body = """ | ||
This is my | ||
testing | ||
body, which | ||
should not be | ||
cleared."""; | ||
GitHubJson githubJson = GitHubJson.builder("pr-template.json").action(Action.EDITED).title("WFLY-00001 title").body(body).build(); | ||
|
||
given().github(mocks -> { | ||
mocks.configFile(RuntimeConstants.CONFIG_FILE_NAME).fromString(wildflyConfigFile); | ||
processPullRequestMock(mocks.pullRequest(githubJson.pullRequest()), mockEmptyFileDetails(), mockEmptyComments(), mockCommits("WFLY-00002 commit")); | ||
}).when().payloadFromString(githubJson.jsonString()).event(GHEvent.PULL_REQUEST).then().github(mocks -> { | ||
StringBuilder sb = new StringBuilder(); | ||
Mockito.verify(mocks.pullRequest(githubJson.pullRequest())).setBody(String.format(body + "\n\n" + appendedMessage, | ||
sb.append(blockQuoted(String.format(RuntimeConstants.BOT_JIRA_LINK_TEMPLATE, "WFLY-00001"))) | ||
.append(blockQuoted(String.format(RuntimeConstants.BOT_JIRA_LINK_TEMPLATE, "WFLY-00002")).toString()))); | ||
}); | ||
} | ||
|
||
@Test | ||
public void testEmptyBodyAppendMessageMultipleDifferentLinks() throws IOException { | ||
GitHubJson githubJson = GitHubJson.builder("pr-template.json").action(Action.EDITED).title("WFLY-00001, WFLY-00002 title").body(null).build(); | ||
|
||
given().github(mocks -> { | ||
mocks.configFile(RuntimeConstants.CONFIG_FILE_NAME).fromString(wildflyConfigFile); | ||
processPullRequestMock(mocks.pullRequest(githubJson.pullRequest()), mockEmptyFileDetails(), mockEmptyComments(), mockCommits("WFLY-00002 commit", "WFLY-00003 commit")); | ||
}).when().payloadFromString(githubJson.jsonString()).event(GHEvent.PULL_REQUEST).then().github(mocks -> { | ||
StringBuilder sb = new StringBuilder(); | ||
Mockito.verify(mocks.pullRequest(githubJson.pullRequest())).setBody(String.format(appendedMessage, | ||
sb.append(blockQuoted(String.format(RuntimeConstants.BOT_JIRA_LINK_TEMPLATE, "WFLY-00001"))) | ||
.append(blockQuoted(String.format(RuntimeConstants.BOT_JIRA_LINK_TEMPLATE, "WFLY-00002"))) | ||
.append(blockQuoted(String.format(RuntimeConstants.BOT_JIRA_LINK_TEMPLATE, "WFLY-00003")).toString()))); | ||
}); | ||
} | ||
|
||
|
||
@Test | ||
public void testNonEmptyBodyAppendMessageMultipleDifferentLinks() throws IOException { | ||
String body = """ | ||
This is my | ||
testing | ||
body, which | ||
should not be | ||
cleared."""; | ||
GitHubJson githubJson = GitHubJson.builder("pr-template.json").action(Action.EDITED).title("WFLY-00001, WFLY-00002 title").body(body).build(); | ||
|
||
given().github(mocks -> { | ||
mocks.configFile(RuntimeConstants.CONFIG_FILE_NAME).fromString(wildflyConfigFile); | ||
processPullRequestMock(mocks.pullRequest(githubJson.pullRequest()), mockEmptyFileDetails(), mockEmptyComments(), mockCommits("WFLY-00002 commit", "WFLY-00003 commit")); | ||
}).when().payloadFromString(githubJson.jsonString()).event(GHEvent.PULL_REQUEST).then().github(mocks -> { | ||
StringBuilder sb = new StringBuilder(); | ||
Mockito.verify(mocks.pullRequest(githubJson.pullRequest())).setBody(String.format(body + "\n\n" + appendedMessage, | ||
sb.append(blockQuoted(String.format(RuntimeConstants.BOT_JIRA_LINK_TEMPLATE, "WFLY-00001"))) | ||
.append(blockQuoted(String.format(RuntimeConstants.BOT_JIRA_LINK_TEMPLATE, "WFLY-00002"))) | ||
.append(blockQuoted(String.format(RuntimeConstants.BOT_JIRA_LINK_TEMPLATE, "WFLY-00003")).toString()))); | ||
}); | ||
} | ||
} |
Oops, something went wrong.