Add GitHub community support plugin (#231)
This commit is contained in:
23
source/plugins/support/README.md
Normal file
23
source/plugins/support/README.md
Normal file
@@ -0,0 +1,23 @@
|
||||
### 🗨️ GitHub Community Support
|
||||
|
||||
The *support* plugin lets you display your statistics from [GitHub Support Community](https://github.community/).
|
||||
|
||||
<table>
|
||||
<td align="center">
|
||||
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.support.svg">
|
||||
<img width="900" height="1" alt="">
|
||||
</td>
|
||||
</table>
|
||||
|
||||
An account on [GitHub Support Community](https://github.community/) is required to use this plugin.
|
||||
|
||||
#### ℹ️ Examples workflows
|
||||
|
||||
[➡️ Available options for this plugin](metadata.yml)
|
||||
|
||||
```yaml
|
||||
- uses: lowlighter/metrics@latest
|
||||
with:
|
||||
# ... other options
|
||||
plugin_support: yes
|
||||
```
|
||||
81
source/plugins/support/index.mjs
Normal file
81
source/plugins/support/index.mjs
Normal file
@@ -0,0 +1,81 @@
|
||||
//Setup
|
||||
export default async function({login, q, imports, data, account}, {enabled = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled)||(!q.support))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
imports.metadata.plugins.stackoverflow.inputs({data, account, q})
|
||||
|
||||
//Start puppeteer and navigate to github.community
|
||||
const result = {stats:{solutions:0, posts:0, topics:0, received:0}, badges:{count:0}}
|
||||
console.debug(`metrics/compute/${login}/plugins > support > starting browser`)
|
||||
const browser = await imports.puppeteer.launch()
|
||||
console.debug(`metrics/compute/${login}/plugins > support > started ${await browser.version()}`)
|
||||
const page = await browser.newPage()
|
||||
|
||||
//Check account existence
|
||||
{
|
||||
await page.goto(`https://github.community/u/${login}`)
|
||||
const frame = page.mainFrame()
|
||||
try {
|
||||
await frame.waitForSelector(".user-profile-names", {timeout:5000})
|
||||
}
|
||||
catch {
|
||||
throw {error:{message:"Could not find matching account on github.community"}}
|
||||
}
|
||||
}
|
||||
|
||||
//Stats
|
||||
{
|
||||
await page.goto(`https://github.community/u/${login}/summary`)
|
||||
const frame = page.mainFrame()
|
||||
await frame.waitForSelector(".stats-section")
|
||||
Object.assign(result.stats, Object.fromEntries((await frame.evaluate(() => [...document.querySelectorAll(".stats-section li")].map(el => [
|
||||
el.querySelector(".label").innerText.trim().toLocaleLowerCase(),
|
||||
el.querySelector(".value").innerText.trim().toLocaleLowerCase(),
|
||||
]))).map(([key, value]) => {
|
||||
switch (true) {
|
||||
case /solutions?/.test(key):
|
||||
return ["solutions", Number(value)]
|
||||
case /posts? created/.test(key):
|
||||
return ["posts", Number(value)]
|
||||
case /topics? created/.test(key):
|
||||
return ["topics", Number(value)]
|
||||
case /received/.test(key):
|
||||
return ["hearts", Number(value)]
|
||||
default:
|
||||
return null
|
||||
}
|
||||
}).filter(kv => kv)))
|
||||
}
|
||||
|
||||
//Badges
|
||||
{
|
||||
await page.goto(`https://github.community/u/${login}/badges`)
|
||||
const frame = page.mainFrame()
|
||||
await frame.waitForSelector(".user-badges-list")
|
||||
const badges = await frame.evaluate(() => ({
|
||||
uniques:[...document.querySelectorAll(".badge-card .badge-link")].map(el => el.innerText),
|
||||
multiples:[...document.querySelectorAll(".grant-count")].map(el => Number(el.innerText)),
|
||||
}))
|
||||
badges.count = badges.uniques.length + (badges.multiples.reduce((a, b) => a + b, 0) - badges.multiples.length)
|
||||
result.badges = badges
|
||||
}
|
||||
|
||||
//Close browser
|
||||
console.debug(`metrics/compute/${login}/plugins > support > closing browser`)
|
||||
await browser.close()
|
||||
|
||||
//Results
|
||||
return result
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
if (error.error?.message)
|
||||
throw error
|
||||
throw {error:{message:"An error occured", instance:error}}
|
||||
}
|
||||
}
|
||||
12
source/plugins/support/metadata.yml
Normal file
12
source/plugins/support/metadata.yml
Normal file
@@ -0,0 +1,12 @@
|
||||
name: "🗨️ GitHub Community Support"
|
||||
cost: N/A
|
||||
categorie: github
|
||||
supports:
|
||||
- user
|
||||
inputs:
|
||||
|
||||
# Enable or disable plugin
|
||||
plugin_support:
|
||||
description: GitHub Community Support metrics
|
||||
type: boolean
|
||||
default: no
|
||||
5
source/plugins/support/tests.yml
Normal file
5
source/plugins/support/tests.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
- name: Support plugin (default)
|
||||
uses: lowlighter/metrics@latest
|
||||
with:
|
||||
token: MOCKED_TOKEN
|
||||
plugin_support: yes
|
||||
Reference in New Issue
Block a user