P粉1079910302023-09-02 16:21:43
It does support filtering by organization. use:
await octokit.request("GET /search/issues", { q: `is:pr is:open org:ORGANIZATION`, });
P粉7138664252023-09-02 13:30:20
There is no direct way to use GitHub's API or Octokit to get all open PRs in all repositories within an organization in a single request. The Search API can search for PRs, but does not support filtering by organization.
You can get a list of all repositories in your organization and get all pull requests for each repository using the repository list.
Example:
const { Octokit } = require("@octokit/core"); const octokit = new Octokit({ auth: `your_auth_token` }); async function fetchAllRepos(org) { const repos = []; let page = 1; while (true) { const result = await octokit.request('GET /orgs/{org}/repos', { org: org, type: 'public', per_page: 100, page: page }); if (result.data.length === 0) break; repos.push(...result.data); page++; } return repos; } async function fetchAllPRs(org) { const repos = await fetchAllRepos(org); const prPromises = repos.map(repo => octokit.request('GET /repos/{owner}/{repo}/pulls', { owner: org, repo: repo.name, state: 'open' }) ); const prResults = await Promise.all(prPromises); const prs = prResults.flatMap(result => result.data); return prs; } fetchAllPRs('my-org-name') .then(prs => console.log(prs)) .catch(err => console.error(err));
Not sure how slow this would be in your case. Anyway, I hope this helps.