From 1ece383d3bd42f4e478ae48d74e8ee963ddce0f3 Mon Sep 17 00:00:00 2001 From: Sergii Leshchenko Date: Tue, 12 Mar 2019 16:48:52 +0200 Subject: [PATCH] Fixed accepting factory if GitHub repo URL contains trailing slash (#12867) * Fix accepting factory if url contains trailing slash * Improve error message if exception occurred during devfile processing Signed-off-by: Sergii Leshchenko --- .../che/plugin/github/factory/resolver/GithubURLParser.java | 2 +- .../plugin/github/factory/resolver/GithubURLParserTest.java | 2 ++ .../api/factory/server/urlfactory/URLFactoryBuilder.java | 6 +++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/plugin-github/che-plugin-github-factory-resolver/src/main/java/org/eclipse/che/plugin/github/factory/resolver/GithubURLParser.java b/plugins/plugin-github/che-plugin-github-factory-resolver/src/main/java/org/eclipse/che/plugin/github/factory/resolver/GithubURLParser.java index 2975c0eaed..a416d82422 100644 --- a/plugins/plugin-github/che-plugin-github-factory-resolver/src/main/java/org/eclipse/che/plugin/github/factory/resolver/GithubURLParser.java +++ b/plugins/plugin-github/che-plugin-github-factory-resolver/src/main/java/org/eclipse/che/plugin/github/factory/resolver/GithubURLParser.java @@ -35,7 +35,7 @@ public class GithubURLParser { */ protected static final Pattern GITHUB_PATTERN = Pattern.compile( - "^(?:http)(?:s)?(?:\\:\\/\\/)github.com/(?[^/]++)/(?[^/]++)((?:/tree/(?[^/]++)(?:/(?.*))?)|(/pull/(?[^/]++)))?$"); + "^(?:http)(?:s)?(?:\\:\\/\\/)github.com/(?[^/]++)/(?[^/]++)((/)|(?:/tree/(?[^/]++)(?:/(?.*))?)|(/pull/(?[^/]++)))?$"); /** Regexp to find repository and branch name from PR link */ protected static final Pattern PR_DATA_PATTERN = diff --git a/plugins/plugin-github/che-plugin-github-factory-resolver/src/test/java/org/eclipse/che/plugin/github/factory/resolver/GithubURLParserTest.java b/plugins/plugin-github/che-plugin-github-factory-resolver/src/test/java/org/eclipse/che/plugin/github/factory/resolver/GithubURLParserTest.java index 7258a1436e..450262a481 100644 --- a/plugins/plugin-github/che-plugin-github-factory-resolver/src/test/java/org/eclipse/che/plugin/github/factory/resolver/GithubURLParserTest.java +++ b/plugins/plugin-github/che-plugin-github-factory-resolver/src/test/java/org/eclipse/che/plugin/github/factory/resolver/GithubURLParserTest.java @@ -72,6 +72,7 @@ public class GithubURLParserTest { public Object[][] urls() { return new Object[][] { {"https://github.com/eclipse/che"}, + {"https://github.com/eclipse/che/"}, {"https://github.com/eclipse/che/tree/4.2.x"}, {"https://github.com/eclipse/che/tree/master/"}, {"https://github.com/eclipse/che/tree/master/dashboard/"}, @@ -85,6 +86,7 @@ public class GithubURLParserTest { public Object[][] expectedParsing() { return new Object[][] { {"https://github.com/eclipse/che", "eclipse", "che", "master", null}, + {"https://github.com/eclipse/che/", "eclipse", "che", "master", null}, {"https://github.com/eclipse/che/tree/4.2.x", "eclipse", "che", "4.2.x", null}, { "https://github.com/eclipse/che/tree/master/dashboard/", diff --git a/wsmaster/che-core-api-factory/src/main/java/org/eclipse/che/api/factory/server/urlfactory/URLFactoryBuilder.java b/wsmaster/che-core-api-factory/src/main/java/org/eclipse/che/api/factory/server/urlfactory/URLFactoryBuilder.java index bf6e0e0b38..6e05c8660e 100644 --- a/wsmaster/che-core-api-factory/src/main/java/org/eclipse/che/api/factory/server/urlfactory/URLFactoryBuilder.java +++ b/wsmaster/che-core-api-factory/src/main/java/org/eclipse/che/api/factory/server/urlfactory/URLFactoryBuilder.java @@ -106,7 +106,11 @@ public class URLFactoryBuilder { .withV(CURRENT_VERSION) .withWorkspace(DtoConverter.asDto(wsConfig))); } catch (DevfileException e) { - throw new BadRequestException(e.getMessage()); + throw new BadRequestException( + "Error occurred during creation a workspace from devfile located at `" + + devfileLocation + + "`. Cause: " + + e.getMessage()); } }