{"action":"created","comment":{"url":"https://api.github.com/repos/jspm/github/pulls/comments/73158469","id":73158469,"diff_hunk":"@@ -338,56 +317,124 @@ GithubLocation.prototype = {\n   // { versions: { versionhash } }\n   // { notfound: true }\n   lookup: function(repo) {\n-    var execOpt = this.execOpt;\n+    var self = this;\n     var remoteString = this.remoteString;\n-    return new Promise(function(resolve, reject) {\n-      execGit('ls-remote ' + remoteString.replace(/(['\"()])/g, '\\\\\\$1') + repo + '.git refs/tags/* refs/heads/*', execOpt, function(err, stdout, stderr) {\n-        if (err) {\n-          if (err.toString().indexOf('not found') == -1) {\n-            var error = new Error(stderr);\n-            error.hideStack = true;\n-            error.retriable = true;\n-            reject(error);\n-          }\n+\n+    return Promise.resolve()\n+    .then(function() {\n+      if (self.auth && self.auth.token) {\n+        // use API to get branches/tags\n+        return Promise.all(['tags', 'heads'].map(function(type) {\n+          return asp(request)(extend({\n+            uri: self.apiRemoteString + 'repos/' + repo + '/git/refs/' + type + self.authSuffix,\n+            headers: {\n+              'Accept': 'application/vnd.github.v3.raw'\n+            }\n+          }, self.defaultRequestOptions));\n+        })).then(function(responses) {\n+          var tagRes = responses[0];\n+          var headRes = responses[1];\n+\n+          var refs = [];\n+\n+          // there should always be heads\n+          if (headRes.statusCode != 200)\n+            throw { statusCode: headRes.statusCode, headers: headRes.headers, api: true };\n           else\n-            resolve({ notfound: true });\n-        }\n+            refs = refs.concat(JSON.parse(headRes.body));\n+\n+          // tag response can be 404, i.e. no tags\n+          if (tagRes.statusCode == 200)\n+            refs = refs.concat(JSON.parse(tagRes.body));\n+          else if (tagRes.statusCode != 404)\n+            throw { statusCode: tagRes.statusCode, headers: tagRes.headers, api: true };\n \n-        versions = {};\n-        var refs = stdout.split('\\n');\n-        for (var i = 0; i < refs.length; i++) {\n-          if (!refs[i])\n-            continue;\n+          return refs.map(function(obj) {\n+            return { sha: obj.object.sha, name: obj.ref };\n+          });\n+        });\n+      } else {\n+        // fallback to git-based approach\n+        return false;\n+      }\n+    })\n+    .catch(function(e) {\n+      if (e.headers && e.headers['x-ratelimit-remaining'] == '0') {\n+        if (!apiWarned) {\n+          ui.log('API ratelimit reached, falling back to slower git protocol');","path":"github.js","position":161,"original_position":161,"commit_id":"fd64ea430404712fee7447a3f67f2a556d982853","original_commit_id":"fd64ea430404712fee7447a3f67f2a556d982853","user":{"login":"guybedford","id":598730,"avatar_url":"https://avatars.githubusercontent.com/u/598730?v=3","gravatar_id":"","url":"https://api.github.com/users/guybedford","html_url":"https://github.com/guybedford","followers_url":"https://api.github.com/users/guybedford/followers","following_url":"https://api.github.com/users/guybedford/following{/other_user}","gists_url":"https://api.github.com/users/guybedford/gists{/gist_id}","starred_url":"https://api.github.com/users/guybedford/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/guybedford/subscriptions","organizations_url":"https://api.github.com/users/guybedford/orgs","repos_url":"https://api.github.com/users/guybedford/repos","events_url":"https://api.github.com/users/guybedford/events{/privacy}","received_events_url":"https://api.github.com/users/guybedford/received_events","type":"User","site_admin":false},"body":"The original numbers you posted showed the git protocol as faster. Did it turn out the API is faster then?","created_at":"2016-08-02T13:53:14Z","updated_at":"2016-08-02T13:53:14Z","html_url":"https://github.com/jspm/github/pull/95#discussion_r73158469","pull_request_url":"https://api.github.com/repos/jspm/github/pulls/95","_links":{"self":{"href":"https://api.github.com/repos/jspm/github/pulls/comments/73158469"},"html":{"href":"https://github.com/jspm/github/pull/95#discussion_r73158469"},"pull_request":{"href":"https://api.github.com/repos/jspm/github/pulls/95"}}},"pull_request":{"url":"https://api.github.com/repos/jspm/github/pulls/95","id":76077482,"html_url":"https://github.com/jspm/github/pull/95","diff_url":"https://github.com/jspm/github/pull/95.diff","patch_url":"https://github.com/jspm/github/pull/95.patch","issue_url":"https://api.github.com/repos/jspm/github/issues/95","number":95,"state":"open","locked":false,"title":"[do not merge] use a pure node implementation of git ls-remote","user":{"login":"adamburgess","id":7473960,"avatar_url":"https://avatars.githubusercontent.com/u/7473960?v=3","gravatar_id":"","url":"https://api.github.com/users/adamburgess","html_url":"https://github.com/adamburgess","followers_url":"https://api.github.com/users/adamburgess/followers","following_url":"https://api.github.com/users/adamburgess/following{/other_user}","gists_url":"https://api.github.com/users/adamburgess/gists{/gist_id}","starred_url":"https://api.github.com/users/adamburgess/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adamburgess/subscriptions","organizations_url":"https://api.github.com/users/adamburgess/orgs","repos_url":"https://api.github.com/users/adamburgess/repos","events_url":"https://api.github.com/users/adamburgess/events{/privacy}","received_events_url":"https://api.github.com/users/adamburgess/received_events","type":"User","site_admin":false},"body":"continued on from #94 (which used a loosely cobbled together npm:js-git and npm:nogit), this one uses a library I just made, [npm:git-ls-remote-pure](https://github.com/adamburgess/git-ls-remote-pure). If you like, I can inline it in this PR instead of using an external library - it's a single file.\r\nimplementation is quite small, it fetches `https://github.com/user/repo.git/info/refs?service=git-upload-pack` and parses the response, which is what actual git does. this means no more git! (though jspm registry still uses git...)\r\n\r\nnow, onto the problems\r\nthe https git endpoint needs a username and password combo for private repositories (where password can/should be a token).\r\nthis was broken by #90 - and note, native git will also fail here.\r\n\r\nthis can be fixed in two ways\r\n* ask, once again, for username and token. Use token specifically for API requests, and use username + token for the locate hook.\r\n* do a one-time lookup \\<githup-api\\>/user and then read the `login` property, which contains the token's username","created_at":"2016-07-03T00:13:47Z","updated_at":"2016-08-02T13:53:14Z","closed_at":null,"merged_at":null,"merge_commit_sha":"daef6b016838b4e3bec08510706bf4aacf60f0e7","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/jspm/github/pulls/95/commits","review_comments_url":"https://api.github.com/repos/jspm/github/pulls/95/comments","review_comment_url":"https://api.github.com/repos/jspm/github/pulls/comments{/number}","comments_url":"https://api.github.com/repos/jspm/github/issues/95/comments","statuses_url":"https://api.github.com/repos/jspm/github/statuses/fd64ea430404712fee7447a3f67f2a556d982853","head":{"label":"adamburgess:js-git-take-2","ref":"js-git-take-2","sha":"fd64ea430404712fee7447a3f67f2a556d982853","user":{"login":"adamburgess","id":7473960,"avatar_url":"https://avatars.githubusercontent.com/u/7473960?v=3","gravatar_id":"","url":"https://api.github.com/users/adamburgess","html_url":"https://github.com/adamburgess","followers_url":"https://api.github.com/users/adamburgess/followers","following_url":"https://api.github.com/users/adamburgess/following{/other_user}","gists_url":"https://api.github.com/users/adamburgess/gists{/gist_id}","starred_url":"https://api.github.com/users/adamburgess/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adamburgess/subscriptions","organizations_url":"https://api.github.com/users/adamburgess/orgs","repos_url":"https://api.github.com/users/adamburgess/repos","events_url":"https://api.github.com/users/adamburgess/events{/privacy}","received_events_url":"https://api.github.com/users/adamburgess/received_events","type":"User","site_admin":false},"repo":{"id":62466482,"name":"github","full_name":"adamburgess/github","owner":{"login":"adamburgess","id":7473960,"avatar_url":"https://avatars.githubusercontent.com/u/7473960?v=3","gravatar_id":"","url":"https://api.github.com/users/adamburgess","html_url":"https://github.com/adamburgess","followers_url":"https://api.github.com/users/adamburgess/followers","following_url":"https://api.github.com/users/adamburgess/following{/other_user}","gists_url":"https://api.github.com/users/adamburgess/gists{/gist_id}","starred_url":"https://api.github.com/users/adamburgess/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/adamburgess/subscriptions","organizations_url":"https://api.github.com/users/adamburgess/orgs","repos_url":"https://api.github.com/users/adamburgess/repos","events_url":"https://api.github.com/users/adamburgess/events{/privacy}","received_events_url":"https://api.github.com/users/adamburgess/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/adamburgess/github","description":"Github Location Service","fork":true,"url":"https://api.github.com/repos/adamburgess/github","forks_url":"https://api.github.com/repos/adamburgess/github/forks","keys_url":"https://api.github.com/repos/adamburgess/github/keys{/key_id}","collaborators_url":"https://api.github.com/repos/adamburgess/github/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/adamburgess/github/teams","hooks_url":"https://api.github.com/repos/adamburgess/github/hooks","issue_events_url":"https://api.github.com/repos/adamburgess/github/issues/events{/number}","events_url":"https://api.github.com/repos/adamburgess/github/events","assignees_url":"https://api.github.com/repos/adamburgess/github/assignees{/user}","branches_url":"https://api.github.com/repos/adamburgess/github/branches{/branch}","tags_url":"https://api.github.com/repos/adamburgess/github/tags","blobs_url":"https://api.github.com/repos/adamburgess/github/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/adamburgess/github/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/adamburgess/github/git/refs{/sha}","trees_url":"https://api.github.com/repos/adamburgess/github/git/trees{/sha}","statuses_url":"https://api.github.com/repos/adamburgess/github/statuses/{sha}","languages_url":"https://api.github.com/repos/adamburgess/github/languages","stargazers_url":"https://api.github.com/repos/adamburgess/github/stargazers","contributors_url":"https://api.github.com/repos/adamburgess/github/contributors","subscribers_url":"https://api.github.com/repos/adamburgess/github/subscribers","subscription_url":"https://api.github.com/repos/adamburgess/github/subscription","commits_url":"https://api.github.com/repos/adamburgess/github/commits{/sha}","git_commits_url":"https://api.github.com/repos/adamburgess/github/git/commits{/sha}","comments_url":"https://api.github.com/repos/adamburgess/github/comments{/number}","issue_comment_url":"https://api.github.com/repos/adamburgess/github/issues/comments{/number}","contents_url":"https://api.github.com/repos/adamburgess/github/contents/{+path}","compare_url":"https://api.github.com/repos/adamburgess/github/compare/{base}...{head}","merges_url":"https://api.github.com/repos/adamburgess/github/merges","archive_url":"https://api.github.com/repos/adamburgess/github/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/adamburgess/github/downloads","issues_url":"https://api.github.com/repos/adamburgess/github/issues{/number}","pulls_url":"https://api.github.com/repos/adamburgess/github/pulls{/number}","milestones_url":"https://api.github.com/repos/adamburgess/github/milestones{/number}","notifications_url":"https://api.github.com/repos/adamburgess/github/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/adamburgess/github/labels{/name}","releases_url":"https://api.github.com/repos/adamburgess/github/releases{/id}","deployments_url":"https://api.github.com/repos/adamburgess/github/deployments","created_at":"2016-07-02T19:20:51Z","updated_at":"2016-07-02T19:20:53Z","pushed_at":"2016-08-02T03:43:26Z","git_url":"git://github.com/adamburgess/github.git","ssh_url":"git@github.com:adamburgess/github.git","clone_url":"https://github.com/adamburgess/github.git","svn_url":"https://github.com/adamburgess/github","homepage":"","size":249,"stargazers_count":0,"watchers_count":0,"language":"JavaScript","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":"jspm:0.17","ref":"0.17","sha":"3ea3febfe8cebd4b114e5c4dc5ad83b67e3c512e","user":{"login":"jspm","id":3802108,"avatar_url":"https://avatars.githubusercontent.com/u/3802108?v=3","gravatar_id":"","url":"https://api.github.com/users/jspm","html_url":"https://github.com/jspm","followers_url":"https://api.github.com/users/jspm/followers","following_url":"https://api.github.com/users/jspm/following{/other_user}","gists_url":"https://api.github.com/users/jspm/gists{/gist_id}","starred_url":"https://api.github.com/users/jspm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jspm/subscriptions","organizations_url":"https://api.github.com/users/jspm/orgs","repos_url":"https://api.github.com/users/jspm/repos","events_url":"https://api.github.com/users/jspm/events{/privacy}","received_events_url":"https://api.github.com/users/jspm/received_events","type":"Organization","site_admin":false},"repo":{"id":12779357,"name":"github","full_name":"jspm/github","owner":{"login":"jspm","id":3802108,"avatar_url":"https://avatars.githubusercontent.com/u/3802108?v=3","gravatar_id":"","url":"https://api.github.com/users/jspm","html_url":"https://github.com/jspm","followers_url":"https://api.github.com/users/jspm/followers","following_url":"https://api.github.com/users/jspm/following{/other_user}","gists_url":"https://api.github.com/users/jspm/gists{/gist_id}","starred_url":"https://api.github.com/users/jspm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jspm/subscriptions","organizations_url":"https://api.github.com/users/jspm/orgs","repos_url":"https://api.github.com/users/jspm/repos","events_url":"https://api.github.com/users/jspm/events{/privacy}","received_events_url":"https://api.github.com/users/jspm/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/jspm/github","description":"Github Location Service","fork":false,"url":"https://api.github.com/repos/jspm/github","forks_url":"https://api.github.com/repos/jspm/github/forks","keys_url":"https://api.github.com/repos/jspm/github/keys{/key_id}","collaborators_url":"https://api.github.com/repos/jspm/github/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/jspm/github/teams","hooks_url":"https://api.github.com/repos/jspm/github/hooks","issue_events_url":"https://api.github.com/repos/jspm/github/issues/events{/number}","events_url":"https://api.github.com/repos/jspm/github/events","assignees_url":"https://api.github.com/repos/jspm/github/assignees{/user}","branches_url":"https://api.github.com/repos/jspm/github/branches{/branch}","tags_url":"https://api.github.com/repos/jspm/github/tags","blobs_url":"https://api.github.com/repos/jspm/github/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/jspm/github/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/jspm/github/git/refs{/sha}","trees_url":"https://api.github.com/repos/jspm/github/git/trees{/sha}","statuses_url":"https://api.github.com/repos/jspm/github/statuses/{sha}","languages_url":"https://api.github.com/repos/jspm/github/languages","stargazers_url":"https://api.github.com/repos/jspm/github/stargazers","contributors_url":"https://api.github.com/repos/jspm/github/contributors","subscribers_url":"https://api.github.com/repos/jspm/github/subscribers","subscription_url":"https://api.github.com/repos/jspm/github/subscription","commits_url":"https://api.github.com/repos/jspm/github/commits{/sha}","git_commits_url":"https://api.github.com/repos/jspm/github/git/commits{/sha}","comments_url":"https://api.github.com/repos/jspm/github/comments{/number}","issue_comment_url":"https://api.github.com/repos/jspm/github/issues/comments{/number}","contents_url":"https://api.github.com/repos/jspm/github/contents/{+path}","compare_url":"https://api.github.com/repos/jspm/github/compare/{base}...{head}","merges_url":"https://api.github.com/repos/jspm/github/merges","archive_url":"https://api.github.com/repos/jspm/github/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/jspm/github/downloads","issues_url":"https://api.github.com/repos/jspm/github/issues{/number}","pulls_url":"https://api.github.com/repos/jspm/github/pulls{/number}","milestones_url":"https://api.github.com/repos/jspm/github/milestones{/number}","notifications_url":"https://api.github.com/repos/jspm/github/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/jspm/github/labels{/name}","releases_url":"https://api.github.com/repos/jspm/github/releases{/id}","deployments_url":"https://api.github.com/repos/jspm/github/deployments","created_at":"2013-09-12T09:02:24Z","updated_at":"2016-06-29T12:42:47Z","pushed_at":"2016-08-02T03:43:26Z","git_url":"git://github.com/jspm/github.git","ssh_url":"git@github.com:jspm/github.git","clone_url":"https://github.com/jspm/github.git","svn_url":"https://github.com/jspm/github","homepage":"","size":261,"stargazers_count":11,"watchers_count":11,"language":"JavaScript","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":22,"mirror_url":null,"open_issues_count":14,"forks":22,"open_issues":14,"watchers":11,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/jspm/github/pulls/95"},"html":{"href":"https://github.com/jspm/github/pull/95"},"issue":{"href":"https://api.github.com/repos/jspm/github/issues/95"},"comments":{"href":"https://api.github.com/repos/jspm/github/issues/95/comments"},"review_comments":{"href":"https://api.github.com/repos/jspm/github/pulls/95/comments"},"review_comment":{"href":"https://api.github.com/repos/jspm/github/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/jspm/github/pulls/95/commits"},"statuses":{"href":"https://api.github.com/repos/jspm/github/statuses/fd64ea430404712fee7447a3f67f2a556d982853"}}}}
{"actor":{"display_login":"guybedford"}}