{"action":"created","comment":{"url":"https://api.github.com/repos/openshift/origin/pulls/comments/82196844","pull_request_review_id":3114884,"id":82196844,"diff_hunk":"@@ -134,85 +135,53 @@ func IsRegistryDockerHub(registry string) bool {\n // DockerImageReference.\n func ParseDockerImageReference(spec string) (DockerImageReference, error) {\n \tvar ref DockerImageReference\n-\t// TODO replace with docker version once docker/docker PR11109 is merged upstream\n-\tstream, tag, id := parseRepositoryTag(spec)\n \n-\trepoParts := strings.Split(stream, \"/\")\n-\tswitch len(repoParts) {\n-\tcase 2:\n-\t\tif isRegistryName(repoParts[0]) {\n-\t\t\t// registry/name\n-\t\t\tref.Registry = repoParts[0]\n-\t\t\tif IsRegistryDockerHub(ref.Registry) {\n-\t\t\t\tref.Namespace = DockerDefaultNamespace\n-\t\t\t}\n-\t\t\tif len(repoParts[1]) == 0 {\n-\t\t\t\treturn ref, fmt.Errorf(\"the docker pull spec %q must be two or three segments separated by slashes\", spec)\n-\t\t\t}\n-\t\t\tref.Name = repoParts[1]\n-\t\t\tref.Tag = tag\n-\t\t\tref.ID = id\n-\t\t\tbreak\n-\t\t}\n-\t\t// namespace/name\n-\t\tref.Namespace = repoParts[0]\n-\t\tif len(repoParts[1]) == 0 {\n-\t\t\treturn ref, fmt.Errorf(\"the docker pull spec %q must be two or three segments separated by slashes\", spec)\n-\t\t}\n-\t\tref.Name = repoParts[1]\n-\t\tref.Tag = tag\n-\t\tref.ID = id\n-\t\tbreak\n-\tcase 3:\n-\t\t// registry/namespace/name\n-\t\tref.Registry = repoParts[0]\n-\t\tref.Namespace = repoParts[1]\n-\t\tif len(repoParts[2]) == 0 {\n-\t\t\treturn ref, fmt.Errorf(\"the docker pull spec %q must be two or three segments separated by slashes\", spec)\n-\t\t}\n-\t\tref.Name = repoParts[2]\n-\t\tref.Tag = tag\n-\t\tref.ID = id\n-\t\tbreak\n-\tcase 1:\n-\t\t// name\n-\t\tif len(repoParts[0]) == 0 {\n-\t\t\treturn ref, fmt.Errorf(\"the docker pull spec %q must be two or three segments separated by slashes\", spec)\n-\t\t}\n-\t\tref.Name = repoParts[0]\n-\t\tref.Tag = tag\n-\t\tref.ID = id\n-\t\tbreak\n-\tdefault:\n-\t\t// Handle multiple segments in form: registry/namespace/namesegment1/namesegment2/.../name\n-\t\t// but not this form: http://registry/namespace/name. We don't support using the schema in\n-\t\t// the DockerImageReference.\n-\t\tif len(repoParts) > 3 && !strings.HasSuffix(repoParts[0], \":\") {\n-\t\t\tif len(repoParts[0]) == 0 {\n-\t\t\t\treturn ref, fmt.Errorf(\"the docker pull spec %q cannot have empty segments\", spec)\n-\t\t\t}\n-\t\t\tref.Registry = repoParts[0]\n+\tdockerRef, err := reference.Parse(spec)\n+\tif err != nil {\n+\t\treturn ref, err\n+\t}\n \n-\t\t\tif len(repoParts[1]) == 0 {\n-\t\t\t\treturn ref, fmt.Errorf(\"the docker pull spec %q cannot have empty segments\", spec)\n-\t\t\t}\n-\t\t\tref.Namespace = repoParts[1]\n+\tif named, ok := dockerRef.(reference.Named); ok {\n+\t\tref.Registry, ref.Name = reference.SplitHostname(named)\n+\t} else if named, ok := dockerRef.(reference.Tagged); ok {\n+\t\tref.Tag = named.Tag()\n+\t} else if named, ok := dockerRef.(reference.Digested); ok {\n+\t\tref.ID = named.Digest().String()\n+\t}\n \n-\t\t\tfor i, part := range repoParts[2:] {\n-\t\t\t\tif len(part) == 0 {\n-\t\t\t\t\treturn ref, fmt.Errorf(\"the docker pull spec %q cannot have empty segments\", spec)\n-\t\t\t\t}\n-\t\t\t\tif i > 0 {\n-\t\t\t\t\tref.Name += \"/\"\n-\t\t\t\t}\n-\t\t\t\tref.Name += part\n-\t\t\t}\n+\tif named, ok := dockerRef.(reference.NamedTagged); ok {\n+\t\tref.Tag = named.Tag()\n+\t}\n \n-\t\t\tref.Tag = tag\n-\t\t\tref.ID = id\n-\t\t\tbreak\n+\tif named, ok := dockerRef.(reference.Canonical); ok {\n+\t\tref.ID = named.Digest().String()\n+\t}\n+\n+\t// It's not enough just to use the reference.Parse(). We have the fill\n+\t// ref.Namespace from ref.Name and handle few special cases:\n+\t//   registry/name  - no namespace at all;\n+\t//   namespace/name - no registry;\n+\t//   name           - registry and namespace missing;\n+\n+\trepoParts := strings.Split(ref.Name, \"/\")\n+\n+\tif !isRegistryName(ref.Registry) && len(repoParts) == 1 {\n+\t\t// Case: namespace/name\n+\t\tref.Namespace = ref.Registry\n+\t\tref.Registry = \"\"\n+\t}\n+\n+\tif ref.Namespace == \"\" && len(repoParts) >= 2 {","path":"pkg/image/api/helper.go","position":121,"original_position":121,"commit_id":"a1b8c4bacc4b0f668504b6e4c6628dd0ad3e8cf0","original_commit_id":"a1b8c4bacc4b0f668504b6e4c6628dd0ad3e8cf0","user":{"login":"miminar","id":1478803,"avatar_url":"https://avatars.githubusercontent.com/u/1478803?v=3","gravatar_id":"","url":"https://api.github.com/users/miminar","html_url":"https://github.com/miminar","followers_url":"https://api.github.com/users/miminar/followers","following_url":"https://api.github.com/users/miminar/following{/other_user}","gists_url":"https://api.github.com/users/miminar/gists{/gist_id}","starred_url":"https://api.github.com/users/miminar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/miminar/subscriptions","organizations_url":"https://api.github.com/users/miminar/orgs","repos_url":"https://api.github.com/users/miminar/repos","events_url":"https://api.github.com/users/miminar/events{/privacy}","received_events_url":"https://api.github.com/users/miminar/received_events","type":"User","site_admin":false},"body":"*nit*: `len(ref.Namespace) == 0`","created_at":"2016-10-06T14:09:34Z","updated_at":"2016-10-06T14:09:34Z","html_url":"https://github.com/openshift/origin/pull/11245#discussion_r82196844","pull_request_url":"https://api.github.com/repos/openshift/origin/pulls/11245","_links":{"self":{"href":"https://api.github.com/repos/openshift/origin/pulls/comments/82196844"},"html":{"href":"https://github.com/openshift/origin/pull/11245#discussion_r82196844"},"pull_request":{"href":"https://api.github.com/repos/openshift/origin/pulls/11245"}}},"pull_request":{"url":"https://api.github.com/repos/openshift/origin/pulls/11245","id":88260448,"html_url":"https://github.com/openshift/origin/pull/11245","diff_url":"https://github.com/openshift/origin/pull/11245.diff","patch_url":"https://github.com/openshift/origin/pull/11245.patch","issue_url":"https://api.github.com/repos/openshift/origin/issues/11245","number":11245,"state":"open","locked":false,"title":"ParseDockerImageReference use docker/distribution reference parser","user":{"login":"legionus","id":1690313,"avatar_url":"https://avatars.githubusercontent.com/u/1690313?v=3","gravatar_id":"","url":"https://api.github.com/users/legionus","html_url":"https://github.com/legionus","followers_url":"https://api.github.com/users/legionus/followers","following_url":"https://api.github.com/users/legionus/following{/other_user}","gists_url":"https://api.github.com/users/legionus/gists{/gist_id}","starred_url":"https://api.github.com/users/legionus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/legionus/subscriptions","organizations_url":"https://api.github.com/users/legionus/orgs","repos_url":"https://api.github.com/users/legionus/repos","events_url":"https://api.github.com/users/legionus/events{/privacy}","received_events_url":"https://api.github.com/users/legionus/received_events","type":"User","site_admin":false},"body":"We can't remove ParseDockerImageReference and just use docker/distribution/reference\r\nto parse DockerImageReference because we have to support few special cases related\r\nto docker.io. Keeping it in mind, we can reimplement ParseDockerImageReference\r\nto use new parser.\r\n\r\nIn addition we got new limits on the length of the DockerImageReference.\r\nSo, after refactoring our restrictions are pretty the same as in docker/distribution.\r\n\r\nFix #11211 \r\n\r\n@ncdc @miminar please review.","created_at":"2016-10-06T13:21:35Z","updated_at":"2016-10-06T14:32:19Z","closed_at":null,"merged_at":null,"merge_commit_sha":"911f3372a29fd2ab32dceef7ef029892ed184414","assignee":{"login":"legionus","id":1690313,"avatar_url":"https://avatars.githubusercontent.com/u/1690313?v=3","gravatar_id":"","url":"https://api.github.com/users/legionus","html_url":"https://github.com/legionus","followers_url":"https://api.github.com/users/legionus/followers","following_url":"https://api.github.com/users/legionus/following{/other_user}","gists_url":"https://api.github.com/users/legionus/gists{/gist_id}","starred_url":"https://api.github.com/users/legionus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/legionus/subscriptions","organizations_url":"https://api.github.com/users/legionus/orgs","repos_url":"https://api.github.com/users/legionus/repos","events_url":"https://api.github.com/users/legionus/events{/privacy}","received_events_url":"https://api.github.com/users/legionus/received_events","type":"User","site_admin":false},"assignees":[{"login":"legionus","id":1690313,"avatar_url":"https://avatars.githubusercontent.com/u/1690313?v=3","gravatar_id":"","url":"https://api.github.com/users/legionus","html_url":"https://github.com/legionus","followers_url":"https://api.github.com/users/legionus/followers","following_url":"https://api.github.com/users/legionus/following{/other_user}","gists_url":"https://api.github.com/users/legionus/gists{/gist_id}","starred_url":"https://api.github.com/users/legionus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/legionus/subscriptions","organizations_url":"https://api.github.com/users/legionus/orgs","repos_url":"https://api.github.com/users/legionus/repos","events_url":"https://api.github.com/users/legionus/events{/privacy}","received_events_url":"https://api.github.com/users/legionus/received_events","type":"User","site_admin":false}],"milestone":null,"commits_url":"https://api.github.com/repos/openshift/origin/pulls/11245/commits","review_comments_url":"https://api.github.com/repos/openshift/origin/pulls/11245/comments","review_comment_url":"https://api.github.com/repos/openshift/origin/pulls/comments{/number}","comments_url":"https://api.github.com/repos/openshift/origin/issues/11245/comments","statuses_url":"https://api.github.com/repos/openshift/origin/statuses/a1b8c4bacc4b0f668504b6e4c6628dd0ad3e8cf0","head":{"label":"legionus:refactor-parse-dockerimagereference","ref":"refactor-parse-dockerimagereference","sha":"a1b8c4bacc4b0f668504b6e4c6628dd0ad3e8cf0","user":{"login":"legionus","id":1690313,"avatar_url":"https://avatars.githubusercontent.com/u/1690313?v=3","gravatar_id":"","url":"https://api.github.com/users/legionus","html_url":"https://github.com/legionus","followers_url":"https://api.github.com/users/legionus/followers","following_url":"https://api.github.com/users/legionus/following{/other_user}","gists_url":"https://api.github.com/users/legionus/gists{/gist_id}","starred_url":"https://api.github.com/users/legionus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/legionus/subscriptions","organizations_url":"https://api.github.com/users/legionus/orgs","repos_url":"https://api.github.com/users/legionus/repos","events_url":"https://api.github.com/users/legionus/events{/privacy}","received_events_url":"https://api.github.com/users/legionus/received_events","type":"User","site_admin":false},"repo":{"id":49266113,"name":"origin","full_name":"legionus/origin","owner":{"login":"legionus","id":1690313,"avatar_url":"https://avatars.githubusercontent.com/u/1690313?v=3","gravatar_id":"","url":"https://api.github.com/users/legionus","html_url":"https://github.com/legionus","followers_url":"https://api.github.com/users/legionus/followers","following_url":"https://api.github.com/users/legionus/following{/other_user}","gists_url":"https://api.github.com/users/legionus/gists{/gist_id}","starred_url":"https://api.github.com/users/legionus/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/legionus/subscriptions","organizations_url":"https://api.github.com/users/legionus/orgs","repos_url":"https://api.github.com/users/legionus/repos","events_url":"https://api.github.com/users/legionus/events{/privacy}","received_events_url":"https://api.github.com/users/legionus/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/legionus/origin","description":"OpenShift 3 - build, deploy, and manage your applications with Docker and Kubernetes","fork":true,"url":"https://api.github.com/repos/legionus/origin","forks_url":"https://api.github.com/repos/legionus/origin/forks","keys_url":"https://api.github.com/repos/legionus/origin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/legionus/origin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/legionus/origin/teams","hooks_url":"https://api.github.com/repos/legionus/origin/hooks","issue_events_url":"https://api.github.com/repos/legionus/origin/issues/events{/number}","events_url":"https://api.github.com/repos/legionus/origin/events","assignees_url":"https://api.github.com/repos/legionus/origin/assignees{/user}","branches_url":"https://api.github.com/repos/legionus/origin/branches{/branch}","tags_url":"https://api.github.com/repos/legionus/origin/tags","blobs_url":"https://api.github.com/repos/legionus/origin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/legionus/origin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/legionus/origin/git/refs{/sha}","trees_url":"https://api.github.com/repos/legionus/origin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/legionus/origin/statuses/{sha}","languages_url":"https://api.github.com/repos/legionus/origin/languages","stargazers_url":"https://api.github.com/repos/legionus/origin/stargazers","contributors_url":"https://api.github.com/repos/legionus/origin/contributors","subscribers_url":"https://api.github.com/repos/legionus/origin/subscribers","subscription_url":"https://api.github.com/repos/legionus/origin/subscription","commits_url":"https://api.github.com/repos/legionus/origin/commits{/sha}","git_commits_url":"https://api.github.com/repos/legionus/origin/git/commits{/sha}","comments_url":"https://api.github.com/repos/legionus/origin/comments{/number}","issue_comment_url":"https://api.github.com/repos/legionus/origin/issues/comments{/number}","contents_url":"https://api.github.com/repos/legionus/origin/contents/{+path}","compare_url":"https://api.github.com/repos/legionus/origin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/legionus/origin/merges","archive_url":"https://api.github.com/repos/legionus/origin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/legionus/origin/downloads","issues_url":"https://api.github.com/repos/legionus/origin/issues{/number}","pulls_url":"https://api.github.com/repos/legionus/origin/pulls{/number}","milestones_url":"https://api.github.com/repos/legionus/origin/milestones{/number}","notifications_url":"https://api.github.com/repos/legionus/origin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/legionus/origin/labels{/name}","releases_url":"https://api.github.com/repos/legionus/origin/releases{/id}","deployments_url":"https://api.github.com/repos/legionus/origin/deployments","created_at":"2016-01-08T10:32:30Z","updated_at":"2016-07-15T15:52:46Z","pushed_at":"2016-10-06T11:34:51Z","git_url":"git://github.com/legionus/origin.git","ssh_url":"git@github.com:legionus/origin.git","clone_url":"https://github.com/legionus/origin.git","svn_url":"https://github.com/legionus/origin","homepage":"http://www.openshift.org","size":340587,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":0,"default_branch":"master"}},"base":{"label":"openshift:master","ref":"master","sha":"a4eebdd17f4797de5647ca9877fe382200f56d94","user":{"login":"openshift","id":792337,"avatar_url":"https://avatars.githubusercontent.com/u/792337?v=3","gravatar_id":"","url":"https://api.github.com/users/openshift","html_url":"https://github.com/openshift","followers_url":"https://api.github.com/users/openshift/followers","following_url":"https://api.github.com/users/openshift/following{/other_user}","gists_url":"https://api.github.com/users/openshift/gists{/gist_id}","starred_url":"https://api.github.com/users/openshift/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openshift/subscriptions","organizations_url":"https://api.github.com/users/openshift/orgs","repos_url":"https://api.github.com/users/openshift/repos","events_url":"https://api.github.com/users/openshift/events{/privacy}","received_events_url":"https://api.github.com/users/openshift/received_events","type":"Organization","site_admin":false},"repo":{"id":22442668,"name":"origin","full_name":"openshift/origin","owner":{"login":"openshift","id":792337,"avatar_url":"https://avatars.githubusercontent.com/u/792337?v=3","gravatar_id":"","url":"https://api.github.com/users/openshift","html_url":"https://github.com/openshift","followers_url":"https://api.github.com/users/openshift/followers","following_url":"https://api.github.com/users/openshift/following{/other_user}","gists_url":"https://api.github.com/users/openshift/gists{/gist_id}","starred_url":"https://api.github.com/users/openshift/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/openshift/subscriptions","organizations_url":"https://api.github.com/users/openshift/orgs","repos_url":"https://api.github.com/users/openshift/repos","events_url":"https://api.github.com/users/openshift/events{/privacy}","received_events_url":"https://api.github.com/users/openshift/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/openshift/origin","description":"Enterprise-Ready Kubernetes for Developers","fork":false,"url":"https://api.github.com/repos/openshift/origin","forks_url":"https://api.github.com/repos/openshift/origin/forks","keys_url":"https://api.github.com/repos/openshift/origin/keys{/key_id}","collaborators_url":"https://api.github.com/repos/openshift/origin/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/openshift/origin/teams","hooks_url":"https://api.github.com/repos/openshift/origin/hooks","issue_events_url":"https://api.github.com/repos/openshift/origin/issues/events{/number}","events_url":"https://api.github.com/repos/openshift/origin/events","assignees_url":"https://api.github.com/repos/openshift/origin/assignees{/user}","branches_url":"https://api.github.com/repos/openshift/origin/branches{/branch}","tags_url":"https://api.github.com/repos/openshift/origin/tags","blobs_url":"https://api.github.com/repos/openshift/origin/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/openshift/origin/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/openshift/origin/git/refs{/sha}","trees_url":"https://api.github.com/repos/openshift/origin/git/trees{/sha}","statuses_url":"https://api.github.com/repos/openshift/origin/statuses/{sha}","languages_url":"https://api.github.com/repos/openshift/origin/languages","stargazers_url":"https://api.github.com/repos/openshift/origin/stargazers","contributors_url":"https://api.github.com/repos/openshift/origin/contributors","subscribers_url":"https://api.github.com/repos/openshift/origin/subscribers","subscription_url":"https://api.github.com/repos/openshift/origin/subscription","commits_url":"https://api.github.com/repos/openshift/origin/commits{/sha}","git_commits_url":"https://api.github.com/repos/openshift/origin/git/commits{/sha}","comments_url":"https://api.github.com/repos/openshift/origin/comments{/number}","issue_comment_url":"https://api.github.com/repos/openshift/origin/issues/comments{/number}","contents_url":"https://api.github.com/repos/openshift/origin/contents/{+path}","compare_url":"https://api.github.com/repos/openshift/origin/compare/{base}...{head}","merges_url":"https://api.github.com/repos/openshift/origin/merges","archive_url":"https://api.github.com/repos/openshift/origin/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/openshift/origin/downloads","issues_url":"https://api.github.com/repos/openshift/origin/issues{/number}","pulls_url":"https://api.github.com/repos/openshift/origin/pulls{/number}","milestones_url":"https://api.github.com/repos/openshift/origin/milestones{/number}","notifications_url":"https://api.github.com/repos/openshift/origin/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/openshift/origin/labels{/name}","releases_url":"https://api.github.com/repos/openshift/origin/releases{/id}","deployments_url":"https://api.github.com/repos/openshift/origin/deployments","created_at":"2014-07-30T20:04:05Z","updated_at":"2016-10-06T10:55:35Z","pushed_at":"2016-10-06T14:22:05Z","git_url":"git://github.com/openshift/origin.git","ssh_url":"git@github.com:openshift/origin.git","clone_url":"https://github.com/openshift/origin.git","svn_url":"https://github.com/openshift/origin","homepage":"http://www.openshift.org","size":594169,"stargazers_count":1807,"watchers_count":1807,"language":"Go","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1190,"mirror_url":null,"open_issues_count":1215,"forks":1190,"open_issues":1215,"watchers":1807,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/openshift/origin/pulls/11245"},"html":{"href":"https://github.com/openshift/origin/pull/11245"},"issue":{"href":"https://api.github.com/repos/openshift/origin/issues/11245"},"comments":{"href":"https://api.github.com/repos/openshift/origin/issues/11245/comments"},"review_comments":{"href":"https://api.github.com/repos/openshift/origin/pulls/11245/comments"},"review_comment":{"href":"https://api.github.com/repos/openshift/origin/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/openshift/origin/pulls/11245/commits"},"statuses":{"href":"https://api.github.com/repos/openshift/origin/statuses/a1b8c4bacc4b0f668504b6e4c6628dd0ad3e8cf0"}}}}
{"actor":{"display_login":"miminar"}}