{"action":"created","comment":{"url":"https://api.github.com/repos/codenvy/codenvy/pulls/comments/64028825","id":64028825,"diff_hunk":"@@ -0,0 +1,194 @@\n+/*\n+ *  [2012] - [2016] Codenvy, S.A.\n+ *  All Rights Reserved.\n+ *\n+ * NOTICE:  All information contained herein is, and remains\n+ * the property of Codenvy S.A. and its suppliers,\n+ * if any.  The intellectual and technical concepts contained\n+ * herein are proprietary to Codenvy S.A.\n+ * and its suppliers and may be covered by U.S. and Foreign Patents,\n+ * patents in process, and are protected by trade secret or copyright law.\n+ * Dissemination of this information or reproduction of this material\n+ * is strictly forbidden unless prior written permission is obtained\n+ * from Codenvy S.A..\n+ */\n+package com.codenvy.plugin.factory.github.server;\n+\n+import org.eclipse.che.api.core.BadRequestException;\n+import org.eclipse.che.api.factory.server.FactoryParametersResolver;\n+import org.eclipse.che.api.factory.shared.dto.Factory;\n+import org.eclipse.che.api.machine.shared.dto.LimitsDto;\n+import org.eclipse.che.api.machine.shared.dto.MachineConfigDto;\n+import org.eclipse.che.api.machine.shared.dto.MachineSourceDto;\n+import org.eclipse.che.api.workspace.shared.dto.EnvironmentDto;\n+import org.eclipse.che.api.workspace.shared.dto.ProjectConfigDto;\n+import org.eclipse.che.api.workspace.shared.dto.SourceStorageDto;\n+import org.eclipse.che.api.workspace.shared.dto.WorkspaceConfigDto;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+\n+import javax.validation.constraints.NotNull;\n+import java.io.IOException;\n+import java.net.HttpURLConnection;\n+import java.net.URL;\n+import java.util.HashMap;\n+import java.util.Map;\n+import java.util.concurrent.TimeUnit;\n+import java.util.regex.Matcher;\n+import java.util.regex.Pattern;\n+\n+import static java.util.Collections.singletonList;\n+import static org.eclipse.che.dto.server.DtoFactory.newDto;\n+\n+/**\n+ * Provides Factory Parameters resolver for github repositories.\n+ *\n+ * @author Florent Benoit\n+ */\n+public class GithubFactoryParametersResolver implements FactoryParametersResolver {\n+\n+    /**\n+     * Logger.\n+     */\n+    private static final Logger LOG = LoggerFactory.getLogger(GithubFactoryParametersResolver.class);\n+\n+    /**\n+     * Parameter name.\n+     */\n+    protected static final String URL_PARAMETER_NAME = \"url\";\n+\n+    /**\n+     * Connection timeout of 30seconds.\n+     */\n+    private static final int CONNECTION_TIMEOUT = (int) TimeUnit.SECONDS.toMillis(30);\n+\n+    /**\n+     * Regexp to find repository details (repository name, project name and branch and subfolder)\n+     */\n+    private final Pattern GITHUB_PATTERN = Pattern.compile(\"^(?:http)(?:s)?(?:\\\\:\\\\/\\\\/)github.com/(.*?)/(.*?)(?:/tree/(.*?)(?:/(.*?))?)?$\");\n+\n+    /**\n+     * Check if this resolver can be used with the given parameters.\n+     *\n+     * @param factoryParameters\n+     *         map of parameters dedicated to factories\n+     * @return true if it will be accepted by the resolver implementation or false if it is not accepted\n+     */\n+    @Override\n+    public boolean accept(@NotNull Map<String, String> factoryParameters) {\n+        // Check if url parameter is a github URL\n+        return factoryParameters.containsKey(URL_PARAMETER_NAME) && GITHUB_PATTERN.matcher(factoryParameters.get(URL_PARAMETER_NAME)).matches();\n+    }\n+\n+    /**\n+     * Create factory object based on provided parameters\n+     *\n+     * @param factoryParameters\n+     *         map containing factory data parameters provided through URL\n+     * @throws BadRequestException when data are invalid\n+     */\n+    @Override\n+    public Factory createFactory(@NotNull Map<String, String> factoryParameters) throws BadRequestException {\n+\n+        String githubUrl = factoryParameters.get(\"url\");\n+\n+        // Apply github url to the regexp\n+        Matcher matcher = GITHUB_PATTERN.matcher(githubUrl);\n+        if (!matcher.matches()) {\n+            throw new BadRequestException(String.format(\n+                    \"The given github url %s is not a valid URL github url. It should start with https://github.com/<user>/<repo>\",\n+                    githubUrl));\n+        }\n+\n+        // ok so now get matching group\n+        int regexpGroupCount = matcher.groupCount();\n+        if (regexpGroupCount < 2) {\n+            throw new BadRequestException(String.format(\n+                    \"The given github url %s is not a valid URL github url. It should start with https://github.com/<user>/<repo>\",\n+                    githubUrl));\n+        }\n+\n+        String repoUser = matcher.group(1);","path":"plugins/plugin-factory-github/codenvy-plugin-factory-github-server/src/main/java/com/codenvy/plugin/factory/github/server/GithubFactoryParametersResolver.java","position":111,"original_position":111,"commit_id":"71d1b5b03f7668ac7df34926b733d08eefee4d33","original_commit_id":"71d1b5b03f7668ac7df34926b733d08eefee4d33","user":{"login":"garagatyi","id":1851863,"avatar_url":"https://avatars.githubusercontent.com/u/1851863?v=3","gravatar_id":"","url":"https://api.github.com/users/garagatyi","html_url":"https://github.com/garagatyi","followers_url":"https://api.github.com/users/garagatyi/followers","following_url":"https://api.github.com/users/garagatyi/following{/other_user}","gists_url":"https://api.github.com/users/garagatyi/gists{/gist_id}","starred_url":"https://api.github.com/users/garagatyi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/garagatyi/subscriptions","organizations_url":"https://api.github.com/users/garagatyi/orgs","repos_url":"https://api.github.com/users/garagatyi/repos","events_url":"https://api.github.com/users/garagatyi/events{/privacy}","received_events_url":"https://api.github.com/users/garagatyi/received_events","type":"User","site_admin":false},"body":"Again usage of named groups would be much expressive and safe","created_at":"2016-05-20T11:47:24Z","updated_at":"2016-05-20T11:47:24Z","html_url":"https://github.com/codenvy/codenvy/pull/195#discussion_r64028825","pull_request_url":"https://api.github.com/repos/codenvy/codenvy/pulls/195","_links":{"self":{"href":"https://api.github.com/repos/codenvy/codenvy/pulls/comments/64028825"},"html":{"href":"https://github.com/codenvy/codenvy/pull/195#discussion_r64028825"},"pull_request":{"href":"https://api.github.com/repos/codenvy/codenvy/pulls/195"}}},"pull_request":{"url":"https://api.github.com/repos/codenvy/codenvy/pulls/195","id":69961956,"html_url":"https://github.com/codenvy/codenvy/pull/195","diff_url":"https://github.com/codenvy/codenvy/pull/195.diff","patch_url":"https://github.com/codenvy/codenvy/pull/195.patch","issue_url":"https://api.github.com/repos/codenvy/codenvy/issues/195","number":195,"state":"open","locked":false,"title":"CODENVY-502 allow to create factories by providing github URL","user":{"login":"benoitf","id":436777,"avatar_url":"https://avatars.githubusercontent.com/u/436777?v=3","gravatar_id":"","url":"https://api.github.com/users/benoitf","html_url":"https://github.com/benoitf","followers_url":"https://api.github.com/users/benoitf/followers","following_url":"https://api.github.com/users/benoitf/following{/other_user}","gists_url":"https://api.github.com/users/benoitf/gists{/gist_id}","starred_url":"https://api.github.com/users/benoitf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benoitf/subscriptions","organizations_url":"https://api.github.com/users/benoitf/orgs","repos_url":"https://api.github.com/users/benoitf/repos","events_url":"https://api.github.com/users/benoitf/events{/privacy}","received_events_url":"https://api.github.com/users/benoitf/received_events","type":"User","site_admin":false},"body":"Change-Id: Ic5707936dfb9682126f14a2ed7b1716becde31cd\r\nSigned-off-by: Florent BENOIT <fbenoit@codenvy.com>","created_at":"2016-05-13T08:47:56Z","updated_at":"2016-05-20T11:47:24Z","closed_at":null,"merged_at":null,"merge_commit_sha":"085df5c015750bdf519fcd09db52682ffe8558a3","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/codenvy/codenvy/pulls/195/commits","review_comments_url":"https://api.github.com/repos/codenvy/codenvy/pulls/195/comments","review_comment_url":"https://api.github.com/repos/codenvy/codenvy/pulls/comments{/number}","comments_url":"https://api.github.com/repos/codenvy/codenvy/issues/195/comments","statuses_url":"https://api.github.com/repos/codenvy/codenvy/statuses/71d1b5b03f7668ac7df34926b733d08eefee4d33","head":{"label":"codenvy:CODENVY-502","ref":"CODENVY-502","sha":"71d1b5b03f7668ac7df34926b733d08eefee4d33","user":{"login":"codenvy","id":2736247,"avatar_url":"https://avatars.githubusercontent.com/u/2736247?v=3","gravatar_id":"","url":"https://api.github.com/users/codenvy","html_url":"https://github.com/codenvy","followers_url":"https://api.github.com/users/codenvy/followers","following_url":"https://api.github.com/users/codenvy/following{/other_user}","gists_url":"https://api.github.com/users/codenvy/gists{/gist_id}","starred_url":"https://api.github.com/users/codenvy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codenvy/subscriptions","organizations_url":"https://api.github.com/users/codenvy/orgs","repos_url":"https://api.github.com/users/codenvy/repos","events_url":"https://api.github.com/users/codenvy/events{/privacy}","received_events_url":"https://api.github.com/users/codenvy/received_events","type":"Organization","site_admin":false},"repo":{"id":54102761,"name":"codenvy","full_name":"codenvy/codenvy","owner":{"login":"codenvy","id":2736247,"avatar_url":"https://avatars.githubusercontent.com/u/2736247?v=3","gravatar_id":"","url":"https://api.github.com/users/codenvy","html_url":"https://github.com/codenvy","followers_url":"https://api.github.com/users/codenvy/followers","following_url":"https://api.github.com/users/codenvy/following{/other_user}","gists_url":"https://api.github.com/users/codenvy/gists{/gist_id}","starred_url":"https://api.github.com/users/codenvy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codenvy/subscriptions","organizations_url":"https://api.github.com/users/codenvy/orgs","repos_url":"https://api.github.com/users/codenvy/repos","events_url":"https://api.github.com/users/codenvy/events{/privacy}","received_events_url":"https://api.github.com/users/codenvy/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/codenvy/codenvy","description":"Codenvy","fork":false,"url":"https://api.github.com/repos/codenvy/codenvy","forks_url":"https://api.github.com/repos/codenvy/codenvy/forks","keys_url":"https://api.github.com/repos/codenvy/codenvy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/codenvy/codenvy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/codenvy/codenvy/teams","hooks_url":"https://api.github.com/repos/codenvy/codenvy/hooks","issue_events_url":"https://api.github.com/repos/codenvy/codenvy/issues/events{/number}","events_url":"https://api.github.com/repos/codenvy/codenvy/events","assignees_url":"https://api.github.com/repos/codenvy/codenvy/assignees{/user}","branches_url":"https://api.github.com/repos/codenvy/codenvy/branches{/branch}","tags_url":"https://api.github.com/repos/codenvy/codenvy/tags","blobs_url":"https://api.github.com/repos/codenvy/codenvy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/codenvy/codenvy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/codenvy/codenvy/git/refs{/sha}","trees_url":"https://api.github.com/repos/codenvy/codenvy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/codenvy/codenvy/statuses/{sha}","languages_url":"https://api.github.com/repos/codenvy/codenvy/languages","stargazers_url":"https://api.github.com/repos/codenvy/codenvy/stargazers","contributors_url":"https://api.github.com/repos/codenvy/codenvy/contributors","subscribers_url":"https://api.github.com/repos/codenvy/codenvy/subscribers","subscription_url":"https://api.github.com/repos/codenvy/codenvy/subscription","commits_url":"https://api.github.com/repos/codenvy/codenvy/commits{/sha}","git_commits_url":"https://api.github.com/repos/codenvy/codenvy/git/commits{/sha}","comments_url":"https://api.github.com/repos/codenvy/codenvy/comments{/number}","issue_comment_url":"https://api.github.com/repos/codenvy/codenvy/issues/comments{/number}","contents_url":"https://api.github.com/repos/codenvy/codenvy/contents/{+path}","compare_url":"https://api.github.com/repos/codenvy/codenvy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/codenvy/codenvy/merges","archive_url":"https://api.github.com/repos/codenvy/codenvy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/codenvy/codenvy/downloads","issues_url":"https://api.github.com/repos/codenvy/codenvy/issues{/number}","pulls_url":"https://api.github.com/repos/codenvy/codenvy/pulls{/number}","milestones_url":"https://api.github.com/repos/codenvy/codenvy/milestones{/number}","notifications_url":"https://api.github.com/repos/codenvy/codenvy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/codenvy/codenvy/labels{/name}","releases_url":"https://api.github.com/repos/codenvy/codenvy/releases{/id}","deployments_url":"https://api.github.com/repos/codenvy/codenvy/deployments","created_at":"2016-03-17T08:51:27Z","updated_at":"2016-05-08T02:26:17Z","pushed_at":"2016-05-20T11:46:18Z","git_url":"git://github.com/codenvy/codenvy.git","ssh_url":"git@github.com:codenvy/codenvy.git","clone_url":"https://github.com/codenvy/codenvy.git","svn_url":"https://github.com/codenvy/codenvy","homepage":null,"size":68493,"stargazers_count":7,"watchers_count":7,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":10,"mirror_url":null,"open_issues_count":4,"forks":10,"open_issues":4,"watchers":7,"default_branch":"master"}},"base":{"label":"codenvy:master","ref":"master","sha":"6374ba3aede77e4ec35339f5da828a9c2882ae27","user":{"login":"codenvy","id":2736247,"avatar_url":"https://avatars.githubusercontent.com/u/2736247?v=3","gravatar_id":"","url":"https://api.github.com/users/codenvy","html_url":"https://github.com/codenvy","followers_url":"https://api.github.com/users/codenvy/followers","following_url":"https://api.github.com/users/codenvy/following{/other_user}","gists_url":"https://api.github.com/users/codenvy/gists{/gist_id}","starred_url":"https://api.github.com/users/codenvy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codenvy/subscriptions","organizations_url":"https://api.github.com/users/codenvy/orgs","repos_url":"https://api.github.com/users/codenvy/repos","events_url":"https://api.github.com/users/codenvy/events{/privacy}","received_events_url":"https://api.github.com/users/codenvy/received_events","type":"Organization","site_admin":false},"repo":{"id":54102761,"name":"codenvy","full_name":"codenvy/codenvy","owner":{"login":"codenvy","id":2736247,"avatar_url":"https://avatars.githubusercontent.com/u/2736247?v=3","gravatar_id":"","url":"https://api.github.com/users/codenvy","html_url":"https://github.com/codenvy","followers_url":"https://api.github.com/users/codenvy/followers","following_url":"https://api.github.com/users/codenvy/following{/other_user}","gists_url":"https://api.github.com/users/codenvy/gists{/gist_id}","starred_url":"https://api.github.com/users/codenvy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/codenvy/subscriptions","organizations_url":"https://api.github.com/users/codenvy/orgs","repos_url":"https://api.github.com/users/codenvy/repos","events_url":"https://api.github.com/users/codenvy/events{/privacy}","received_events_url":"https://api.github.com/users/codenvy/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/codenvy/codenvy","description":"Codenvy","fork":false,"url":"https://api.github.com/repos/codenvy/codenvy","forks_url":"https://api.github.com/repos/codenvy/codenvy/forks","keys_url":"https://api.github.com/repos/codenvy/codenvy/keys{/key_id}","collaborators_url":"https://api.github.com/repos/codenvy/codenvy/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/codenvy/codenvy/teams","hooks_url":"https://api.github.com/repos/codenvy/codenvy/hooks","issue_events_url":"https://api.github.com/repos/codenvy/codenvy/issues/events{/number}","events_url":"https://api.github.com/repos/codenvy/codenvy/events","assignees_url":"https://api.github.com/repos/codenvy/codenvy/assignees{/user}","branches_url":"https://api.github.com/repos/codenvy/codenvy/branches{/branch}","tags_url":"https://api.github.com/repos/codenvy/codenvy/tags","blobs_url":"https://api.github.com/repos/codenvy/codenvy/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/codenvy/codenvy/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/codenvy/codenvy/git/refs{/sha}","trees_url":"https://api.github.com/repos/codenvy/codenvy/git/trees{/sha}","statuses_url":"https://api.github.com/repos/codenvy/codenvy/statuses/{sha}","languages_url":"https://api.github.com/repos/codenvy/codenvy/languages","stargazers_url":"https://api.github.com/repos/codenvy/codenvy/stargazers","contributors_url":"https://api.github.com/repos/codenvy/codenvy/contributors","subscribers_url":"https://api.github.com/repos/codenvy/codenvy/subscribers","subscription_url":"https://api.github.com/repos/codenvy/codenvy/subscription","commits_url":"https://api.github.com/repos/codenvy/codenvy/commits{/sha}","git_commits_url":"https://api.github.com/repos/codenvy/codenvy/git/commits{/sha}","comments_url":"https://api.github.com/repos/codenvy/codenvy/comments{/number}","issue_comment_url":"https://api.github.com/repos/codenvy/codenvy/issues/comments{/number}","contents_url":"https://api.github.com/repos/codenvy/codenvy/contents/{+path}","compare_url":"https://api.github.com/repos/codenvy/codenvy/compare/{base}...{head}","merges_url":"https://api.github.com/repos/codenvy/codenvy/merges","archive_url":"https://api.github.com/repos/codenvy/codenvy/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/codenvy/codenvy/downloads","issues_url":"https://api.github.com/repos/codenvy/codenvy/issues{/number}","pulls_url":"https://api.github.com/repos/codenvy/codenvy/pulls{/number}","milestones_url":"https://api.github.com/repos/codenvy/codenvy/milestones{/number}","notifications_url":"https://api.github.com/repos/codenvy/codenvy/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/codenvy/codenvy/labels{/name}","releases_url":"https://api.github.com/repos/codenvy/codenvy/releases{/id}","deployments_url":"https://api.github.com/repos/codenvy/codenvy/deployments","created_at":"2016-03-17T08:51:27Z","updated_at":"2016-05-08T02:26:17Z","pushed_at":"2016-05-20T11:46:18Z","git_url":"git://github.com/codenvy/codenvy.git","ssh_url":"git@github.com:codenvy/codenvy.git","clone_url":"https://github.com/codenvy/codenvy.git","svn_url":"https://github.com/codenvy/codenvy","homepage":null,"size":68493,"stargazers_count":7,"watchers_count":7,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":10,"mirror_url":null,"open_issues_count":4,"forks":10,"open_issues":4,"watchers":7,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/codenvy/codenvy/pulls/195"},"html":{"href":"https://github.com/codenvy/codenvy/pull/195"},"issue":{"href":"https://api.github.com/repos/codenvy/codenvy/issues/195"},"comments":{"href":"https://api.github.com/repos/codenvy/codenvy/issues/195/comments"},"review_comments":{"href":"https://api.github.com/repos/codenvy/codenvy/pulls/195/comments"},"review_comment":{"href":"https://api.github.com/repos/codenvy/codenvy/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/codenvy/codenvy/pulls/195/commits"},"statuses":{"href":"https://api.github.com/repos/codenvy/codenvy/statuses/71d1b5b03f7668ac7df34926b733d08eefee4d33"}}}}
{"actor":{"display_login":"garagatyi"}}