Accept more than 100 events in activity plugin

This commit is contained in:
lowlighter
2021-05-05 23:05:45 +02:00
parent a06ba37c3b
commit f9aa59b3d5
2 changed files with 13 additions and 2 deletions

View File

@@ -19,11 +19,21 @@ export default async function({login, data, rest, q, account, imports}, {enabled
if (!days) if (!days)
days = Infinity days = Infinity
skipped.push(...data.shared["repositories.skipped"]) skipped.push(...data.shared["repositories.skipped"])
const pages = Math.ceil(limit/100)
const codelines = 2 const codelines = 2
//Get user recent activity //Get user recent activity
console.debug(`metrics/compute/${login}/plugins > activity > querying api`) 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`) console.debug(`metrics/compute/${login}/plugins > activity > ${events.length} events loaded`)
//Extract activity events //Extract activity events

View File

@@ -20,9 +20,10 @@ inputs:
type: number type: number
default: 5 default: 5
min: 1 min: 1
max: 100 max: 1000
# Filter events by age # 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 # Set to 0 to disable age filtering
plugin_activity_days: plugin_activity_days:
description: Maximum event age description: Maximum event age