export async function getPendingPrs()

in ng-dev/utils/github.ts [54:108]


export async function getPendingPrs<PrSchema>(prSchema: PrSchema, git: AuthenticatedGitClient) {
  /** The owner and name of the repository */
  const {owner, name} = git.remoteConfig;
  /** The Graphql query object to get a page of pending PRs */
  const PRS_QUERY = params(
    {
      $first: 'Int', // How many entries to get with each request
      $after: 'String', // The cursor to start the page at
      $owner: 'String!', // The organization to query for
      $name: 'String!', // The repository to query for
    },
    {
      repository: params(
        {owner: '$owner', name: '$name'},
        {
          pullRequests: params(
            {
              first: '$first',
              after: '$after',
              states: `OPEN`,
            },
            {
              nodes: [prSchema],
              pageInfo: {
                hasNextPage: types.boolean,
                endCursor: types.string,
              },
            },
          ),
        },
      ),
    },
  );
  /** The current cursor */
  let cursor: string | undefined;
  /** If an additional page of members is expected */
  let hasNextPage = true;
  /** Array of pending PRs */
  const prs: Array<PrSchema> = [];

  // For each page of the response, get the page and add it to the list of PRs
  while (hasNextPage) {
    const params = {
      after: cursor || null,
      first: 100,
      owner,
      name,
    };
    const results = (await git.github.graphql(PRS_QUERY, params)) as typeof PRS_QUERY;
    prs.push(...results.repository.pullRequests.nodes);
    hasNextPage = results.repository.pullRequests.pageInfo.hasNextPage;
    cursor = results.repository.pullRequests.pageInfo.endCursor;
  }
  return prs;
}