Discussions plugin: Add upvotes statistics (#469)
This commit is contained in:
22
source/app/mocks/api/github/graphql/discussions.comments.mjs
Normal file
22
source/app/mocks/api/github/graphql/discussions.comments.mjs
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
/**Mocked data */
|
||||||
|
export default function({faker, query, login = faker.internet.userName()}) {
|
||||||
|
console.debug("metrics/compute/mocks > mocking graphql api result > discussions/comments")
|
||||||
|
return /after: "MOCKED_CURSOR"/m.test(query)
|
||||||
|
? ({
|
||||||
|
user:{
|
||||||
|
repositoryDiscussionsComments:{
|
||||||
|
edges:[],
|
||||||
|
nodes:[],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
: ({
|
||||||
|
user:{
|
||||||
|
repositoryDiscussionsComments:{
|
||||||
|
edges:new Array(100).fill(null).map(_ => ({cursor:"MOCKED_CURSOR"})),
|
||||||
|
nodes:new Array(100).fill(null).map(_ => ({upvoteCount: faker.datatype.number(10)}))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
@@ -594,6 +594,7 @@
|
|||||||
stats: { '🙏 Q&A': faker.datatype.number(100), '📣 Announcements': faker.datatype.number(100), '💡 Ideas': faker.datatype.number(100), '💬 General': faker.datatype.number(100) },
|
stats: { '🙏 Q&A': faker.datatype.number(100), '📣 Announcements': faker.datatype.number(100), '💡 Ideas': faker.datatype.number(100), '💬 General': faker.datatype.number(100) },
|
||||||
favorite: '📣 Announcements'
|
favorite: '📣 Announcements'
|
||||||
},
|
},
|
||||||
|
upvotes: { discussions:faker.datatype.number(1000), comments: faker.datatype.number(1000) },
|
||||||
started: faker.datatype.number(1000),
|
started: faker.datatype.number(1000),
|
||||||
comments: faker.datatype.number(1000),
|
comments: faker.datatype.number(1000),
|
||||||
answers: faker.datatype.number(1000),
|
answers: faker.datatype.number(1000),
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
//Load inputs
|
//Load inputs
|
||||||
imports.metadata.plugins.discussions.inputs({data, account, q})
|
imports.metadata.plugins.discussions.inputs({data, account, q})
|
||||||
const discussions = {categories:{}}
|
const discussions = {categories:{}, upvotes:{discussions:0, comments:0}}
|
||||||
|
|
||||||
//Fetch general statistics
|
//Fetch general statistics
|
||||||
const stats = Object.fromEntries(Object.entries((await graphql(queries.discussions.statistics({login}))).user).map(([key, value]) => [key, value.totalCount]))
|
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}`)
|
console.debug(`metrics/compute/${login}/discussions > retrieved ${pushed} discussions after ${cursor}`)
|
||||||
} while ((pushed) && (cursor))
|
} while ((pushed) && (cursor))
|
||||||
|
|
||||||
|
//Compute upvotes
|
||||||
|
fetched.map(({upvoteCount}) => discussions.upvotes.discussions += upvoteCount)
|
||||||
|
|
||||||
//Compute favorite category
|
//Compute favorite category
|
||||||
for (const category of [...fetched.map(({category:{emoji, name}}) => `${imports.emoji.get(emoji)} ${name}`)])
|
for (const category of [...fetched.map(({category:{emoji, name}}) => `${imports.emoji.get(emoji)} ${name}`)])
|
||||||
categories[category] = (categories[category] ?? 0) + 1
|
categories[category] = (categories[category] ?? 0) + 1
|
||||||
@@ -37,6 +40,24 @@
|
|||||||
discussions.categories.favorite = categoryEntries[0]?.[0] ?? null
|
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
|
//Results
|
||||||
return discussions
|
return discussions
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ query DiscussionsCategories {
|
|||||||
cursor
|
cursor
|
||||||
}
|
}
|
||||||
nodes {
|
nodes {
|
||||||
|
upvoteCount
|
||||||
category {
|
category {
|
||||||
emoji
|
emoji
|
||||||
name
|
name
|
||||||
|
|||||||
12
source/plugins/discussions/queries/comments.graphql
Normal file
12
source/plugins/discussions/queries/comments.graphql
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
query DiscussionsComments {
|
||||||
|
user(login: "$login") {
|
||||||
|
repositoryDiscussionComments($after first: 100) {
|
||||||
|
edges {
|
||||||
|
cursor
|
||||||
|
}
|
||||||
|
nodes {
|
||||||
|
upvoteCount
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,13 +24,21 @@
|
|||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M16 1.25v4.146a.25.25 0 01-.427.177L14.03 4.03l-3.75 3.75a.75.75 0 11-1.06-1.06l3.75-3.75-1.543-1.543A.25.25 0 0111.604 1h4.146a.25.25 0 01.25.25zM2.75 3.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h2a.75.75 0 01.75.75v2.19l2.72-2.72a.75.75 0 01.53-.22h4.5a.25.25 0 00.25-.25v-2.5a.75.75 0 111.5 0v2.5A1.75 1.75 0 0113.25 13H9.06l-2.573 2.573A1.457 1.457 0 014 14.543V13H2.75A1.75 1.75 0 011 11.25v-7.5C1 2.784 1.784 2 2.75 2h5.5a.75.75 0 010 1.5h-5.5z"></path></svg>
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M16 1.25v4.146a.25.25 0 01-.427.177L14.03 4.03l-3.75 3.75a.75.75 0 11-1.06-1.06l3.75-3.75-1.543-1.543A.25.25 0 0111.604 1h4.146a.25.25 0 01.25.25zM2.75 3.5a.25.25 0 00-.25.25v7.5c0 .138.112.25.25.25h2a.75.75 0 01.75.75v2.19l2.72-2.72a.75.75 0 01.53-.22h4.5a.25.25 0 00.25-.25v-2.5a.75.75 0 111.5 0v2.5A1.75 1.75 0 0113.25 13H9.06l-2.573 2.573A1.457 1.457 0 014 14.543V13H2.75A1.75 1.75 0 011 11.25v-7.5C1 2.784 1.784 2 2.75 2h5.5a.75.75 0 010 1.5h-5.5z"></path></svg>
|
||||||
<%= plugins.discussions.comments %> Comment<%= s(plugins.discussions.comments) %>
|
<%= plugins.discussions.comments %> Comment<%= s(plugins.discussions.comments) %>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
|
||||||
<section class="largeable-column-fields">
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M1.5 8a6.5 6.5 0 1113 0 6.5 6.5 0 01-13 0zM0 8a8 8 0 1116 0A8 8 0 010 8zm11.78-1.72a.75.75 0 00-1.06-1.06L6.75 9.19 5.28 7.72a.75.75 0 00-1.06 1.06l2 2a.75.75 0 001.06 0l4.5-4.5z"></path></svg>
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M1.5 8a6.5 6.5 0 1113 0 6.5 6.5 0 01-13 0zM0 8a8 8 0 1116 0A8 8 0 010 8zm11.78-1.72a.75.75 0 00-1.06-1.06L6.75 9.19 5.28 7.72a.75.75 0 00-1.06 1.06l2 2a.75.75 0 001.06 0l4.5-4.5z"></path></svg>
|
||||||
<%= plugins.discussions.answers %> Answer<%= s(plugins.discussions.answers) %>
|
<%= plugins.discussions.answers %> Answer<%= s(plugins.discussions.answers) %>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
<section class="largeable-column-fields">
|
||||||
|
<div class="field">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M8.53 1.22a.75.75 0 00-1.06 0L3.72 4.97a.75.75 0 001.06 1.06l2.47-2.47v6.69a.75.75 0 001.5 0V3.56l2.47 2.47a.75.75 0 101.06-1.06L8.53 1.22zM3.75 13a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5z"></path></svg>
|
||||||
|
<%= plugins.discussions.upvotes.discussions %> Upvote<%= s(plugins.discussions.upvotes.discussions) %> from discussions
|
||||||
|
</div>
|
||||||
|
<div class="field">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M3.47 7.78a.75.75 0 010-1.06l4.25-4.25a.75.75 0 011.06 0l4.25 4.25a.75.75 0 01-1.06 1.06L9 4.81v7.44a.75.75 0 01-1.5 0V4.81L4.53 7.78a.75.75 0 01-1.06 0z"></path></svg>
|
||||||
|
<%= plugins.discussions.upvotes.comments %> Upvote<%= s(plugins.discussions.upvotes.comments) %> from comments
|
||||||
|
</div>
|
||||||
|
</section>
|
||||||
</div>
|
</div>
|
||||||
<% if (Object.keys(plugins.discussions.categories.stats).length) { %>
|
<% if (Object.keys(plugins.discussions.categories.stats).length) { %>
|
||||||
<div class="row fill-width">
|
<div class="row fill-width">
|
||||||
|
|||||||
Reference in New Issue
Block a user