Add option to ignores users in reactions plugin (#256)
This commit is contained in:
@@ -17,7 +17,10 @@
|
|||||||
node:{
|
node:{
|
||||||
createdAt:faker.date.recent(),
|
createdAt:faker.date.recent(),
|
||||||
reactions:{
|
reactions:{
|
||||||
nodes:new Array(50).fill(null).map(_ => ({content:faker.random.arrayElement(["HEART", "THUMBS_UP", "THUMBS_DOWN", "LAUGH", "CONFUSED", "EYES", "ROCKET", "HOORAY"])})),
|
nodes:new Array(50).fill(null).map(_ => ({
|
||||||
|
user:{login:faker.internet.userName()},
|
||||||
|
content:faker.random.arrayElement(["HEART", "THUMBS_UP", "THUMBS_DOWN", "LAUGH", "CONFUSED", "EYES", "ROCKET", "HOORAY"]),
|
||||||
|
})),
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
})),
|
})),
|
||||||
|
|||||||
@@ -21,4 +21,5 @@ The *reactions* plugin displays overall reactions on your recent issues and issu
|
|||||||
plugin_reactions_limit: 200 # Compute reactions over last 200 issue comments
|
plugin_reactions_limit: 200 # Compute reactions over last 200 issue comments
|
||||||
plugin_reactions_days: 14 # Compute reactions on issue comments posted less than 14 days ago
|
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_details: count, percentage # Display reactions count and percentage
|
||||||
|
plugin_reactions_ignored: bot # Ignore "bot" user
|
||||||
```
|
```
|
||||||
@@ -7,7 +7,7 @@
|
|||||||
return null
|
return null
|
||||||
|
|
||||||
//Load inputs
|
//Load inputs
|
||||||
let {limit, days, details, display} = imports.metadata.plugins.reactions.inputs({data, account, q})
|
let {limit, days, details, display, ignored} = imports.metadata.plugins.reactions.inputs({data, account, q})
|
||||||
|
|
||||||
//Load issue comments
|
//Load issue comments
|
||||||
let cursor = null, pushed = 0
|
let cursor = null, pushed = 0
|
||||||
@@ -19,7 +19,9 @@
|
|||||||
const {user:{[type]:{edges}}} = await graphql(queries.reactions({login, type, after:cursor ? `after: "${cursor}"` : ""}))
|
const {user:{[type]:{edges}}} = await graphql(queries.reactions({login, type, after:cursor ? `after: "${cursor}"` : ""}))
|
||||||
cursor = edges?.[edges?.length-1]?.cursor
|
cursor = edges?.[edges?.length-1]?.cursor
|
||||||
//Save issue comments
|
//Save issue comments
|
||||||
const filtered = edges.flatMap(({node:{createdAt:created, reactions:{nodes:reactions}}}) => ({created:new Date(created), reactions:reactions.map(({content}) => content)})).filter(comment => Number.isFinite(days) ? comment.created < new Date(Date.now()-days*24*60*60*1000) : true)
|
const filtered = edges
|
||||||
|
.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
|
pushed = filtered.length
|
||||||
comments.push(...filtered)
|
comments.push(...filtered)
|
||||||
console.debug(`metrics/compute/${login}/plugins > reactions > currently at ${comments.length} comments`)
|
console.debug(`metrics/compute/${login}/plugins > reactions > currently at ${comments.length} comments`)
|
||||||
|
|||||||
@@ -52,3 +52,10 @@ inputs:
|
|||||||
values:
|
values:
|
||||||
- count
|
- count
|
||||||
- percentage
|
- percentage
|
||||||
|
|
||||||
|
# Ignored users (useful to ignore bots users)
|
||||||
|
plugin_reactions_ignored:
|
||||||
|
description: Users to ignore
|
||||||
|
type: array
|
||||||
|
format: comma-separated
|
||||||
|
default: github-actions[bot], dependabot[bot]
|
||||||
@@ -9,6 +9,9 @@ query ReactionsDefault {
|
|||||||
reactions(last: 100, orderBy: {field: CREATED_AT, direction: DESC}) {
|
reactions(last: 100, orderBy: {field: CREATED_AT, direction: DESC}) {
|
||||||
nodes {
|
nodes {
|
||||||
content
|
content
|
||||||
|
user {
|
||||||
|
login
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user