fix: fixes while exit condition
This commit is contained in:
@@ -33,11 +33,15 @@ export async function renderer(
|
||||
}
|
||||
|
||||
export function getNextPage(links: PaginationLink[]): string | null {
|
||||
const link = links.find((l) => l.rel === 'next');
|
||||
if (!link) return null;
|
||||
const match = link.uri.match(/page=([0-9]*)/);
|
||||
if (!match) return null;
|
||||
return match[1];
|
||||
const next = links.find((l) => l.rel === 'next');
|
||||
const last = links.find((l) => l.rel === 'last');
|
||||
if (!next || !last) return null;
|
||||
const matchNext = next.uri.match(/page=([0-9]*)/);
|
||||
const matchLast = next.uri.match(/page=([0-9]*)/);
|
||||
|
||||
if (!matchNext || !matchLast) return null;
|
||||
if (matchNext[1] === matchLast[1]) return null;
|
||||
return matchNext[1];
|
||||
}
|
||||
|
||||
async function* paginateStars(url: string): AsyncGenerator<Stars> {
|
||||
@@ -49,10 +53,8 @@ async function* paginateStars(url: string): AsyncGenerator<Stars> {
|
||||
page: nextPage,
|
||||
},
|
||||
});
|
||||
console.log('body, typeof body :>> ', body, typeof body);
|
||||
yield (body as unknown) as Stars;
|
||||
nextPage = getNextPage(link.parse(headers.link).refs);
|
||||
console.log('sleeping 1second to avoid rate-limit');
|
||||
await wait(1000); // avoid limits
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
|
@@ -7,7 +7,7 @@ sinon.replace(core, 'getInput', sinon.fake());
|
||||
|
||||
import GithubApi from '../src/api';
|
||||
const GithubApiFake = sinon.fake((rul) => ({
|
||||
body: 'data',
|
||||
body: [],
|
||||
headers: {
|
||||
link:
|
||||
'<https://api.github.com/user/5617452/starred?page=2>; rel="next", <https://api.github.com/user/5617452/starred?page=2>; rel="last"',
|
||||
@@ -32,11 +32,9 @@ const writeFile = sinon.fake();
|
||||
sinon.replace(fsp, 'writeFile', writeFile);
|
||||
|
||||
import {
|
||||
isLastPage,
|
||||
wait,
|
||||
renderer,
|
||||
apiGetStar,
|
||||
paginate,
|
||||
generateMd,
|
||||
pushNewFiles,
|
||||
} from '../src/helpers';
|
||||
@@ -46,40 +44,15 @@ test('wait should wait', async (t) => {
|
||||
t.pass();
|
||||
});
|
||||
|
||||
test('isLastPage', (t) => {
|
||||
t.true(
|
||||
isLastPage({
|
||||
next: 'last',
|
||||
last: 'last',
|
||||
})
|
||||
);
|
||||
t.false(
|
||||
isLastPage({
|
||||
next: 'last',
|
||||
last: undefined,
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
test('renderer should render', async (t) => {
|
||||
const output = await renderer({ variable: 123 }, 'Test: <%= variable %>');
|
||||
t.is(output, 'Test: 123');
|
||||
});
|
||||
|
||||
test('apiGetStar', async (t) => {
|
||||
let { data, links } = await apiGetStar('url');
|
||||
let stars = await apiGetStar('url');
|
||||
t.true(GithubApiFake.called);
|
||||
t.is(data, 'data');
|
||||
t.deepEqual(links, {
|
||||
last: 'https://api.github.com/user/5617452/starred?page=2',
|
||||
next: 'https://api.github.com/user/5617452/starred?page=2',
|
||||
});
|
||||
});
|
||||
|
||||
test('paginate', async (t) => {
|
||||
await paginate();
|
||||
const res = await paginate();
|
||||
t.is(res, null);
|
||||
t.true(Array.isArray(stars));
|
||||
});
|
||||
|
||||
test('generateMd should create TOC', async (t) => {
|
||||
@@ -97,7 +70,7 @@ test('generateMd should create TOC', async (t) => {
|
||||
});
|
||||
|
||||
test('should push', async (t) => {
|
||||
await pushNewFiles([{filename: "README.md", data: '# title'}]);
|
||||
await pushNewFiles([{ filename: 'README.md', data: '# title' }]);
|
||||
t.true(writeFile.calledWith('README.md', '# title'));
|
||||
t.true(pull.called);
|
||||
t.true(add.calledWith('README.md'));
|
||||
|
Reference in New Issue
Block a user