From aabb352656103d5e50d16f8273b77cec87d1b356 Mon Sep 17 00:00:00 2001 From: nntthuy-axonivy Date: Thu, 12 Dec 2024 15:08:34 +0700 Subject: [PATCH 1/4] Fix regex get exact h2 name --- .../main/java/com/axonivy/market/util/ProductContentUtils.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/marketplace-service/src/main/java/com/axonivy/market/util/ProductContentUtils.java b/marketplace-service/src/main/java/com/axonivy/market/util/ProductContentUtils.java index 9a9e0b8c..9aa00d27 100644 --- a/marketplace-service/src/main/java/com/axonivy/market/util/ProductContentUtils.java +++ b/marketplace-service/src/main/java/com/axonivy/market/util/ProductContentUtils.java @@ -22,7 +22,7 @@ import static com.axonivy.market.constants.ProductJsonConstants.DEFAULT_PRODUCT_TYPE; public class ProductContentUtils { - public static final String DEMO_SETUP_TITLE = "(?i)## Demo|## Setup"; + public static final String DEMO_SETUP_TITLE = "(?m)^## (Demo|Setup)$"; private static final String HASH = "#"; public static final String DESCRIPTION = "description"; public static final String DEMO = "demo"; From 37c538f521319cbf8e1e52706101dfbca1641822 Mon Sep 17 00:00:00 2001 From: nntthuy-axonivy Date: Fri, 13 Dec 2024 08:33:17 +0700 Subject: [PATCH 2/4] Add unit test --- .../axonivy/market/util/ProductContentUtilsTest.java | 10 ++++++++++ marketplace-service/src/test/resources/README.md | 2 ++ 2 files changed, 12 insertions(+) diff --git a/marketplace-service/src/test/java/com/axonivy/market/util/ProductContentUtilsTest.java b/marketplace-service/src/test/java/com/axonivy/market/util/ProductContentUtilsTest.java index c302c66e..dac89bb7 100644 --- a/marketplace-service/src/test/java/com/axonivy/market/util/ProductContentUtilsTest.java +++ b/marketplace-service/src/test/java/com/axonivy/market/util/ProductContentUtilsTest.java @@ -114,6 +114,16 @@ void testGetExtractedPartsOfEmptyReadme() { assertTrue(StringUtils.isBlank(readmeContentsModel.getSetup())); } + @Test + void testGetExtractedPartsOfReadmeAtCorrectHeadings() { + String readmeContents = getMockReadmeContent(); + ReadmeContentsModel readmeContentsModel = ProductContentUtils.getExtractedPartsOfReadme(readmeContents); + assertTrue(readmeContentsModel.getDescription().startsWith("Axon Ivy’s mattermost connector")); + assertTrue(readmeContentsModel.getDemo().startsWith("### Demo sample")); + assertTrue(readmeContentsModel.getSetup().startsWith("### Setup guideline")); + + } + @Test void testHasImageDirectives() { String readmeContents = getMockReadmeContent(); diff --git a/marketplace-service/src/test/resources/README.md b/marketplace-service/src/test/resources/README.md index c86eea4e..c68b040e 100644 --- a/marketplace-service/src/test/resources/README.md +++ b/marketplace-service/src/test/resources/README.md @@ -12,6 +12,7 @@ This connector: ## Demo +### Demo sample 1. Hit the slash command key on the channel's chat. The Axon Ivy process will be triggered and create a new task. The task's information will be sent to the channel by a message. @@ -20,6 +21,7 @@ This connector: ## Setup +### Setup guideline Mattermost Instance 1. Ref to [Deploy Mattermost](https://docs.mattermost.com/guides/deployment.html). From 8c0d85da161b9f20c23fbf9f96930219801c7eaf Mon Sep 17 00:00:00 2001 From: nntthuy-axonivy Date: Mon, 16 Dec 2024 14:10:18 +0700 Subject: [PATCH 3/4] Fix general image regex for demo projects --- .../java/com/axonivy/market/util/ProductContentUtils.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/marketplace-service/src/main/java/com/axonivy/market/util/ProductContentUtils.java b/marketplace-service/src/main/java/com/axonivy/market/util/ProductContentUtils.java index 9aa00d27..0a117928 100644 --- a/marketplace-service/src/main/java/com/axonivy/market/util/ProductContentUtils.java +++ b/marketplace-service/src/main/java/com/axonivy/market/util/ProductContentUtils.java @@ -27,7 +27,7 @@ public class ProductContentUtils { public static final String DESCRIPTION = "description"; public static final String DEMO = "demo"; public static final String SETUP = "setup"; - public static final String README_IMAGE_FORMAT = "\\(([^)]*?/)?%s\\)"; + public static final String README_IMAGE_FORMAT = "\\(([^)]*?/)?%s(\\s+\"[^\"]+\")?\\)"; public static final String IMAGE_DOWNLOAD_URL_FORMAT = "(%s)"; private ProductContentUtils() { @@ -141,6 +141,11 @@ public static void updateProductModuleTabContents(ProductModuleContent productMo productModuleContent.setSetup(replaceEmptyContentsWithEnContent(moduleContents.get(SETUP))); } + /** + * Cover some inconsistent cases: + * Products contain image names in round brackets (employee-onboarding, demo-projects, etc.) + * Image with name contains in other images' (mattermost) + */ public static String replaceImageDirWithImageCustomId(Map imageUrls, String readmeContents) { for (Map.Entry entry : imageUrls.entrySet()) { String imagePattern = String.format(README_IMAGE_FORMAT, Pattern.quote(entry.getKey())); From 7a841a1b579e943478a661428bf3556feaef500b Mon Sep 17 00:00:00 2001 From: nntthuy-axonivy Date: Wed, 18 Dec 2024 16:13:50 +0700 Subject: [PATCH 4/4] Fix README regex + Update tests --- .../market/util/ProductContentUtils.java | 6 ++++- .../java/com/axonivy/market/BaseSetup.java | 1 + .../market/util/ProductContentUtilsTest.java | 27 ++++++++++++++++++- .../src/test/resources/README.md | 1 + 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/marketplace-service/src/main/java/com/axonivy/market/util/ProductContentUtils.java b/marketplace-service/src/main/java/com/axonivy/market/util/ProductContentUtils.java index 0a117928..a90e3be0 100644 --- a/marketplace-service/src/main/java/com/axonivy/market/util/ProductContentUtils.java +++ b/marketplace-service/src/main/java/com/axonivy/market/util/ProductContentUtils.java @@ -22,7 +22,11 @@ import static com.axonivy.market.constants.ProductJsonConstants.DEFAULT_PRODUCT_TYPE; public class ProductContentUtils { - public static final String DEMO_SETUP_TITLE = "(?m)^## (Demo|Setup)$"; + /* + * Accept any combination of #, can be ## or ###, and whitespaces before Demo/Setup word + * Match exactly Demo or Setup + */ + public static final String DEMO_SETUP_TITLE = "(?m)^[#\\s]*##?\\s*(Demo|Setup)\\s*$"; private static final String HASH = "#"; public static final String DESCRIPTION = "description"; public static final String DEMO = "demo"; diff --git a/marketplace-service/src/test/java/com/axonivy/market/BaseSetup.java b/marketplace-service/src/test/java/com/axonivy/market/BaseSetup.java index 0e494e82..adac142e 100644 --- a/marketplace-service/src/test/java/com/axonivy/market/BaseSetup.java +++ b/marketplace-service/src/test/java/com/axonivy/market/BaseSetup.java @@ -53,6 +53,7 @@ public class BaseSetup { protected static final String MOCK_PRODUCT_REPOSITORY_NAME = "axonivy-market/bpmn-statistic"; protected static final String MOCK_IMAGE_ID_FORMAT_1 = "imageId-66e2b14868f2f95b2f95549a"; protected static final String MOCK_IMAGE_ID_FORMAT_2 = "imageId-66e2b14868f2f95b2f95550a"; + protected static final String MOCK_IMAGE_ID_FORMAT_3 = "imageId-66e2b14868f2f95b2f95551a"; protected static final String MOCK_PRODUCT_JSON_FILE_PATH = "src/test/resources/product.json"; protected static final String MOCK_PRODUCT_JSON_FILE_PATH_NO_URL = "src/test/resources/productMissingURL.json"; protected static final String MOCK_PRODUCT_JSON_WITH_DROPINS_FILE_PATH = "src/test/resources/product-dropins.json"; diff --git a/marketplace-service/src/test/java/com/axonivy/market/util/ProductContentUtilsTest.java b/marketplace-service/src/test/java/com/axonivy/market/util/ProductContentUtilsTest.java index dac89bb7..b1199ede 100644 --- a/marketplace-service/src/test/java/com/axonivy/market/util/ProductContentUtilsTest.java +++ b/marketplace-service/src/test/java/com/axonivy/market/util/ProductContentUtilsTest.java @@ -50,10 +50,11 @@ void testReplaceImageDirWithImageCustomId() { Map imageUrls = new HashMap<>(); imageUrls.put("slash-command.png", MOCK_IMAGE_ID_FORMAT_1); imageUrls.put("create-slash-command.png", MOCK_IMAGE_ID_FORMAT_2); + imageUrls.put("screen2.png", MOCK_IMAGE_ID_FORMAT_3); String expectedResult = readmeContents.replace("images/slash-command.png", MOCK_IMAGE_ID_FORMAT_1).replace("images/create-slash-command.png", - MOCK_IMAGE_ID_FORMAT_2); + MOCK_IMAGE_ID_FORMAT_2).replace("screen2.png \"Restful Person Manager\"", MOCK_IMAGE_ID_FORMAT_3); String updatedContents = ProductContentUtils.replaceImageDirWithImageCustomId(imageUrls, readmeContents); assertEquals(expectedResult, updatedContents); @@ -121,7 +122,31 @@ void testGetExtractedPartsOfReadmeAtCorrectHeadings() { assertTrue(readmeContentsModel.getDescription().startsWith("Axon Ivy’s mattermost connector")); assertTrue(readmeContentsModel.getDemo().startsWith("### Demo sample")); assertTrue(readmeContentsModel.getSetup().startsWith("### Setup guideline")); + } + @Test + void testGetExtractedPartsOfReadmeWithInconsistentFormats() { + String readmeContentsWithHeading3 = """ + #Product-name + Test README + ### Setup + Setup content (./image.png)"""; + ReadmeContentsModel readmeContentsModel = ProductContentUtils.getExtractedPartsOfReadme(readmeContentsWithHeading3); + assertTrue(readmeContentsModel.getDescription().startsWith("Test README")); + assertTrue(readmeContentsModel.getSetup().startsWith("Setup content (./image.png)")); + + String readmeContentsWithSpaceHeading = """ + #Product-name + Test README + ##Demo + ### Demo project + Demo content + ## Setup + Setup content (./image.png)"""; + ReadmeContentsModel readmeContentsModel1 = + ProductContentUtils.getExtractedPartsOfReadme(readmeContentsWithSpaceHeading); + assertTrue(readmeContentsModel1.getDemo().startsWith("### Demo project")); + assertTrue(readmeContentsModel1.getSetup().startsWith("Setup content (./image.png)")); } @Test diff --git a/marketplace-service/src/test/resources/README.md b/marketplace-service/src/test/resources/README.md index c68b040e..d7ef143e 100644 --- a/marketplace-service/src/test/resources/README.md +++ b/marketplace-service/src/test/resources/README.md @@ -9,6 +9,7 @@ This connector: - allow you to start the Axon Ivy process by hitting the slash command key from the mattermost's channel. - allow you to send a message to the mattermost's channel from the Axon Ivy workplace. - notifies users on the channel for new Axon Ivy workflow Tasks. + ![Restful Person Manager](screen2.png "Restful Person Manager") ## Demo