Reputation: 29179
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 ?
Upvotes: 1
Views: 308
Reputation: 25161
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.
Upvotes: 4