Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ wildfly:
message: Wrong content of the PR title
description: # 3
regexes:
- pattern: JIRA:\s+https://issues.redhat.com/browse/WFLY-\d+|https://issues.redhat.com/browse/WFLY-\d+
- pattern: JIRA:\s+https://redhat.atlassian.net/browse/WFLY-\d+|https://redhat.atlassian.net/browse/WFLY-\d+
message: The PR description must contain a link to the JIRA issue # 4
emails: # 5
- foo@bar.baz
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/org/wildfly/bot/model/RuntimeConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,13 @@ public class RuntimeConstants {

public static final String BOT_JIRA_LINKS_HEADER = "Additional WildFly Issue Links Found:\n";

public static final String BOT_JIRA_LINK_TEMPLATE = "https://issues.redhat.com/browse/%1$s";
// Kept for backward compatibility, should be removed when the link stops
// working, for more info see
// https://github.com/wildfly/wildfly-github-bot/issues/238
@Deprecated
public static final String BOT_JIRA_OLD_LINK_TEMPLATE = "https://issues.redhat.com/browse/%1$s";

public static final String BOT_JIRA_LINK_TEMPLATE = "https://redhat.atlassian.net/browse/%1$s";

public static final String BOT_JIRA_LINK_COMMENT_TEMPLATE = String.format("* [%%1$s](%s)\n", BOT_JIRA_LINK_TEMPLATE);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static org.wildfly.bot.model.RuntimeConstants.BOT_JIRA_LINKS_HEADER;
import static org.wildfly.bot.model.RuntimeConstants.BOT_JIRA_LINK_COMMENT_TEMPLATE;
import static org.wildfly.bot.model.RuntimeConstants.BOT_JIRA_LINK_TEMPLATE;
import static org.wildfly.bot.model.RuntimeConstants.BOT_JIRA_OLD_LINK_TEMPLATE;
import static org.wildfly.bot.model.RuntimeConstants.BOT_MESSAGE_DELIMITER;
import static org.wildfly.bot.model.RuntimeConstants.BOT_MESSAGE_WARNING;
import static org.wildfly.bot.model.RuntimeConstants.BOT_REPO_REF_FOOTER;
Expand Down Expand Up @@ -65,7 +66,8 @@ public PullRequestDescriptionHandler(GHPullRequest pullRequest, Pattern issueKey
this.missingIssueLinksWithinUserBody = textSources.stream()
.flatMap(text -> issueKeyPattern.matcher(text).results().map(MatchResult::group))
.distinct()
.filter(issueKey -> !userBody.contains(BOT_JIRA_LINK_TEMPLATE.formatted(issueKey)))
.filter(issueKey -> !userBody.contains(BOT_JIRA_LINK_TEMPLATE.formatted(issueKey))
&& !userBody.contains(BOT_JIRA_OLD_LINK_TEMPLATE.formatted(issueKey)))
.collect(Collectors.toCollection(LinkedHashSet::new));
}

Expand Down
97 changes: 77 additions & 20 deletions src/test/java/org/wildfly/bot/PRAppendingMessageTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,8 @@ void testBodyContainingSomeJirasAppendMessageMultipleDifferentLinks() throws Thr
should not be

cleared.
Here is one jira for you https://issues.redhat.com/browse/WFLY-00002
and here is another one https://issues.redhat.com/browse/WFLY-00003
Here is one jira for you https://redhat.atlassian.net/browse/WFLY-00002
and here is another one https://redhat.atlassian.net/browse/WFLY-00003
""";

final String expectedDescriptionToBeChangedByBot = constructFullDescription(userBodySection,
Expand Down Expand Up @@ -164,9 +164,9 @@ void testBodyContainingAllJirasAppendMessageMultipleDifferentLinks() throws Thro
cleared.

Listing all jiras:
https://issues.redhat.com/browse/WFLY-00001
https://issues.redhat.com/browse/WFLY-00002
https://issues.redhat.com/browse/WFLY-00003
https://redhat.atlassian.net/browse/WFLY-00001
https://redhat.atlassian.net/browse/WFLY-00002
https://redhat.atlassian.net/browse/WFLY-00003
""";

pullRequestJson = TestModel.setPullRequestJsonBuilder(pullRequestJsonBuilder -> pullRequestJsonBuilder
Expand All @@ -189,7 +189,7 @@ void testBodyContainingAllJirasAppendMessageMultipleDifferentLinks() throws Thro
void testBotChangingBotSectionUponUserCorrectedSomeIssueLinks() throws Throwable {
final String userBodySection = """
This user body section has been corrected and here is the issue link:
https://issues.redhat.com/browse/WFLY-00002
https://redhat.atlassian.net/browse/WFLY-00002
""";
final String descriptionToBeChangedByBot = constructFullDescription(userBodySection,
List.of("WFLY-00000", "WFLY-00001", "WFLY-00002",
Expand Down Expand Up @@ -220,14 +220,14 @@ void testBotChangingBotSectionUponUserCorrectedSomeIssueLinks() throws Throwable
void testBotDeletingBotSectionUponUserCorrectedIssueLinks() throws Throwable {
final String userBodySection = """
This user body section has been corrected and here are the issue links:
https://issues.redhat.com/browse/WFLY-00000
https://issues.redhat.com/browse/WFLY-00001
https://redhat.atlassian.net/browse/WFLY-00000
https://redhat.atlassian.net/browse/WFLY-00001

____

https://issues.redhat.com/browse/WFLY-00002
https://issues.redhat.com/browse/WFLY-00003
https://issues.redhat.com/browse/WFLY-00004
https://redhat.atlassian.net/browse/WFLY-00002
https://redhat.atlassian.net/browse/WFLY-00003
https://redhat.atlassian.net/browse/WFLY-00004
""";
final String descriptionToBeChangedByBot = constructFullDescription(userBodySection,
List.of("WFLY-00000", "WFLY-00001", "WFLY-00002",
Expand Down Expand Up @@ -258,8 +258,8 @@ void testBotDeletingBotSectionUponUserCorrectedIssueLinks() throws Throwable {
void testEditingTitleToContainMissingIssueLink() throws Throwable {
final String userBodySection = """
This is my user section body with WFLY-00000 and WFLY-00001 issue links.
https://issues.redhat.com/browse/WFLY-00001
https://issues.redhat.com/browse/WFLY-00002
https://redhat.atlassian.net/browse/WFLY-00001
https://redhat.atlassian.net/browse/WFLY-00002
""";

final String originalBodyBeforeTheEdit = constructFullDescription(userBodySection, List.of("WFLY-00003"));
Expand Down Expand Up @@ -333,21 +333,21 @@ void testDescriptionIsModifiedByBotIfBotSectionIsIncorrect() throws Throwable {
@Test
void testNonBreakingChangesWithThePreviousAppendMessageFormat() throws Throwable {
final String oldBody = """
https://issues.redhat.com/browse/WFLY-20743
https://redhat.atlassian.net/browse/WFLY-20743

____

<--- THIS SECTION IS AUTOMATICALLY GENERATED BY WILDFLY GITHUB BOT. ANY MANUAL CHANGES WILL BE LOST. --->

> WildFly issue links:

> * [WFLY-20730] (https://issues.redhat.com/browse/WFLY-20730)
> * [WFLY-20730] (https://redhat.atlassian.net/browse/WFLY-20730)

<--- END OF WILDFLY GITHUB BOT REPORT --->

More information about the [wildfly-bot](https://github.com/wildfly/wildfly-bot)""";

final String expectedNewBody = constructFullDescription("https://issues.redhat.com/browse/WFLY-20743",
final String expectedNewBody = constructFullDescription("https://redhat.atlassian.net/browse/WFLY-20743",
List.of("WFLY-20730"));

pullRequestJson = TestModel.setPullRequestJsonBuilder(pullRequestJsonBuilder -> pullRequestJsonBuilder
Expand Down Expand Up @@ -404,8 +404,8 @@ void testSequencedCommitsWithoutUserManualyEditingDescription() throws Throwable
@Test
void testBotChangingBotSectionUponUserFixupsCommitWithMissingIssueLink() throws Throwable {
final String userBodySection = """
This is my user section body with one WFLY issue link:
https://issues.redhat.com/browse/WFLY-00001
This is my user section body with one WFLY issue link:
https://redhat.atlassian.net/browse/WFLY-00001
""";

final String fullDescriptionBeforeTheFixup = constructFullDescription(userBodySection, List.of("WFLY-00002"));
Expand Down Expand Up @@ -444,8 +444,8 @@ void testBotChangingBotSectionUponUserFixupsCommitWithMissingIssueLink() throws
void testBotChangingBotSectionUponUserRewordingCommit() throws Throwable {
final String userBodySection = """
This is my user section body with two WFLY issue links:
https://issues.redhat.com/browse/WFLY-00001
https://issues.redhat.com/browse/WFLY-00003
https://redhat.atlassian.net/browse/WFLY-00001
https://redhat.atlassian.net/browse/WFLY-00003
""";
final String fullDescriptionBeforeTheReword = constructFullDescription(userBodySection, List.of("WFLY-00002"));

Expand Down Expand Up @@ -479,6 +479,59 @@ void testBotChangingBotSectionUponUserRewordingCommit() throws Throwable {
.setBody(userBodySection)); // bot section should be removed
}

@Test
void testBackwardCompatibilityOldLinkInUserSectionNoBot() throws Throwable {
final String userBodySection = """
This PR fixes the following issue:
https://issues.redhat.com/browse/WFLY-00000

Additional fixes:
https://issues.redhat.com/browse/WFLY-00001
""";

pullRequestJson = TestModel.setPullRequestJsonBuilder(pullRequestJsonBuilder -> pullRequestJsonBuilder
.action(Action.EDITED)
.title("[WFLY-00000, WFLY-00001] title")
.description(userBodySection));

mockedContext = MockedGHPullRequest.builder(pullRequestJson.id())
.commit("WFLY-00000 commit")
.commit("WFLY-00001 commit");

TestModel.given(
mocks -> WildflyGitHubBotTesting.mockRepo(mocks, WILDFLY_CONFIG_FILE, pullRequestJson,
mockedContext))
.pullRequestEvent(pullRequestJson)
// Old links should be recognized as valid, so no bot section should be added
.then(mocks -> verify(mocks.pullRequest(pullRequestJson.id()), never()).setBody(any()));
}

@Test
void testBackwardCompatibilityBotSectionHasOldLinksGetsUpdated() throws Throwable {
final String userBodySection = "This is my user section body without any WFLY issue links.";
final String expectedNewDescription = constructFullDescription(userBodySection,
List.of("WFLY-00000"));
final String oldDescription = userBodySection + convertNewLinksToOldLinks(
expectedNewDescription.substring(userBodySection.length()));

pullRequestJson = TestModel.setPullRequestJsonBuilder(pullRequestJsonBuilder -> pullRequestJsonBuilder
.action(Action.EDITED)
.title("[WFLY-00000] title")
.description(oldDescription));

mockedContext = MockedGHPullRequest.builder(pullRequestJson.id())
.commit("WFLY-00000 commit");

TestModel.given(
mocks -> WildflyGitHubBotTesting.mockRepo(mocks, WILDFLY_CONFIG_FILE, pullRequestJson,
mockedContext))
.pullRequestEvent(pullRequestJson)
// Bot should regenerate bot section with both old and new issues using new link
// format
.then(mocks -> verify(mocks.pullRequest(pullRequestJson.id()))
.setBody(expectedNewDescription));
}

private String constructFullDescription(String userBodySection, SequencedCollection<String> botAddedIssueKeys) {
userBodySection = userBodySection == null ? "" : userBodySection;
String issueLinks = botAddedIssueKeys.stream()
Expand All @@ -487,4 +540,8 @@ private String constructFullDescription(String userBodySection, SequencedCollect
return userBodySection + incompleteBotSectionDescription.formatted(issueLinks,
BOT_REPO_REF_FOOTER.formatted(botContextProvider.getBotName()));
}

private String convertNewLinksToOldLinks(String description) {
return description.replace("https://redhat.atlassian.net/browse/", "https://issues.redhat.com/browse/");
}
}
14 changes: 7 additions & 7 deletions src/test/java/org/wildfly/bot/PRChecksTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,13 +65,13 @@ void testAllChecksPass() throws Throwable {
title: "Title"
notify: [Tadpole]
- id: "Description"
body: "issues.redhat.com"
body: "redhat.atlassian.net"
notify: [Butterfly]
format:
description:
regexes:
- pattern: "JIRA:\\\\s+https://issues.redhat.com/browse/WFLY-\\\\d+|https://issues.redhat.com/browse/WFLY-\\\\d+"
message: "The PR description must contain a link to the JIRA issue"
regexes:
- pattern: "JIRA:\\\\s+https://redhat.atlassian.net/browse/WFLY-\\\\d+|https://redhat.atlassian.net/browse/WFLY-\\\\d+"
message: "The PR description must contain a link to the JIRA issue"
""";
pullRequestJson = TestModel.getPullRequestJson();

Expand All @@ -98,9 +98,9 @@ void testAllChecksFail() throws Throwable {
notify: [Butterfly]
format:
description:
regexes:
- pattern: "JIRA:\\\\s+https://issues.redhat.com/browse/WFLY-\\\\d+|https://issues.redhat.com/browse/WFLY-\\\\d+"
message: "The PR description must contain a link to the JIRA issue"
regexes:
- pattern: "JIRA:\\\\s+https://redhat.atlassian.net/browse/WFLY-\\\\d+|https://redhat.atlassian.net/browse/WFLY-\\\\d+"
message: "The PR description must contain a link to the JIRA issue"
""";
pullRequestJson = TestModel.setPullRequestJsonBuilder(
pullRequestJsonBuilder -> pullRequestJsonBuilder.title(TestConstants.INVALID_TITLE)
Expand Down
18 changes: 9 additions & 9 deletions src/test/java/org/wildfly/bot/PRDependabotTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ static void setPullRequestJson() throws Exception {
void testDependabotOnPREdited() throws Throwable {
wildflyConfigFile = """
wildfly:
format:
description:
regexes:
- pattern: "https://issues.redhat.com/browse/WFLY-\\\\d+"
message: "The PR description must contain a link to the JIRA issue"
format:
description:
regexes:
- pattern: "https://redhat.atlassian.net/browse/WFLY-\\\\d+"
message: "The PR description must contain a link to the JIRA issue"
""";

pullRequestJson = TestModel.setPullRequestJsonBuilder(pullRequestJsonBuilder -> pullRequestJsonBuilder
Expand All @@ -78,10 +78,10 @@ void testDependabotOnPREdited() throws Throwable {
void testDependabotFormatCheckSkipOnPROpened() throws Throwable {
wildflyConfigFile = """
wildfly:
format:
description:
regexes:
- pattern: "https://issues.redhat.com/browse/WFLY-\\\\d+"
format:
description:
regexes:
- pattern: "https://redhat.atlassian.net/browse/WFLY-\\\\d+"
""";

pullRequestJson = TestModel.setPullRequestJsonBuilder(pullRequestJsonBuilder -> pullRequestJsonBuilder
Expand Down
Loading