如果您参考这个 octokit 项目,它似乎没有公开 Github API 来获取问题,而只是为特定存储库发布事件。
在这里,Github 推荐使用octokit/rest for node.js
npm install @octokit/rest
要获取所有问题(所有状态的问题和拉取请求),它将是:
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);
})
检查问题.getForRepo
如果您不想要拉取请求而只想要问题,您也可以执行这样的搜索请求:
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`);
})
但请注意,搜索请求中仅返回前 1000 个问题