octokit / octokit.js

The all-batteries-included GitHub SDK for Browsers, Node.js, and Deno.
MIT License
7.03k stars 1.03k forks source link

Ability to chain api calls #195

Closed mwq27 closed 8 years ago

mwq27 commented 10 years ago

Is it possible to chain api calls like so -

var git = new GitHubApi({
   ...
});

var srcGit = new GitHubApi({
    ...
});

srcGit.issues.repoIssues({
...}, function(err, res){ 
     git.issues.create({
                ...
            }, function(err, res){
    srcGit.issues.getComment({ ... }, function(err, res){
    git.issues.createComment({ ... }, function(err, res){});
});
});
});

I'm trying to move issues from one repo to another. Creating the issues is working, but trying to add the comments to each new issue im running into problems, since the for loops seems to continue while the API call is still working.

kaizensoze commented 8 years ago

You'll want to use promises. To promisify node-github, see here: http://bluebirdjs.com/docs/api/promise.promisifyall.html

kaizensoze commented 8 years ago

Actually, the ability to use promises will be included in the next release. See example.

kaizensoze commented 8 years ago

Included in latest 2.1.0.