From 7f08abb0405da0e55a2ce8e3b2e4953f60513095 Mon Sep 17 00:00:00 2001 From: lowlighter <22963968+lowlighter@users.noreply.github.com> Date: Wed, 2 Jun 2021 01:03:19 +0200 Subject: [PATCH] Add `plugin_reactions_limit_issues` (#334) --- source/plugins/reactions/README.md | 1 + source/plugins/reactions/index.mjs | 29 +++++++++++++-------------- source/plugins/reactions/metadata.yml | 11 ++++++++-- 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/source/plugins/reactions/README.md b/source/plugins/reactions/README.md index 65ce7e7b..83ee4dd5 100644 --- a/source/plugins/reactions/README.md +++ b/source/plugins/reactions/README.md @@ -19,6 +19,7 @@ The *reactions* plugin displays overall reactions on your recent issues and issu # ... other options plugin_reactions: yes plugin_reactions_limit: 200 # Compute reactions over last 200 issue comments + plugin_reactions_limit_issues: 100 # Compute reactions over laste 100 issues/pull requests opened plugin_reactions_days: 14 # Compute reactions on issue comments posted less than 14 days ago plugin_reactions_details: count, percentage # Display reactions count and percentage plugin_reactions_ignored: bot # Ignore "bot" user diff --git a/source/plugins/reactions/index.mjs b/source/plugins/reactions/index.mjs index ba4b4a4c..affcb5ec 100644 --- a/source/plugins/reactions/index.mjs +++ b/source/plugins/reactions/index.mjs @@ -7,12 +7,13 @@ export default async function({login, q, imports, data, graphql, queries, accoun return null //Load inputs - let {limit, days, details, display, ignored} = imports.metadata.plugins.reactions.inputs({data, account, q}) + let {limit:_limit1, "limit.issues":_limit2, days, details, display, ignored} = imports.metadata.plugins.reactions.inputs({data, account, q}) //Load issue comments - let cursor = null, pushed = 0 const comments = [] - for (const type of ["issues", "issueComments"]) { + for (const {type, limit} of [{type:"issueComments", limit:_limit1}, {type:"issues", limit:_limit2}].filter(({limit}) => limit)) { + let cursor = null, pushed = 0 + const fetched = [] do { //Load issue comments console.debug(`metrics/compute/${login}/plugins > reactions > retrieving ${type} after ${cursor}`) @@ -23,19 +24,17 @@ export default async function({login, q, imports, data, graphql, queries, accoun .flatMap(({node:{createdAt:created, reactions:{nodes:reactions}}}) => ({created:new Date(created), reactions:reactions.filter(({user = {}}) => !ignored.includes(user.login)).map(({content}) => content)})) .filter(comment => Number.isFinite(days) ? comment.created < new Date(Date.now() - days * 24 * 60 * 60 * 1000) : true) pushed = filtered.length - comments.push(...filtered) - console.debug(`metrics/compute/${login}/plugins > reactions > currently at ${comments.length} comments`) - //Early break - if ((comments.length >= limit) || (filtered.length < edges.length)) - break - } while ((cursor) && (pushed) && (comments.length < limit)) - } - - //Applying limit - if (limit) { - comments.splice(limit) - console.debug(`metrics/compute/${login}/plugins > reactions > keeping only ${comments.length} comments`) + fetched.push(...filtered) + console.debug(`metrics/compute/${login}/plugins > reactions > currently at ${fetched.length} ${type} comments`) + //Applying limit + if ((fetched.length >= limit) || (filtered.length < edges.length)) { + fetched.splice(limit) + console.debug(`metrics/compute/${login}/plugins > reactions > keeping only ${fetched.length} ${type} comments`) + } + } while ((cursor) && (pushed) && (fetched.length < limit)) + comments.push(...fetched) } + console.debug(`metrics/compute/${login}/plugins > reactions > fetched ${comments.length} comments`) //Format reactions list const list = {} diff --git a/source/plugins/reactions/metadata.yml b/source/plugins/reactions/metadata.yml index caa63bc9..0f573988 100644 --- a/source/plugins/reactions/metadata.yml +++ b/source/plugins/reactions/metadata.yml @@ -13,12 +13,19 @@ inputs: default: no # Maximum number of issue comments to parse - # Issues will be fetched before issues comments plugin_reactions_limit: description: Maximum number of issue comments to parse type: number default: 200 - min: 1 + min: 0 + max: 1000 + + # Maximum number of issues and pull requests opened to parse + plugin_reactions_limit_issues: + description: Maximum number of issues and pull requests opened to parse + type: number + default: 100 + min: 0 max: 1000 # Filter reactions by issue comments age