Skip to content

Commit 7f08abb

Browse files
committed
Add plugin_reactions_limit_issues (lowlighter#334)
1 parent 4722035 commit 7f08abb

File tree

3 files changed

+24
-17
lines changed

3 files changed

+24
-17
lines changed

source/plugins/reactions/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ The *reactions* plugin displays overall reactions on your recent issues and issu
1919
# ... other options
2020
plugin_reactions: yes
2121
plugin_reactions_limit: 200 # Compute reactions over last 200 issue comments
22+
plugin_reactions_limit_issues: 100 # Compute reactions over laste 100 issues/pull requests opened
2223
plugin_reactions_days: 14 # Compute reactions on issue comments posted less than 14 days ago
2324
plugin_reactions_details: count, percentage # Display reactions count and percentage
2425
plugin_reactions_ignored: bot # Ignore "bot" user

source/plugins/reactions/index.mjs

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ export default async function({login, q, imports, data, graphql, queries, accoun
77
return null
88

99
//Load inputs
10-
let {limit, days, details, display, ignored} = imports.metadata.plugins.reactions.inputs({data, account, q})
10+
let {limit:_limit1, "limit.issues":_limit2, days, details, display, ignored} = imports.metadata.plugins.reactions.inputs({data, account, q})
1111

1212
//Load issue comments
13-
let cursor = null, pushed = 0
1413
const comments = []
15-
for (const type of ["issues", "issueComments"]) {
14+
for (const {type, limit} of [{type:"issueComments", limit:_limit1}, {type:"issues", limit:_limit2}].filter(({limit}) => limit)) {
15+
let cursor = null, pushed = 0
16+
const fetched = []
1617
do {
1718
//Load issue comments
1819
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
2324
.flatMap(({node:{createdAt:created, reactions:{nodes:reactions}}}) => ({created:new Date(created), reactions:reactions.filter(({user = {}}) => !ignored.includes(user.login)).map(({content}) => content)}))
2425
.filter(comment => Number.isFinite(days) ? comment.created < new Date(Date.now() - days * 24 * 60 * 60 * 1000) : true)
2526
pushed = filtered.length
26-
comments.push(...filtered)
27-
console.debug(`metrics/compute/${login}/plugins > reactions > currently at ${comments.length} comments`)
28-
//Early break
29-
if ((comments.length >= limit) || (filtered.length < edges.length))
30-
break
31-
} while ((cursor) && (pushed) && (comments.length < limit))
32-
}
33-
34-
//Applying limit
35-
if (limit) {
36-
comments.splice(limit)
37-
console.debug(`metrics/compute/${login}/plugins > reactions > keeping only ${comments.length} comments`)
27+
fetched.push(...filtered)
28+
console.debug(`metrics/compute/${login}/plugins > reactions > currently at ${fetched.length} ${type} comments`)
29+
//Applying limit
30+
if ((fetched.length >= limit) || (filtered.length < edges.length)) {
31+
fetched.splice(limit)
32+
console.debug(`metrics/compute/${login}/plugins > reactions > keeping only ${fetched.length} ${type} comments`)
33+
}
34+
} while ((cursor) && (pushed) && (fetched.length < limit))
35+
comments.push(...fetched)
3836
}
37+
console.debug(`metrics/compute/${login}/plugins > reactions > fetched ${comments.length} comments`)
3938

4039
//Format reactions list
4140
const list = {}

source/plugins/reactions/metadata.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,19 @@ inputs:
1313
default: no
1414

1515
# Maximum number of issue comments to parse
16-
# Issues will be fetched before issues comments
1716
plugin_reactions_limit:
1817
description: Maximum number of issue comments to parse
1918
type: number
2019
default: 200
21-
min: 1
20+
min: 0
21+
max: 1000
22+
23+
# Maximum number of issues and pull requests opened to parse
24+
plugin_reactions_limit_issues:
25+
description: Maximum number of issues and pull requests opened to parse
26+
type: number
27+
default: 100
28+
min: 0
2229
max: 1000
2330

2431
# Filter reactions by issue comments age

0 commit comments

Comments
 (0)