feat(plugins/reactions): add support for discussions and discussions comments (#637)
This commit is contained in:
@@ -7,32 +7,38 @@ export default async function({login, q, imports, data, graphql, queries, accoun
|
|||||||
return null
|
return null
|
||||||
|
|
||||||
//Load inputs
|
//Load inputs
|
||||||
let {limit:_limit1, "limit.issues":_limit2, days, details, display, ignored} = imports.metadata.plugins.reactions.inputs({data, account, q})
|
let {limit:_limit1, "limit.issues":_limit2, "limit.discussions":_limit3, "limit.discussions.comments":_limit4, days, details, display, ignored} = imports.metadata.plugins.reactions.inputs({data, account, q})
|
||||||
|
|
||||||
//Load issue comments
|
//Load issue comments
|
||||||
const comments = []
|
const comments = []
|
||||||
for (const {type, limit} of [{type:"issueComments", limit:_limit1}, {type:"issues", limit:_limit2}].filter(({limit}) => limit)) {
|
for (const {type, limit} of [{type:"issueComments", limit:_limit1}, {type:"issues", limit:_limit2}, {type:"repositoryDiscussionComments", limit:_limit3}, {type:"repositoryDiscussions", limit:_limit4}].filter(({limit}) => limit)) {
|
||||||
let cursor = null, pushed = 0
|
let cursor = null, pushed = 0
|
||||||
const fetched = []
|
const fetched = []
|
||||||
do {
|
try {
|
||||||
//Load issue comments
|
do {
|
||||||
console.debug(`metrics/compute/${login}/plugins > reactions > retrieving ${type} after ${cursor}`)
|
//Load issue comments
|
||||||
const {user:{[type]:{edges}}} = await graphql(queries.reactions({login, type, after:cursor ? `after: "${cursor}"` : ""}))
|
console.debug(`metrics/compute/${login}/plugins > reactions > retrieving ${type} before ${cursor}`)
|
||||||
cursor = edges?.[edges?.length - 1]?.cursor
|
const {user:{[type]:{edges}}} = await graphql(queries.reactions({login, type, before:cursor ? `before: "${cursor}"` : ""}))
|
||||||
//Save issue comments
|
cursor = edges?.[0]?.cursor
|
||||||
const filtered = edges
|
//Save issue comments
|
||||||
.flatMap(({node:{createdAt:created, reactions:{nodes:reactions}}}) => ({created:new Date(created), reactions:reactions.filter(({user = {}}) => !ignored.includes(user.login)).map(({content}) => content)}))
|
const filtered = edges
|
||||||
.filter(comment => Number.isFinite(days) ? comment.created < new Date(Date.now() - days * 24 * 60 * 60 * 1000) : true)
|
.flatMap(({node:{createdAt:created, reactions:{nodes:reactions}}}) => ({created:new Date(created), reactions:reactions.filter(({user = {}}) => !ignored.includes(user.login)).map(({content}) => content)}))
|
||||||
pushed = filtered.length
|
.filter(comment => Number.isFinite(days) ? comment.created < new Date(Date.now() - days * 24 * 60 * 60 * 1000) : true)
|
||||||
fetched.push(...filtered)
|
pushed = filtered.length
|
||||||
console.debug(`metrics/compute/${login}/plugins > reactions > currently at ${fetched.length} ${type} comments`)
|
fetched.push(...filtered)
|
||||||
//Applying limit
|
console.debug(`metrics/compute/${login}/plugins > reactions > currently at ${fetched.length} ${type} comments`)
|
||||||
if ((fetched.length >= limit) || (filtered.length < edges.length)) {
|
//Applying limit
|
||||||
fetched.splice(limit)
|
if ((fetched.length >= limit) || (filtered.length < edges.length)) {
|
||||||
console.debug(`metrics/compute/${login}/plugins > reactions > keeping only ${fetched.length} ${type} comments`)
|
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)
|
} while ((cursor) && (pushed) && (fetched.length < limit))
|
||||||
|
comments.push(...fetched)
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.debug(error)
|
||||||
|
console.debug(`metrics/compute/${login}/plugins > reactions > an error occured while retrieving ${type}`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
console.debug(`metrics/compute/${login}/plugins > reactions > fetched ${comments.length} comments`)
|
console.debug(`metrics/compute/${login}/plugins > reactions > fetched ${comments.length} comments`)
|
||||||
|
|
||||||
|
|||||||
@@ -28,10 +28,26 @@ inputs:
|
|||||||
min: 0
|
min: 0
|
||||||
max: 1000
|
max: 1000
|
||||||
|
|
||||||
|
# Maximum number of discussions opened to parse
|
||||||
|
plugin_reactions_limit_discussions:
|
||||||
|
description: Maximum number of discussions opened to parse
|
||||||
|
type: number
|
||||||
|
default: 100
|
||||||
|
min: 0
|
||||||
|
max: 1000
|
||||||
|
|
||||||
|
# Maximum number of discussions comments opened to parse
|
||||||
|
plugin_reactions_limit_discussions_comments:
|
||||||
|
description: Maximum number of discussions comments opened to parse
|
||||||
|
type: number
|
||||||
|
default: 100
|
||||||
|
min: 0
|
||||||
|
max: 1000
|
||||||
|
|
||||||
# Filter reactions by issue comments age
|
# Filter reactions by issue comments age
|
||||||
# Set to 0 to disable age filtering
|
# Set to 0 to disable age filtering
|
||||||
plugin_reactions_days:
|
plugin_reactions_days:
|
||||||
description: Maximum issue comments age
|
description: Maximum comments age
|
||||||
type: number
|
type: number
|
||||||
default: 0
|
default: 0
|
||||||
min: 0
|
min: 0
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
query ReactionsDefault {
|
query ReactionsDefault {
|
||||||
user(login: "$login") {
|
user(login: "$login") {
|
||||||
login
|
login
|
||||||
$type($after first: 100, orderBy: {field: UPDATED_AT, direction: DESC}) {
|
$type($before last: 50) {
|
||||||
edges {
|
edges {
|
||||||
cursor
|
cursor
|
||||||
node {
|
node {
|
||||||
|
|||||||
Reference in New Issue
Block a user