{"action":"created","comment":{"url":"https://api.github.com/repos/coderly/code/pulls/comments/28434232","id":28434232,"diff_hunk":"@@ -20,7 +20,13 @@ def open_in_browser(url)\n     end\n \n     def open(item)\n-      `open #{item}`\n+      if (/darwin/ =~ RUBY_PLATFORM) != nil","path":"lib/code/system.rb","position":5,"original_position":5,"commit_id":"8735899ad6db53cf707d128bec17ea448781351f","original_commit_id":"8735899ad6db53cf707d128bec17ea448781351f","user":{"login":"venkatd","id":220686,"avatar_url":"https://avatars.githubusercontent.com/u/220686?v=3","gravatar_id":"","url":"https://api.github.com/users/venkatd","html_url":"https://github.com/venkatd","followers_url":"https://api.github.com/users/venkatd/followers","following_url":"https://api.github.com/users/venkatd/following{/other_user}","gists_url":"https://api.github.com/users/venkatd/gists{/gist_id}","starred_url":"https://api.github.com/users/venkatd/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/venkatd/subscriptions","organizations_url":"https://api.github.com/users/venkatd/orgs","repos_url":"https://api.github.com/users/venkatd/repos","events_url":"https://api.github.com/users/venkatd/events{/privacy}","received_events_url":"https://api.github.com/users/venkatd/received_events","type":"User","site_admin":false},"body":"This doesn't follow what-do-I-want","created_at":"2015-04-15T16:01:14Z","updated_at":"2015-04-15T16:01:14Z","html_url":"https://github.com/coderly/code/pull/9#discussion_r28434232","pull_request_url":"https://api.github.com/repos/coderly/code/pulls/9","_links":{"self":{"href":"https://api.github.com/repos/coderly/code/pulls/comments/28434232"},"html":{"href":"https://github.com/coderly/code/pull/9#discussion_r28434232"},"pull_request":{"href":"https://api.github.com/repos/coderly/code/pulls/9"}}},"pull_request":{"url":"https://api.github.com/repos/coderly/code/pulls/9","id":33139505,"html_url":"https://github.com/coderly/code/pull/9","diff_url":"https://github.com/coderly/code/pull/9.diff","patch_url":"https://github.com/coderly/code/pull/9.patch","issue_url":"https://api.github.com/repos/coderly/code/issues/9","number":9,"state":"open","locked":false,"title":"Implement \"code pr\" opening an existing pull request if one exists","user":{"login":"begedin","id":1925540,"avatar_url":"https://avatars.githubusercontent.com/u/1925540?v=3","gravatar_id":"","url":"https://api.github.com/users/begedin","html_url":"https://github.com/begedin","followers_url":"https://api.github.com/users/begedin/followers","following_url":"https://api.github.com/users/begedin/following{/other_user}","gists_url":"https://api.github.com/users/begedin/gists{/gist_id}","starred_url":"https://api.github.com/users/begedin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/begedin/subscriptions","organizations_url":"https://api.github.com/users/begedin/orgs","repos_url":"https://api.github.com/users/begedin/repos","events_url":"https://api.github.com/users/begedin/events{/privacy}","received_events_url":"https://api.github.com/users/begedin/received_events","type":"User","site_admin":false},"body":"## Description\r\n\r\nBranching off of PR #8 to avoid potential trouble and to have something to make a PR out of (for testing). Nothing is implemented yet. In hindsight, this wasn't actually necessary.\r\n\r\nThe actuall changes are in \r\n* `Gemfile` - new gem\r\n* `bin/code` - new `authorize` command, modification of the `publish` command\r\n* `lib/github_api.rb` - new class for communicating with the GitHub API via the octokit gem.\r\n\r\nUnfortunately, there is no simple way to find a PR from the command-line or via `hub`.  The only way this seems to be possible is through the GitHub API.\r\n\r\nI actually contacted github and was promptly answered that this is exactly the case:\r\n\r\n>Yep, that's possible, but you need to use the API:\r\n\r\n>https://developer.github.com/v3/pulls/#list-pull-requests\r\n\r\n>Notice that you can specify the head and/or the base branch for that API endpoint in the query parameters, which allows you to fetch the list of pull requests for those branches.\r\n\r\n>E.g. here's the pull request for the push-changes branch in github/linguist\r\n\r\n>https://api.github.com/repos/github/linguist/pulls?head=github:push-changes\r\n\r\n>Does that help?\r\n\r\nSince that would mean we'd have to handle authentication on code side instead of relying on `hub` authentication, I found a gem called [github_api](https://github.com/peter-murach/github) as well as one called [octokit](https://github.com/octokit/octokit.rb). \r\n\r\nAfter some testing, I decided to go with the second one. It seems more developed and more robust than the first.\r\n\r\n\r\n## Issues\r\n\r\nUnfortunately, I have difficulties with code due to using linux, which I haven't realized I had before.\r\n\r\n* The `open` console command does something on linux different compared to mac. The correct command to be used on my system is ˙xdg-open`, but some linux systems also have `gnome-open` and other variations.\r\n\r\n* When doing a `code pr` to create a new pull request, hub prompts for username and password, it seems, but there's no actual prompt in the console for me. It just hangs there, allowing input, but not indicating what that input is. If I try typing in my credentials, I get various errors, but I haven't yet figured out how and what to type in to get past it.\r\n\r\nBasically, code has issues on linux :)\r\n\r\n## Flow\r\n\r\nTo elaborate, with this feature, the user is required to log in once, using \r\n\r\n```\r\ncode authorize --username \"username\" --password \"password\"\r\n```\r\n\r\nAfter that an oauth token will be created and stored into the global .gitconfig file. The token will be used to fetch and the proper pull request url and open it in browser.\r\n\r\nI don't see a way around this, but I'm thinking there should also be a prompt in that case, to ask for credentials if `code pr` was called before `code authorize` being called first. Either that, or we make `code pr` accept a `--username` and `--password` option to and call `authorize` internally if it's needed and the options are provided, displaying an error otherwise.\r\n\r\nBasically\r\n\r\n* User calls `code pr`\r\n* PR doesn't exist -> PR is created\r\n* PR exists\r\n  * If code is already authorized, open PR\r\n  * If code is not already authorized\r\n    * **Solution A** - user needs to pass in `--username` and `--password` with `code pr`. Authorization runs. If options are not passed in, code shows an error with the instruction to pass them in.\r\n     * **Solution B** - user is prompted for username and password directly and then authorize gets called before code pr is fetched and open. I'm not sure how simple this is to implement.\r\n\r\n**NOTE**: I decided to go with Solution A for the time being. It's faster to implement and more typical of command line behavior.\r\n","created_at":"2015-04-13T06:54:44Z","updated_at":"2015-04-15T16:01:14Z","closed_at":null,"merged_at":null,"merge_commit_sha":"45528b50648e951d6dc8d8653f3706a1301a88df","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/coderly/code/pulls/9/commits","review_comments_url":"https://api.github.com/repos/coderly/code/pulls/9/comments","review_comment_url":"https://api.github.com/repos/coderly/code/pulls/comments{/number}","comments_url":"https://api.github.com/repos/coderly/code/issues/9/comments","statuses_url":"https://api.github.com/repos/coderly/code/statuses/8735899ad6db53cf707d128bec17ea448781351f","head":{"label":"coderly:implement-open-pr","ref":"implement-open-pr","sha":"8735899ad6db53cf707d128bec17ea448781351f","user":{"login":"coderly","id":2837781,"avatar_url":"https://avatars.githubusercontent.com/u/2837781?v=3","gravatar_id":"","url":"https://api.github.com/users/coderly","html_url":"https://github.com/coderly","followers_url":"https://api.github.com/users/coderly/followers","following_url":"https://api.github.com/users/coderly/following{/other_user}","gists_url":"https://api.github.com/users/coderly/gists{/gist_id}","starred_url":"https://api.github.com/users/coderly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coderly/subscriptions","organizations_url":"https://api.github.com/users/coderly/orgs","repos_url":"https://api.github.com/users/coderly/repos","events_url":"https://api.github.com/users/coderly/events{/privacy}","received_events_url":"https://api.github.com/users/coderly/received_events","type":"Organization","site_admin":false},"repo":{"id":12915119,"name":"code","full_name":"coderly/code","owner":{"login":"coderly","id":2837781,"avatar_url":"https://avatars.githubusercontent.com/u/2837781?v=3","gravatar_id":"","url":"https://api.github.com/users/coderly","html_url":"https://github.com/coderly","followers_url":"https://api.github.com/users/coderly/followers","following_url":"https://api.github.com/users/coderly/following{/other_user}","gists_url":"https://api.github.com/users/coderly/gists{/gist_id}","starred_url":"https://api.github.com/users/coderly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coderly/subscriptions","organizations_url":"https://api.github.com/users/coderly/orgs","repos_url":"https://api.github.com/users/coderly/repos","events_url":"https://api.github.com/users/coderly/events{/privacy}","received_events_url":"https://api.github.com/users/coderly/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/coderly/code","description":"The coder.ly toolbelt","fork":false,"url":"https://api.github.com/repos/coderly/code","forks_url":"https://api.github.com/repos/coderly/code/forks","keys_url":"https://api.github.com/repos/coderly/code/keys{/key_id}","collaborators_url":"https://api.github.com/repos/coderly/code/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/coderly/code/teams","hooks_url":"https://api.github.com/repos/coderly/code/hooks","issue_events_url":"https://api.github.com/repos/coderly/code/issues/events{/number}","events_url":"https://api.github.com/repos/coderly/code/events","assignees_url":"https://api.github.com/repos/coderly/code/assignees{/user}","branches_url":"https://api.github.com/repos/coderly/code/branches{/branch}","tags_url":"https://api.github.com/repos/coderly/code/tags","blobs_url":"https://api.github.com/repos/coderly/code/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/coderly/code/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/coderly/code/git/refs{/sha}","trees_url":"https://api.github.com/repos/coderly/code/git/trees{/sha}","statuses_url":"https://api.github.com/repos/coderly/code/statuses/{sha}","languages_url":"https://api.github.com/repos/coderly/code/languages","stargazers_url":"https://api.github.com/repos/coderly/code/stargazers","contributors_url":"https://api.github.com/repos/coderly/code/contributors","subscribers_url":"https://api.github.com/repos/coderly/code/subscribers","subscription_url":"https://api.github.com/repos/coderly/code/subscription","commits_url":"https://api.github.com/repos/coderly/code/commits{/sha}","git_commits_url":"https://api.github.com/repos/coderly/code/git/commits{/sha}","comments_url":"https://api.github.com/repos/coderly/code/comments{/number}","issue_comment_url":"https://api.github.com/repos/coderly/code/issues/comments{/number}","contents_url":"https://api.github.com/repos/coderly/code/contents/{+path}","compare_url":"https://api.github.com/repos/coderly/code/compare/{base}...{head}","merges_url":"https://api.github.com/repos/coderly/code/merges","archive_url":"https://api.github.com/repos/coderly/code/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/coderly/code/downloads","issues_url":"https://api.github.com/repos/coderly/code/issues{/number}","pulls_url":"https://api.github.com/repos/coderly/code/pulls{/number}","milestones_url":"https://api.github.com/repos/coderly/code/milestones{/number}","notifications_url":"https://api.github.com/repos/coderly/code/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/coderly/code/labels{/name}","releases_url":"https://api.github.com/repos/coderly/code/releases{/id}","created_at":"2013-09-18T05:46:40Z","updated_at":"2015-03-11T21:57:00Z","pushed_at":"2015-04-15T14:55:41Z","git_url":"git://github.com/coderly/code.git","ssh_url":"git@github.com:coderly/code.git","clone_url":"https://github.com/coderly/code.git","svn_url":"https://github.com/coderly/code","homepage":null,"size":346,"stargazers_count":1,"watchers_count":1,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":5,"forks":0,"open_issues":5,"watchers":1,"default_branch":"master"}},"base":{"label":"coderly:master","ref":"master","sha":"1cd4dee42eaf985fe9740cd38108a95ca299892f","user":{"login":"coderly","id":2837781,"avatar_url":"https://avatars.githubusercontent.com/u/2837781?v=3","gravatar_id":"","url":"https://api.github.com/users/coderly","html_url":"https://github.com/coderly","followers_url":"https://api.github.com/users/coderly/followers","following_url":"https://api.github.com/users/coderly/following{/other_user}","gists_url":"https://api.github.com/users/coderly/gists{/gist_id}","starred_url":"https://api.github.com/users/coderly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coderly/subscriptions","organizations_url":"https://api.github.com/users/coderly/orgs","repos_url":"https://api.github.com/users/coderly/repos","events_url":"https://api.github.com/users/coderly/events{/privacy}","received_events_url":"https://api.github.com/users/coderly/received_events","type":"Organization","site_admin":false},"repo":{"id":12915119,"name":"code","full_name":"coderly/code","owner":{"login":"coderly","id":2837781,"avatar_url":"https://avatars.githubusercontent.com/u/2837781?v=3","gravatar_id":"","url":"https://api.github.com/users/coderly","html_url":"https://github.com/coderly","followers_url":"https://api.github.com/users/coderly/followers","following_url":"https://api.github.com/users/coderly/following{/other_user}","gists_url":"https://api.github.com/users/coderly/gists{/gist_id}","starred_url":"https://api.github.com/users/coderly/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coderly/subscriptions","organizations_url":"https://api.github.com/users/coderly/orgs","repos_url":"https://api.github.com/users/coderly/repos","events_url":"https://api.github.com/users/coderly/events{/privacy}","received_events_url":"https://api.github.com/users/coderly/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/coderly/code","description":"The coder.ly toolbelt","fork":false,"url":"https://api.github.com/repos/coderly/code","forks_url":"https://api.github.com/repos/coderly/code/forks","keys_url":"https://api.github.com/repos/coderly/code/keys{/key_id}","collaborators_url":"https://api.github.com/repos/coderly/code/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/coderly/code/teams","hooks_url":"https://api.github.com/repos/coderly/code/hooks","issue_events_url":"https://api.github.com/repos/coderly/code/issues/events{/number}","events_url":"https://api.github.com/repos/coderly/code/events","assignees_url":"https://api.github.com/repos/coderly/code/assignees{/user}","branches_url":"https://api.github.com/repos/coderly/code/branches{/branch}","tags_url":"https://api.github.com/repos/coderly/code/tags","blobs_url":"https://api.github.com/repos/coderly/code/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/coderly/code/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/coderly/code/git/refs{/sha}","trees_url":"https://api.github.com/repos/coderly/code/git/trees{/sha}","statuses_url":"https://api.github.com/repos/coderly/code/statuses/{sha}","languages_url":"https://api.github.com/repos/coderly/code/languages","stargazers_url":"https://api.github.com/repos/coderly/code/stargazers","contributors_url":"https://api.github.com/repos/coderly/code/contributors","subscribers_url":"https://api.github.com/repos/coderly/code/subscribers","subscription_url":"https://api.github.com/repos/coderly/code/subscription","commits_url":"https://api.github.com/repos/coderly/code/commits{/sha}","git_commits_url":"https://api.github.com/repos/coderly/code/git/commits{/sha}","comments_url":"https://api.github.com/repos/coderly/code/comments{/number}","issue_comment_url":"https://api.github.com/repos/coderly/code/issues/comments{/number}","contents_url":"https://api.github.com/repos/coderly/code/contents/{+path}","compare_url":"https://api.github.com/repos/coderly/code/compare/{base}...{head}","merges_url":"https://api.github.com/repos/coderly/code/merges","archive_url":"https://api.github.com/repos/coderly/code/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/coderly/code/downloads","issues_url":"https://api.github.com/repos/coderly/code/issues{/number}","pulls_url":"https://api.github.com/repos/coderly/code/pulls{/number}","milestones_url":"https://api.github.com/repos/coderly/code/milestones{/number}","notifications_url":"https://api.github.com/repos/coderly/code/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/coderly/code/labels{/name}","releases_url":"https://api.github.com/repos/coderly/code/releases{/id}","created_at":"2013-09-18T05:46:40Z","updated_at":"2015-03-11T21:57:00Z","pushed_at":"2015-04-15T14:55:41Z","git_url":"git://github.com/coderly/code.git","ssh_url":"git@github.com:coderly/code.git","clone_url":"https://github.com/coderly/code.git","svn_url":"https://github.com/coderly/code","homepage":null,"size":346,"stargazers_count":1,"watchers_count":1,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":5,"forks":0,"open_issues":5,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/coderly/code/pulls/9"},"html":{"href":"https://github.com/coderly/code/pull/9"},"issue":{"href":"https://api.github.com/repos/coderly/code/issues/9"},"comments":{"href":"https://api.github.com/repos/coderly/code/issues/9/comments"},"review_comments":{"href":"https://api.github.com/repos/coderly/code/pulls/9/comments"},"review_comment":{"href":"https://api.github.com/repos/coderly/code/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/coderly/code/pulls/9/commits"},"statuses":{"href":"https://api.github.com/repos/coderly/code/statuses/8735899ad6db53cf707d128bec17ea448781351f"}}}}