feat: make comment page count configurable
and fetch twice as many pages as before
This commit is contained in:
@@ -5,20 +5,30 @@ function truncate(str, len = 26) {
|
|||||||
return `${str.slice(0, len)}...`;
|
return `${str.slice(0, len)}...`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default async function getEvents(repo, { body, actor } = {}) {
|
const getCommentEvents = async (repo, lastEvents) => {
|
||||||
const events = await repo.events.fetch();
|
// just fetch and return the results
|
||||||
|
if (lastEvents == null) return repo.events.fetch();
|
||||||
|
|
||||||
const items = await (async () => {
|
// if there is no next page, just return the passed in object
|
||||||
// process 2 pages of events
|
if (!lastEvents.nextPage) return lastEvents;
|
||||||
if (events.nextPage) {
|
|
||||||
const moreEvents = await events.nextPage.fetch();
|
|
||||||
return [...events.items, ...moreEvents.items];
|
|
||||||
}
|
|
||||||
|
|
||||||
return events.items;
|
// fetch next items and append previous ones
|
||||||
})();
|
const newEvents = await lastEvents.nextPage.fetch();
|
||||||
|
newEvents.items = [...lastEvents.items, ...newEvents.items];
|
||||||
|
return newEvents;
|
||||||
|
};
|
||||||
|
|
||||||
return items
|
export default async function getEvents(repo, { body, actor, pages = 4 } = {}) {
|
||||||
|
// create a task array that we can reduce into a promise chain
|
||||||
|
const chain = [];
|
||||||
|
while (chain.length < pages) chain.push('page');
|
||||||
|
|
||||||
|
const events = await chain.reduce(
|
||||||
|
acc => acc.then(res => getCommentEvents(repo, res)),
|
||||||
|
Promise.resolve()
|
||||||
|
);
|
||||||
|
|
||||||
|
return events.items
|
||||||
.map(comment => {
|
.map(comment => {
|
||||||
let skip = false;
|
let skip = false;
|
||||||
const isComment = comment.type === 'IssueCommentEvent';
|
const isComment = comment.type === 'IssueCommentEvent';
|
||||||
|
|||||||
Reference in New Issue
Block a user