Reputation: 7196
I wish to retrieve all issues from a GitHub repository in my Node.js application. I've used octokit to do this. From the documentation I gather I must use repo.getIssueEvents()
but this just returns the 1st pull request which is not what I expected.
I've tried Googling this but keep coming across the same documentation that I've already used. Waht am I doing wrong?
Here is my code:
var GitHubApi = require('octokit');
retrieveIssues: function(owner, repoName) {
var gh = GitHubApi.new({
username: "user",
password: "password"
});
var repo = gh.getRepo(owner, repoName);
repo.getIssueEvents()
.then(function(events) {console.log(events)})
}
Upvotes: 3
Views: 2092
Reputation: 45372
If you refer to this octokit project, it seems it doesn't expose Github API to get issues but only issue events for a specific repository.
Here, Github recommends using octokit/rest for node.js
npm install @octokit/rest
To get all issues (issues & pull request in all state) it would be :
const octokit = require('@octokit/rest')()
async function paginate(method) {
let response = await method({
owner: "google",
repo: "gson",
state: "all",
per_page: 100
})
let {
data
} = response
var count = 0;
while (octokit.hasNextPage(response)) {
count++;
console.log(`${count} request`);
response = await octokit.getNextPage(response)
data = data.concat(response.data)
}
return data
}
paginate(octokit.issues.getForRepo)
.then(data => {
console.log(data);
})
Check issues.getForRepo
If you don't want pull requests but only issues you could also perform a search request like this :
const octokit = require('@octokit/rest')()
octokit.authenticate({
type: 'oauth',
token: 'YOUR_TOKEN'
});
async function paginate(method) {
let response = await method({
q: "repo:google/gson is:issue",
per_page: 100
})
let data = response.data.items;
var count = 0;
while (octokit.hasNextPage(response)) {
count++;
console.log(`request n°${count}`);
response = await octokit.getNextPage(response);
data = data.concat(response.data.items);
}
return data
}
paginate(octokit.search.issues)
.then(data => {
console.log(data);
console.log(`retrieved ${data.length} issues`);
})
But note that only the first 1000 issues are returned in search requests
Upvotes: 2