简体   繁体   中英

javascript: get all issues from a public repo client-side

I'm looking for a simple way to retrieve all issues for a specific public repository on github.

I found one client-side library gh3 , but I noticed that for everything it does it requires a username. Secondly it doesn't mention 'issues' at all.

Any suggestions how this can be done, which libs I should use ?

Here is some basic code to fetch all issues from a github repo. Uses no libraries except jQuery.

function getIssues(opts){
    opts.data = opts.data || [];
    opts.page = opts.page || 1;
    var url = 'https://api.github.com/repos/' + opts.username + '/' + opts.repo;
    url += '/issues?callback=?&page=' + opts.page + '&per_page=100&state=' + opts.state;
    $.ajax(url, {
        dataType: 'jsonp',
        success: function(res){
            if(res.meta && res.meta.status == '403'){
                return opts.error(res.data);
            }
            opts.data = $.merge(opts.data, res.data);
            if(res.meta && res.meta.Link){
                if(res.meta.Link[0][1].rel == "next"){
                    opts.page++; 
                    getIssues(opts)
                } else {
                    opts.success(opts.data);
                }
            }
        }
    });
}

Example usage:

getIssues({
    username: 'joyent',
    repo: 'node',
    state: 'open',
    success: function(data){
        console.log(data); 
    },
    error: function(err){
        console.log(err);
    }
});

Note: If your requests are un-authenticated, you will be limited to 60 requests per hour (per IP address). See here .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM