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