Octokit 返回一个拉取请求而不是所有问题

Octokit returning one pull request rather than all issues

我希望从我的 Node.js 应用程序的 GitHub 存储库中检索所有问题。我已经使用 octokit 来做到这一点。从我收集的文档中,我必须使用 repo.getIssueEvents() 但这只是 returns 第一个拉取请求,这不是我所期望的。

我试过用谷歌搜索这个,但不断遇到我已经使用过的相同文档。我哪里做错了?

这是我的代码:

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)})

}

如果您参考 this octokit project, it seems it doesn't expose Github API to get issues but only issue events 特定存储库。

Here, Github recommends using octokit/rest for

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);
    })

勾选issues.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 期