{"action":"created","comment":{"url":"https://api.github.com/repos/snapcore/snapd/pulls/comments/70449057","id":70449057,"diff_hunk":"@@ -0,0 +1,140 @@\n+// -*- Mode: Go; indent-tabs-mode: t -*-\n+\n+/*\n+ * Copyright (C) 2016 Canonical Ltd\n+ *\n+ * This program is free software: you can redistribute it and/or modify\n+ * it under the terms of the GNU General Public License version 3 as\n+ * published by the Free Software Foundation.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.\n+ *\n+ */\n+\n+package main\n+\n+import (\n+\t\"bufio\"\n+\t\"fmt\"\n+\t\"strings\"\n+\n+\t\"github.com/snapcore/snapd/client\"\n+\t\"github.com/snapcore/snapd/i18n\"\n+\t\"github.com/snapcore/snapd/store\"\n+\n+\t\"github.com/jessevdk/go-flags\"\n+)\n+\n+var shortBuyHelp = i18n.G(\"Finds packages to install\")\n+var longBuyHelp = i18n.G(`\n+The find command queries the store for available packages.\n+`)\n+\n+var positiveResponse = map[string]bool{\n+\t\"\":            true,\n+\ti18n.G(\"y\"):   true,\n+\ti18n.G(\"yes\"): true,\n+}\n+\n+type cmdBuy struct {\n+\tCurrency  string `long:\"currency\" description:\"ISO 4217 code for currency (https://en.wikipedia.org/wiki/ISO_4217)\"`\n+\tChannel   string `long:\"channel\" description:\"Use this channel instead of stable\"`\n+\tBackendID string `long:\"backend-id\" description:\"e.g. \\\"credit_card\\\", \\\"rest_paypal\\\"\"`\n+\tMethodID  int    `long:\"method-id\" description:\"numeric identifier for a specific credit card or Paypal account\"`\n+\n+\tPositional struct {\n+\t\tSnapName string `positional-arg-name:\"<snap-name>\"`\n+\t} `positional-args:\"yes\" required:\"yes\"`\n+}\n+\n+func init() {\n+\taddCommand(\"buy\", shortBuyHelp, longBuyHelp, func() flags.Commander {\n+\t\treturn &cmdBuy{}\n+\t})\n+}\n+\n+func (x *cmdBuy) Execute([]string) error {\n+\treturn buySnap(&store.BuyOptions{\n+\t\tSnapName:  x.Positional.SnapName,\n+\t\tCurrency:  x.Currency,\n+\t\tBackendID: x.BackendID,\n+\t\tMethodID:  x.MethodID,\n+\t\tChannel:   x.Channel,\n+\t})\n+}\n+\n+func buySnap(opts *store.BuyOptions) error {\n+\tcli := Client()\n+\n+\tif strings.ContainsAny(opts.SnapName, \":*\") {\n+\t\treturn fmt.Errorf(i18n.G(\"cannot buy snap %q: invalid characters in name\"), opts.SnapName)\n+\t}\n+\n+\tsnaps, resultInfo, err := cli.Find(&client.FindOptions{\n+\t\tQuery: fmt.Sprintf(\"name:%s\", opts.SnapName),\n+\t})\n+\n+\tif err != nil {\n+\t\treturn err\n+\t}\n+\n+\tif len(snaps) < 1 {\n+\t\treturn fmt.Errorf(i18n.G(\"cannot buy snap %q: it cannot be found\"), opts.SnapName)\n+\t}\n+\n+\tif len(snaps) > 1 {\n+\t\treturn fmt.Errorf(i18n.G(\"cannot buy snap %q: muliple results found\"), opts.SnapName)\n+\t}\n+\n+\tsnap := snaps[0]\n+\n+\topts.SnapID = snap.ID\n+\n+\tif opts.Channel == \"\" {\n+\t\topts.Channel = snap.Channel\n+\t}\n+\n+\tif opts.Currency == \"\" {","path":"cmd/snap/cmd_buy.go","position":103,"original_position":103,"commit_id":"fcdc350df5833bc2389b559f7aa7ad40715660af","original_commit_id":"fcdc350df5833bc2389b559f7aa7ad40715660af","user":{"login":"niemeyer","id":378683,"avatar_url":"https://avatars.githubusercontent.com/u/378683?v=3","gravatar_id":"","url":"https://api.github.com/users/niemeyer","html_url":"https://github.com/niemeyer","followers_url":"https://api.github.com/users/niemeyer/followers","following_url":"https://api.github.com/users/niemeyer/following{/other_user}","gists_url":"https://api.github.com/users/niemeyer/gists{/gist_id}","starred_url":"https://api.github.com/users/niemeyer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/niemeyer/subscriptions","organizations_url":"https://api.github.com/users/niemeyer/orgs","repos_url":"https://api.github.com/users/niemeyer/repos","events_url":"https://api.github.com/users/niemeyer/events{/privacy}","received_events_url":"https://api.github.com/users/niemeyer/received_events","type":"User","site_admin":false},"body":"Nipick: feels like a bit too much spacing here.  All the logic above is closely related, and could be joined together.","created_at":"2016-07-12T14:27:27Z","updated_at":"2016-07-12T14:27:27Z","html_url":"https://github.com/snapcore/snapd/pull/1507#discussion_r70449057","pull_request_url":"https://api.github.com/repos/snapcore/snapd/pulls/1507","_links":{"self":{"href":"https://api.github.com/repos/snapcore/snapd/pulls/comments/70449057"},"html":{"href":"https://github.com/snapcore/snapd/pull/1507#discussion_r70449057"},"pull_request":{"href":"https://api.github.com/repos/snapcore/snapd/pulls/1507"}}},"pull_request":{"url":"https://api.github.com/repos/snapcore/snapd/pulls/1507","id":76590560,"html_url":"https://github.com/snapcore/snapd/pull/1507","diff_url":"https://github.com/snapcore/snapd/pull/1507.diff","patch_url":"https://github.com/snapcore/snapd/pull/1507.patch","issue_url":"https://api.github.com/repos/snapcore/snapd/issues/1507","number":1507,"state":"open","locked":false,"title":"cmd: add buy command","user":{"login":"pete-woods","id":152569,"avatar_url":"https://avatars.githubusercontent.com/u/152569?v=3","gravatar_id":"","url":"https://api.github.com/users/pete-woods","html_url":"https://github.com/pete-woods","followers_url":"https://api.github.com/users/pete-woods/followers","following_url":"https://api.github.com/users/pete-woods/following{/other_user}","gists_url":"https://api.github.com/users/pete-woods/gists{/gist_id}","starred_url":"https://api.github.com/users/pete-woods/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pete-woods/subscriptions","organizations_url":"https://api.github.com/users/pete-woods/orgs","repos_url":"https://api.github.com/users/pete-woods/repos","events_url":"https://api.github.com/users/pete-woods/events{/privacy}","received_events_url":"https://api.github.com/users/pete-woods/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-07-07T13:00:00Z","updated_at":"2016-07-12T14:27:27Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ad5f7bffb5dcd606c60e2e9bb0d9ca51826c9cef","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/snapcore/snapd/pulls/1507/commits","review_comments_url":"https://api.github.com/repos/snapcore/snapd/pulls/1507/comments","review_comment_url":"https://api.github.com/repos/snapcore/snapd/pulls/comments{/number}","comments_url":"https://api.github.com/repos/snapcore/snapd/issues/1507/comments","statuses_url":"https://api.github.com/repos/snapcore/snapd/statuses/fcdc350df5833bc2389b559f7aa7ad40715660af","head":{"label":"pete-woods:buy-command","ref":"buy-command","sha":"fcdc350df5833bc2389b559f7aa7ad40715660af","user":{"login":"pete-woods","id":152569,"avatar_url":"https://avatars.githubusercontent.com/u/152569?v=3","gravatar_id":"","url":"https://api.github.com/users/pete-woods","html_url":"https://github.com/pete-woods","followers_url":"https://api.github.com/users/pete-woods/followers","following_url":"https://api.github.com/users/pete-woods/following{/other_user}","gists_url":"https://api.github.com/users/pete-woods/gists{/gist_id}","starred_url":"https://api.github.com/users/pete-woods/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pete-woods/subscriptions","organizations_url":"https://api.github.com/users/pete-woods/orgs","repos_url":"https://api.github.com/users/pete-woods/repos","events_url":"https://api.github.com/users/pete-woods/events{/privacy}","received_events_url":"https://api.github.com/users/pete-woods/received_events","type":"User","site_admin":false},"repo":{"id":51448306,"name":"snapd","full_name":"pete-woods/snapd","owner":{"login":"pete-woods","id":152569,"avatar_url":"https://avatars.githubusercontent.com/u/152569?v=3","gravatar_id":"","url":"https://api.github.com/users/pete-woods","html_url":"https://github.com/pete-woods","followers_url":"https://api.github.com/users/pete-woods/followers","following_url":"https://api.github.com/users/pete-woods/following{/other_user}","gists_url":"https://api.github.com/users/pete-woods/gists{/gist_id}","starred_url":"https://api.github.com/users/pete-woods/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/pete-woods/subscriptions","organizations_url":"https://api.github.com/users/pete-woods/orgs","repos_url":"https://api.github.com/users/pete-woods/repos","events_url":"https://api.github.com/users/pete-woods/events{/privacy}","received_events_url":"https://api.github.com/users/pete-woods/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/pete-woods/snapd","description":"Snappy is the software at the heart of Ubuntu Core.","fork":true,"url":"https://api.github.com/repos/pete-woods/snapd","forks_url":"https://api.github.com/repos/pete-woods/snapd/forks","keys_url":"https://api.github.com/repos/pete-woods/snapd/keys{/key_id}","collaborators_url":"https://api.github.com/repos/pete-woods/snapd/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/pete-woods/snapd/teams","hooks_url":"https://api.github.com/repos/pete-woods/snapd/hooks","issue_events_url":"https://api.github.com/repos/pete-woods/snapd/issues/events{/number}","events_url":"https://api.github.com/repos/pete-woods/snapd/events","assignees_url":"https://api.github.com/repos/pete-woods/snapd/assignees{/user}","branches_url":"https://api.github.com/repos/pete-woods/snapd/branches{/branch}","tags_url":"https://api.github.com/repos/pete-woods/snapd/tags","blobs_url":"https://api.github.com/repos/pete-woods/snapd/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/pete-woods/snapd/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/pete-woods/snapd/git/refs{/sha}","trees_url":"https://api.github.com/repos/pete-woods/snapd/git/trees{/sha}","statuses_url":"https://api.github.com/repos/pete-woods/snapd/statuses/{sha}","languages_url":"https://api.github.com/repos/pete-woods/snapd/languages","stargazers_url":"https://api.github.com/repos/pete-woods/snapd/stargazers","contributors_url":"https://api.github.com/repos/pete-woods/snapd/contributors","subscribers_url":"https://api.github.com/repos/pete-woods/snapd/subscribers","subscription_url":"https://api.github.com/repos/pete-woods/snapd/subscription","commits_url":"https://api.github.com/repos/pete-woods/snapd/commits{/sha}","git_commits_url":"https://api.github.com/repos/pete-woods/snapd/git/commits{/sha}","comments_url":"https://api.github.com/repos/pete-woods/snapd/comments{/number}","issue_comment_url":"https://api.github.com/repos/pete-woods/snapd/issues/comments{/number}","contents_url":"https://api.github.com/repos/pete-woods/snapd/contents/{+path}","compare_url":"https://api.github.com/repos/pete-woods/snapd/compare/{base}...{head}","merges_url":"https://api.github.com/repos/pete-woods/snapd/merges","archive_url":"https://api.github.com/repos/pete-woods/snapd/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/pete-woods/snapd/downloads","issues_url":"https://api.github.com/repos/pete-woods/snapd/issues{/number}","pulls_url":"https://api.github.com/repos/pete-woods/snapd/pulls{/number}","milestones_url":"https://api.github.com/repos/pete-woods/snapd/milestones{/number}","notifications_url":"https://api.github.com/repos/pete-woods/snapd/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/pete-woods/snapd/labels{/name}","releases_url":"https://api.github.com/repos/pete-woods/snapd/releases{/id}","deployments_url":"https://api.github.com/repos/pete-woods/snapd/deployments","created_at":"2016-02-10T15:05:48Z","updated_at":"2016-05-25T07:36:15Z","pushed_at":"2016-07-12T13:15:20Z","git_url":"git://github.com/pete-woods/snapd.git","ssh_url":"git@github.com:pete-woods/snapd.git","clone_url":"https://github.com/pete-woods/snapd.git","svn_url":"https://github.com/pete-woods/snapd","homepage":null,"size":32331,"stargazers_count":0,"watchers_count":0,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"snapcore:master","ref":"master","sha":"5209693d264fb4eec99b191edaadc9a462b374ae","user":{"login":"snapcore","id":19532717,"avatar_url":"https://avatars.githubusercontent.com/u/19532717?v=3","gravatar_id":"","url":"https://api.github.com/users/snapcore","html_url":"https://github.com/snapcore","followers_url":"https://api.github.com/users/snapcore/followers","following_url":"https://api.github.com/users/snapcore/following{/other_user}","gists_url":"https://api.github.com/users/snapcore/gists{/gist_id}","starred_url":"https://api.github.com/users/snapcore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/snapcore/subscriptions","organizations_url":"https://api.github.com/users/snapcore/orgs","repos_url":"https://api.github.com/users/snapcore/repos","events_url":"https://api.github.com/users/snapcore/events{/privacy}","received_events_url":"https://api.github.com/users/snapcore/received_events","type":"Organization","site_admin":false},"repo":{"id":44672744,"name":"snapd","full_name":"snapcore/snapd","owner":{"login":"snapcore","id":19532717,"avatar_url":"https://avatars.githubusercontent.com/u/19532717?v=3","gravatar_id":"","url":"https://api.github.com/users/snapcore","html_url":"https://github.com/snapcore","followers_url":"https://api.github.com/users/snapcore/followers","following_url":"https://api.github.com/users/snapcore/following{/other_user}","gists_url":"https://api.github.com/users/snapcore/gists{/gist_id}","starred_url":"https://api.github.com/users/snapcore/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/snapcore/subscriptions","organizations_url":"https://api.github.com/users/snapcore/orgs","repos_url":"https://api.github.com/users/snapcore/repos","events_url":"https://api.github.com/users/snapcore/events{/privacy}","received_events_url":"https://api.github.com/users/snapcore/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/snapcore/snapd","description":"The snapd and snap tools enable systems to work with .snap files.","fork":false,"url":"https://api.github.com/repos/snapcore/snapd","forks_url":"https://api.github.com/repos/snapcore/snapd/forks","keys_url":"https://api.github.com/repos/snapcore/snapd/keys{/key_id}","collaborators_url":"https://api.github.com/repos/snapcore/snapd/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/snapcore/snapd/teams","hooks_url":"https://api.github.com/repos/snapcore/snapd/hooks","issue_events_url":"https://api.github.com/repos/snapcore/snapd/issues/events{/number}","events_url":"https://api.github.com/repos/snapcore/snapd/events","assignees_url":"https://api.github.com/repos/snapcore/snapd/assignees{/user}","branches_url":"https://api.github.com/repos/snapcore/snapd/branches{/branch}","tags_url":"https://api.github.com/repos/snapcore/snapd/tags","blobs_url":"https://api.github.com/repos/snapcore/snapd/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/snapcore/snapd/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/snapcore/snapd/git/refs{/sha}","trees_url":"https://api.github.com/repos/snapcore/snapd/git/trees{/sha}","statuses_url":"https://api.github.com/repos/snapcore/snapd/statuses/{sha}","languages_url":"https://api.github.com/repos/snapcore/snapd/languages","stargazers_url":"https://api.github.com/repos/snapcore/snapd/stargazers","contributors_url":"https://api.github.com/repos/snapcore/snapd/contributors","subscribers_url":"https://api.github.com/repos/snapcore/snapd/subscribers","subscription_url":"https://api.github.com/repos/snapcore/snapd/subscription","commits_url":"https://api.github.com/repos/snapcore/snapd/commits{/sha}","git_commits_url":"https://api.github.com/repos/snapcore/snapd/git/commits{/sha}","comments_url":"https://api.github.com/repos/snapcore/snapd/comments{/number}","issue_comment_url":"https://api.github.com/repos/snapcore/snapd/issues/comments{/number}","contents_url":"https://api.github.com/repos/snapcore/snapd/contents/{+path}","compare_url":"https://api.github.com/repos/snapcore/snapd/compare/{base}...{head}","merges_url":"https://api.github.com/repos/snapcore/snapd/merges","archive_url":"https://api.github.com/repos/snapcore/snapd/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/snapcore/snapd/downloads","issues_url":"https://api.github.com/repos/snapcore/snapd/issues{/number}","pulls_url":"https://api.github.com/repos/snapcore/snapd/pulls{/number}","milestones_url":"https://api.github.com/repos/snapcore/snapd/milestones{/number}","notifications_url":"https://api.github.com/repos/snapcore/snapd/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/snapcore/snapd/labels{/name}","releases_url":"https://api.github.com/repos/snapcore/snapd/releases{/id}","deployments_url":"https://api.github.com/repos/snapcore/snapd/deployments","created_at":"2015-10-21T11:51:46Z","updated_at":"2016-07-12T03:56:00Z","pushed_at":"2016-07-12T14:17:20Z","git_url":"git://github.com/snapcore/snapd.git","ssh_url":"git@github.com:snapcore/snapd.git","clone_url":"https://github.com/snapcore/snapd.git","svn_url":"https://github.com/snapcore/snapd","homepage":"","size":34351,"stargazers_count":352,"watchers_count":352,"language":"Go","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":67,"mirror_url":null,"open_issues_count":35,"forks":67,"open_issues":35,"watchers":352,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/snapcore/snapd/pulls/1507"},"html":{"href":"https://github.com/snapcore/snapd/pull/1507"},"issue":{"href":"https://api.github.com/repos/snapcore/snapd/issues/1507"},"comments":{"href":"https://api.github.com/repos/snapcore/snapd/issues/1507/comments"},"review_comments":{"href":"https://api.github.com/repos/snapcore/snapd/pulls/1507/comments"},"review_comment":{"href":"https://api.github.com/repos/snapcore/snapd/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/snapcore/snapd/pulls/1507/commits"},"statuses":{"href":"https://api.github.com/repos/snapcore/snapd/statuses/fcdc350df5833bc2389b559f7aa7ad40715660af"}}}}
{"actor":{"display_login":"niemeyer"}}