|
145 | 145 | // ------- |
146 | 146 |
|
147 | 147 | this.orgs = function(cb) { |
148 | | - _request("GET", '/user/orgs', null, function(err, res) { |
149 | | - cb(err, res); |
| 148 | + _request("GET", '/user/orgs', null, function(err, res, xhr) { |
| 149 | + cb(err, res, xhr); |
150 | 150 | }); |
151 | 151 | }; |
152 | 152 |
|
153 | 153 | // List authenticated user's gists |
154 | 154 | // ------- |
155 | 155 |
|
156 | 156 | this.gists = function(cb) { |
157 | | - _request("GET", '/gists', null, function(err, res) { |
158 | | - cb(err,res); |
| 157 | + _request("GET", '/gists', null, function(err, res, xhr) { |
| 158 | + cb(err,res, xhr); |
159 | 159 | }); |
160 | 160 | }; |
161 | 161 |
|
|
196 | 196 | if (params.length > 0) { |
197 | 197 | url += '?' + params.join('&'); |
198 | 198 | } |
199 | | - _request("GET", url, null, function(err, res) { |
200 | | - cb(err,res); |
| 199 | + _request("GET", url, null, function(err, res, xhr) { |
| 200 | + cb(err,res,xhr); |
201 | 201 | }); |
202 | 202 | }; |
203 | 203 |
|
|
207 | 207 | this.show = function(username, cb) { |
208 | 208 | var command = username ? '/users/' + username : '/user'; |
209 | 209 |
|
210 | | - _request('GET', command, null, function(err, res) { |
211 | | - cb(err, res); |
| 210 | + _request('GET', command, null, function(err, res, xhr) { |
| 211 | + cb(err, res, xhr); |
212 | 212 | }); |
213 | 213 | }; |
214 | 214 |
|
|
226 | 226 | // ------- |
227 | 227 |
|
228 | 228 | this.userGists = function(username, cb) { |
229 | | - _request('GET', '/users/' + username + '/gists', null, function(err, res) { |
230 | | - cb(err,res); |
| 229 | + _request('GET', '/users/' + username + '/gists', null, function(err, res, xhr) { |
| 230 | + cb(err,res, xhr); |
231 | 231 | }); |
232 | 232 | }; |
233 | 233 |
|
|
316 | 316 | // ------- |
317 | 317 |
|
318 | 318 | this.getRef = function(ref, cb) { |
319 | | - _request('GET', repoPath + '/git/refs/' + ref, null, function(err, res) { |
| 319 | + _request('GET', repoPath + '/git/refs/' + ref, null, function(err, res, xhr) { |
320 | 320 | if (err) { |
321 | 321 | return cb(err); |
322 | 322 | } |
323 | | - |
324 | | - cb(null, res.object.sha); |
| 323 | + |
| 324 | + cb(null, res.object.sha, xhr); |
325 | 325 | }); |
326 | 326 | }; |
327 | 327 |
|
|
365 | 365 | // ------- |
366 | 366 |
|
367 | 367 | this.listTags = function(cb) { |
368 | | - _request('GET', repoPath + '/tags', null, function(err, tags) { |
| 368 | + _request('GET', repoPath + '/tags', null, function(err, tags, xhr) { |
369 | 369 | if (err) { |
370 | 370 | return cb(err); |
371 | 371 | } |
372 | | - |
373 | | - cb(null, tags); |
| 372 | + |
| 373 | + cb(null, tags, xhr); |
374 | 374 | }); |
375 | 375 | }; |
376 | 376 |
|
377 | 377 | // List all pull requests of a respository |
378 | 378 | // ------- |
379 | 379 |
|
380 | 380 | this.listPulls = function(state, cb) { |
381 | | - _request('GET', repoPath + "/pulls" + (state ? '?state=' + state : ''), null, function(err, pulls) { |
| 381 | + _request('GET', repoPath + "/pulls" + (state ? '?state=' + state : ''), null, function(err, pulls, xhr) { |
382 | 382 | if (err) return cb(err); |
383 | | - cb(null, pulls); |
| 383 | + cb(null, pulls, xhr); |
384 | 384 | }); |
385 | 385 | }; |
386 | 386 |
|
387 | 387 | // Gets details for a specific pull request |
388 | 388 | // ------- |
389 | 389 |
|
390 | 390 | this.getPull = function(number, cb) { |
391 | | - _request("GET", repoPath + "/pulls/" + number, null, function(err, pull) { |
| 391 | + _request("GET", repoPath + "/pulls/" + number, null, function(err, pull, xhr) { |
392 | 392 | if (err) return cb(err); |
393 | | - cb(null, pull); |
| 393 | + cb(null, pull, xhr); |
394 | 394 | }); |
395 | 395 | }; |
396 | 396 |
|
397 | 397 | // Retrieve the changes made between base and head |
398 | 398 | // ------- |
399 | 399 |
|
400 | 400 | this.compare = function(base, head, cb) { |
401 | | - _request("GET", repoPath + "/compare/" + base + "..." + head, null, function(err, diff) { |
| 401 | + _request("GET", repoPath + "/compare/" + base + "..." + head, null, function(err, diff, xhr) { |
402 | 402 | if (err) return cb(err); |
403 | | - cb(null, diff); |
| 403 | + cb(null, diff, xhr); |
404 | 404 | }); |
405 | 405 | }; |
406 | 406 |
|
407 | 407 | // List all branches of a repository |
408 | 408 | // ------- |
409 | 409 |
|
410 | 410 | this.listBranches = function(cb) { |
411 | | - _request("GET", repoPath + "/git/refs/heads", null, function(err, heads) { |
| 411 | + _request("GET", repoPath + "/git/refs/heads", null, function(err, heads, xhr) { |
412 | 412 | if (err) return cb(err); |
413 | 413 | cb(null, heads.map(function(head) { |
414 | 414 | return head.ref.replace(/^refs\/heads\//, ''); |
415 | | - })); |
| 415 | + }), xhr); |
416 | 416 | }); |
417 | 417 | }; |
418 | 418 |
|
|
427 | 427 | // ------- |
428 | 428 |
|
429 | 429 | this.getCommit = function(branch, sha, cb) { |
430 | | - _request("GET", repoPath + "/git/commits/"+sha, null, function(err, commit) { |
| 430 | + _request("GET", repoPath + "/git/commits/"+sha, null, function(err, commit, xhr) { |
431 | 431 | if (err) return cb(err); |
432 | | - cb(null, commit); |
| 432 | + cb(null, commit, xhr); |
433 | 433 | }); |
434 | 434 | }; |
435 | 435 |
|
|
438 | 438 |
|
439 | 439 | this.getSha = function(branch, path, cb) { |
440 | 440 | if (!path || path === "") return that.getRef("heads/"+branch, cb); |
441 | | - _request("GET", repoPath + "/contents/" + path + (branch ? "?ref=" + branch : ""), null, function(err, pathContent) { |
| 441 | + _request("GET", repoPath + "/contents/" + path + (branch ? "?ref=" + branch : ""), null, function(err, pathContent, xhr) { |
442 | 442 | if (err) return cb(err); |
443 | | - cb(null, pathContent.sha); |
| 443 | + cb(null, pathContent.sha, xhr); |
444 | 444 | }); |
445 | 445 | }; |
446 | 446 |
|
447 | 447 | // Retrieve the tree a commit points to |
448 | 448 | // ------- |
449 | 449 |
|
450 | 450 | this.getTree = function(tree, cb) { |
451 | | - _request("GET", repoPath + "/git/trees/"+tree, null, function(err, res) { |
| 451 | + _request("GET", repoPath + "/git/trees/"+tree, null, function(err, res, xhr) { |
452 | 452 | if (err) return cb(err); |
453 | | - cb(null, res.tree); |
| 453 | + cb(null, res.tree, xhr); |
454 | 454 | }); |
455 | 455 | }; |
456 | 456 |
|
|
557 | 557 | this.contributors = function (cb, retry) { |
558 | 558 | retry = retry || 1000; |
559 | 559 | var self = this; |
560 | | - _request("GET", repoPath + "/stats/contributors", null, function (err, data, response) { |
| 560 | + _request("GET", repoPath + "/stats/contributors", null, function (err, data, xhr) { |
561 | 561 | if (err) return cb(err); |
562 | | - if (response.status === 202) { |
| 562 | + if (xhr.status === 202) { |
563 | 563 | setTimeout( |
564 | 564 | function () { |
565 | 565 | self.contributors(cb, retry); |
566 | 566 | }, |
567 | 567 | retry |
568 | 568 | ); |
569 | 569 | } else { |
570 | | - cb(err, data); |
| 570 | + cb(err, data, xhr); |
571 | 571 | } |
572 | 572 | }); |
573 | 573 | }; |
|
651 | 651 | // ------- |
652 | 652 |
|
653 | 653 | this.read = function(branch, path, cb) { |
654 | | - _request("GET", repoPath + "/contents/"+encodeURI(path) + (branch ? "?ref=" + branch : ""), null, function(err, obj) { |
| 654 | + _request("GET", repoPath + "/contents/"+encodeURI(path) + (branch ? "?ref=" + branch : ""), null, function(err, obj, xhr) { |
655 | 655 | if (err && err.error === 404) return cb("not found", null, null); |
656 | 656 |
|
657 | 657 | if (err) return cb(err); |
658 | | - cb(null, obj); |
| 658 | + cb(null, obj, xhr); |
659 | 659 | }, true); |
660 | 660 | }; |
661 | 661 |
|
|
785 | 785 | // -------- |
786 | 786 |
|
787 | 787 | this.read = function(cb) { |
788 | | - _request("GET", gistPath, null, function(err, gist) { |
789 | | - cb(err, gist); |
| 788 | + _request("GET", gistPath, null, function(err, gist, xhr) { |
| 789 | + cb(err, gist, xhr); |
790 | 790 | }); |
791 | 791 | }; |
792 | 792 |
|
|
855 | 855 | // -------- |
856 | 856 |
|
857 | 857 | this.isStarred = function(cb) { |
858 | | - _request("GET", gistPath+"/star", null, function(err,res) { |
859 | | - cb(err,res); |
| 858 | + _request("GET", gistPath+"/star", null, function(err,res, xhr) { |
| 859 | + cb(err,res, xhr); |
860 | 860 | }); |
861 | 861 | }; |
862 | 862 | }; |
|
0 commit comments