fix(typescript): GitHubAPI.paginate callback signature (#775)

This commit is contained in:
Adam Netočný 2019-01-09 21:10:58 +01:00 committed by Gregor Martynus
parent fe99d0b2d3
commit 2b78263e82
2 changed files with 4 additions and 4 deletions

View File

@ -49,7 +49,7 @@ export interface OctokitError extends Error {
}
export interface GitHubAPI extends Octokit {
paginate: (res: Promise<Octokit.AnyResponse>, callback: (response: Promise<Octokit.AnyResponse>, done?: () => void) => void) => Promise<any[]>
paginate: (res: Promise<Octokit.AnyResponse>, callback: (response: Octokit.AnyResponse, done?: () => void) => any) => Promise<any[]>
// The following are added because Octokit does not expose the hook.error, hook.before, and hook.after methods
hook: {
error: (when: 'request', callback: (error: OctokitError, options: RequestOptions) => void) => void

View File

@ -5,7 +5,7 @@ export function addPagination (octokit: GitHubAPI) {
octokit.paginate = paginate.bind(null, octokit)
}
const defaultCallback = (response: Promise<AnyResponse>, done?: () => void) => response
const defaultCallback = (response: AnyResponse, done?: () => void) => response
async function paginate (octokit: GitHubAPI, responsePromise: any, callback = defaultCallback) {
let collection: any[] = []
@ -17,12 +17,12 @@ async function paginate (octokit: GitHubAPI, responsePromise: any, callback = de
let response = await responsePromise
collection = collection.concat(await callback(response, done))
collection = collection.concat(callback(response, done))
// eslint-disable-next-line no-unmodified-loop-condition
while (getNextPage && octokit.hasNextPage(response)) {
response = await octokit.getNextPage(response)
collection = collection.concat(await callback(response, done))
collection = collection.concat(callback(response, done))
}
return collection
}