From f9aa59b3d5869c78c447e1c05b61e8eb8f66cd8b Mon Sep 17 00:00:00 2001 From: lowlighter <22963968+lowlighter@users.noreply.github.com> Date: Wed, 5 May 2021 23:05:45 +0200 Subject: [PATCH] Accept more than 100 events in activity plugin --- source/plugins/activity/index.mjs | 12 +++++++++++- source/plugins/activity/metadata.yml | 3 ++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/source/plugins/activity/index.mjs b/source/plugins/activity/index.mjs index d8777e6cb99..8fe72189e5e 100644 --- a/source/plugins/activity/index.mjs +++ b/source/plugins/activity/index.mjs @@ -19,11 +19,21 @@ export default async function({login, data, rest, q, account, imports}, {enabled if (!days) days = Infinity skipped.push(...data.shared["repositories.skipped"]) + const pages = Math.ceil(limit/100) const codelines = 2 //Get user recent activity console.debug(`metrics/compute/${login}/plugins > activity > querying api`) - const {data:events} = context.mode === "repository" ? await rest.activity.listRepoEvents({owner:context.owner, repo:context.repo}) : await rest.activity.listEventsForAuthenticatedUser({username:login, per_page:100}) + const events = [] + try { + for (let page = 1; page <= pages; page++) { + console.debug(`metrics/compute/${login}/plugins > activity > loading page ${page}`) + events.push(...(context.mode === "repository" ? await rest.activity.listRepoEvents({owner:context.owner, repo:context.repo}) : await rest.activity.listEventsForAuthenticatedUser({username:login, per_page:100})).data) + } + } + catch { + console.debug(`metrics/compute/${login}/plugins > activity > no more page to load`) + } console.debug(`metrics/compute/${login}/plugins > activity > ${events.length} events loaded`) //Extract activity events diff --git a/source/plugins/activity/metadata.yml b/source/plugins/activity/metadata.yml index 0e634b8ad9b..2167cac4772 100644 --- a/source/plugins/activity/metadata.yml +++ b/source/plugins/activity/metadata.yml @@ -20,9 +20,10 @@ inputs: type: number default: 5 min: 1 - max: 100 + max: 1000 # Filter events by age + # Note that it only filter fetched events, you may need to increase "plugin_activity_limit" to display older events # Set to 0 to disable age filtering plugin_activity_days: description: Maximum event age