mirror of
https://github.com/maciejpedzich/playlist-entry-validator.git
synced 2024-11-28 00:15:48 +01:00
Handle GitHub PR files pagination
This commit is contained in:
parent
b39372fede
commit
179ca09937
40
appFn.ts
40
appFn.ts
@ -60,11 +60,41 @@ const appFn: ApplicationFunction = (app: Probot, { getRouter }) => {
|
|||||||
|
|
||||||
if (!isAllowlistedRepo) return;
|
if (!isAllowlistedRepo) return;
|
||||||
|
|
||||||
const { data: prFiles } = await octokit.pulls.listFiles({
|
type PRFileArray = Awaited<
|
||||||
|
ReturnType<typeof octokit.pulls.listFiles>
|
||||||
|
>['data'];
|
||||||
|
|
||||||
|
const sleep = (ms: number) =>
|
||||||
|
new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
|
|
||||||
|
const prFiles: PRFileArray = [];
|
||||||
|
let page = 1;
|
||||||
|
let loadingPages = true;
|
||||||
|
let timeToRateLimitReset = 0;
|
||||||
|
|
||||||
|
while (loadingPages) {
|
||||||
|
await sleep(timeToRateLimitReset);
|
||||||
|
|
||||||
|
const { data, headers } = await octokit.pulls.listFiles({
|
||||||
...workingRepo,
|
...workingRepo,
|
||||||
pull_number
|
pull_number,
|
||||||
|
page
|
||||||
});
|
});
|
||||||
|
|
||||||
|
prFiles.push(...data);
|
||||||
|
|
||||||
|
let now = Date.now();
|
||||||
|
timeToRateLimitReset =
|
||||||
|
headers['x-ratelimit-remaining'] !== '0'
|
||||||
|
? 0
|
||||||
|
: (Number(headers['x-ratelimit-reset']) || now) - now;
|
||||||
|
|
||||||
|
if (headers.link?.includes(`rel=\"next\"`)) page++;
|
||||||
|
else loadingPages = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
console.log('Total entries: ' + prFiles.length);
|
||||||
|
|
||||||
const filesToVerify = prFiles.filter(
|
const filesToVerify = prFiles.filter(
|
||||||
({ status, filename }) =>
|
({ status, filename }) =>
|
||||||
filename.startsWith(registryDirectoryPath) &&
|
filename.startsWith(registryDirectoryPath) &&
|
||||||
@ -97,11 +127,7 @@ const appFn: ApplicationFunction = (app: Probot, { getRouter }) => {
|
|||||||
|
|
||||||
if (found) {
|
if (found) {
|
||||||
const html = await spotifyResponse.text();
|
const html = await spotifyResponse.text();
|
||||||
const {
|
const { author: authorUrl, description } = await getMetaData({
|
||||||
title,
|
|
||||||
author: authorUrl,
|
|
||||||
description
|
|
||||||
} = await getMetaData({
|
|
||||||
html,
|
html,
|
||||||
customRules: {
|
customRules: {
|
||||||
author: {
|
author: {
|
||||||
|
Loading…
Reference in New Issue
Block a user