feat(plugins/reactions): add support for discussions and discussions comments (#637)
This commit is contained in:
@@ -7,18 +7,19 @@ export default async function({login, q, imports, data, graphql, queries, accoun
|
||||
return null
|
||||
|
||||
//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
|
||||
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
|
||||
const fetched = []
|
||||
try {
|
||||
do {
|
||||
//Load issue comments
|
||||
console.debug(`metrics/compute/${login}/plugins > reactions > retrieving ${type} after ${cursor}`)
|
||||
const {user:{[type]:{edges}}} = await graphql(queries.reactions({login, type, after:cursor ? `after: "${cursor}"` : ""}))
|
||||
cursor = edges?.[edges?.length - 1]?.cursor
|
||||
console.debug(`metrics/compute/${login}/plugins > reactions > retrieving ${type} before ${cursor}`)
|
||||
const {user:{[type]:{edges}}} = await graphql(queries.reactions({login, type, before:cursor ? `before: "${cursor}"` : ""}))
|
||||
cursor = edges?.[0]?.cursor
|
||||
//Save issue comments
|
||||
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)}))
|
||||
@@ -34,6 +35,11 @@ export default async function({login, q, imports, data, graphql, queries, accoun
|
||||
} 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`)
|
||||
|
||||
//Format reactions list
|
||||
|
||||
@@ -28,10 +28,26 @@ inputs:
|
||||
min: 0
|
||||
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
|
||||
# Set to 0 to disable age filtering
|
||||
plugin_reactions_days:
|
||||
description: Maximum issue comments age
|
||||
description: Maximum comments age
|
||||
type: number
|
||||
default: 0
|
||||
min: 0
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
query ReactionsDefault {
|
||||
user(login: "$login") {
|
||||
login
|
||||
$type($after first: 100, orderBy: {field: UPDATED_AT, direction: DESC}) {
|
||||
$type($before last: 50) {
|
||||
edges {
|
||||
cursor
|
||||
node {
|
||||
|
||||
Reference in New Issue
Block a user