Skip to content

Commit

Permalink
Use Octokit pagination
Browse files Browse the repository at this point in the history
  • Loading branch information
dorny committed Oct 11, 2022
1 parent b0e6c31 commit 248cda5
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as fs from 'fs'
import * as core from '@actions/core'
import * as github from '@actions/github'
import type {Octokit} from '@octokit/rest'
import {Webhooks} from '@octokit/webhooks'

import {Filter, FilterResults} from './filter'
Expand Down Expand Up @@ -166,25 +167,19 @@ async function getChangedFilesFromApi(
const per_page = 100
const files: File[] = []

for (let page = 1; ; page++) {
core.info(`Invoking listFiles(pull_number: ${prNumber.number}, page: ${page}, per_page: ${per_page})`)
const response = await client.pulls.listFiles({
core.info(`Invoking listFiles(pull_number: ${prNumber.number}, per_page: ${per_page})`)
for await (const response of client.paginate.iterator(
client.pulls.listFiles.endpoint.merge({
owner: github.context.repo.owner,
repo: github.context.repo.repo,
pull_number: prNumber.number,
per_page,
page
per_page
})

) as AsyncIterableIterator<Octokit.Response<Octokit.PullsListFilesResponse>>) {
if (response.status !== 200) {
throw new Error(`Fetching list of changed files from GitHub API failed with error code ${response.status}`)
}

core.info(`Received ${response.data.length} items`)
if (response.data.length === 0) {
core.info('All changed files has been fetched from GitHub API')
break
}

for (const row of response.data) {
core.info(`[${row.status}] ${row.filename}`)
Expand Down

0 comments on commit 248cda5

Please sign in to comment.