Discussions plugin: Add upvotes statistics (#469)
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
|
||||
//Load inputs
|
||||
imports.metadata.plugins.discussions.inputs({data, account, q})
|
||||
const discussions = {categories:{}}
|
||||
const discussions = {categories:{}, upvotes:{discussions:0, comments:0}}
|
||||
|
||||
//Fetch general statistics
|
||||
const stats = Object.fromEntries(Object.entries((await graphql(queries.discussions.statistics({login}))).user).map(([key, value]) => [key, value.totalCount]))
|
||||
@@ -29,6 +29,9 @@
|
||||
console.debug(`metrics/compute/${login}/discussions > retrieved ${pushed} discussions after ${cursor}`)
|
||||
} while ((pushed) && (cursor))
|
||||
|
||||
//Compute upvotes
|
||||
fetched.map(({upvoteCount}) => discussions.upvotes.discussions += upvoteCount)
|
||||
|
||||
//Compute favorite category
|
||||
for (const category of [...fetched.map(({category:{emoji, name}}) => `${imports.emoji.get(emoji)} ${name}`)])
|
||||
categories[category] = (categories[category] ?? 0) + 1
|
||||
@@ -37,6 +40,24 @@
|
||||
discussions.categories.favorite = categoryEntries[0]?.[0] ?? null
|
||||
}
|
||||
|
||||
//Load comments
|
||||
{
|
||||
const fetched = []
|
||||
let cursor = null
|
||||
let pushed = 0
|
||||
do {
|
||||
console.debug(`metrics/compute/${login}/discussions > retrieving comments after ${cursor}`)
|
||||
const {user:{repositoryDiscussionComments:{edges = [], nodes = []} = {}}} = await graphql(queries.discussions.comments({login, after:cursor ? `after: "${cursor}"` : ""}))
|
||||
cursor = edges?.[edges?.length - 1]?.cursor
|
||||
fetched.push(...nodes)
|
||||
pushed = nodes.length
|
||||
console.debug(`metrics/compute/${login}/discussions > retrieved ${pushed} comments after ${cursor}`)
|
||||
} while ((pushed) && (cursor))
|
||||
|
||||
//Compute upvotes
|
||||
fetched.map(({upvoteCount}) => discussions.upvotes.comments += upvoteCount)
|
||||
}
|
||||
|
||||
//Results
|
||||
return discussions
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user