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
|
||||
@@ -25,6 +25,7 @@
|
||||
"anilist",
|
||||
"wakatime",
|
||||
"skyline",
|
||||
"support",
|
||||
"stackoverflow",
|
||||
"stock",
|
||||
"achievements",
|
||||
|
||||
45
source/templates/classic/partials/support.ejs
Normal file
45
source/templates/classic/partials/support.ejs
Normal file
@@ -0,0 +1,45 @@
|
||||
<% if (plugins.support) { %>
|
||||
<section>
|
||||
<h2 class="field">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M6.415.52a2.678 2.678 0 013.17 0l.928.68c.153.113.33.186.518.215l1.138.175a2.678 2.678 0 012.241 2.24l.175 1.138c.029.187.102.365.215.518l.68.928a2.678 2.678 0 010 3.17l-.68.928a1.179 1.179 0 00-.215.518l-.175 1.138a2.678 2.678 0 01-2.241 2.241l-1.138.175a1.179 1.179 0 00-.518.215l-.928.68a2.678 2.678 0 01-3.17 0l-.928-.68a1.179 1.179 0 00-.518-.215L3.83 14.41a2.678 2.678 0 01-2.24-2.24l-.175-1.138a1.179 1.179 0 00-.215-.518l-.68-.928a2.678 2.678 0 010-3.17l.68-.928a1.17 1.17 0 00.215-.518l.175-1.14a2.678 2.678 0 012.24-2.24l1.138-.175c.187-.029.365-.102.518-.215l.928-.68zm2.282 1.209a1.178 1.178 0 00-1.394 0l-.928.68a2.678 2.678 0 01-1.18.489l-1.136.174a1.178 1.178 0 00-.987.987l-.174 1.137a2.678 2.678 0 01-.489 1.18l-.68.927c-.305.415-.305.98 0 1.394l.68.928c.256.348.423.752.489 1.18l.174 1.136c.078.51.478.909.987.987l1.137.174c.427.066.831.233 1.18.489l.927.68c.415.305.98.305 1.394 0l.928-.68a2.678 2.678 0 011.18-.489l1.136-.174c.51-.078.909-.478.987-.987l.174-1.137c.066-.427.233-.831.489-1.18l.68-.927c.305-.415.305-.98 0-1.394l-.68-.928a2.678 2.678 0 01-.489-1.18l-.174-1.136a1.178 1.178 0 00-.987-.987l-1.137-.174a2.678 2.678 0 01-1.18-.489l-.927-.68zM9 11a1 1 0 11-2 0 1 1 0 012 0zM6.92 6.085c.081-.16.19-.299.34-.398.145-.097.371-.187.74-.187.28 0 .553.087.738.225A.613.613 0 019 6.25c0 .177-.04.264-.077.318a.956.956 0 01-.277.245c-.076.051-.158.1-.258.161l-.007.004c-.093.056-.204.122-.313.195a2.416 2.416 0 00-.692.661.75.75 0 001.248.832.956.956 0 01.276-.245 6.3 6.3 0 01.26-.16l.006-.004c.093-.057.204-.123.313-.195.222-.149.487-.355.692-.662.214-.32.329-.702.329-1.15 0-.76-.36-1.348-.862-1.725A2.76 2.76 0 008 4c-.631 0-1.154.16-1.572.438-.413.276-.68.638-.849.977a.75.75 0 001.342.67z"></path></svg>
|
||||
GitHub Support Community
|
||||
</h2>
|
||||
<% if (plugins.support.error) { %>
|
||||
<div class="row">
|
||||
<section>
|
||||
<div class="field error">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16" width="16" height="16"><path fill-rule="evenodd" d="M2.343 13.657A8 8 0 1113.657 2.343 8 8 0 012.343 13.657zM6.03 4.97a.75.75 0 00-1.06 1.06L6.94 8 4.97 9.97a.75.75 0 101.06 1.06L8 9.06l1.97 1.97a.75.75 0 101.06-1.06L9.06 8l1.97-1.97a.75.75 0 10-1.06-1.06L8 6.94 6.03 4.97z"></path></svg>
|
||||
<%= plugins.support.error.message %>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
<% } else { %>
|
||||
<div class="row">
|
||||
<section>
|
||||
<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="M4.25 2.5c-1.336 0-2.75 1.164-2.75 3 0 2.15 1.58 4.144 3.365 5.682A20.565 20.565 0 008 13.393a20.561 20.561 0 003.135-2.211C12.92 9.644 14.5 7.65 14.5 5.5c0-1.836-1.414-3-2.75-3-1.373 0-2.609.986-3.029 2.456a.75.75 0 01-1.442 0C6.859 3.486 5.623 2.5 4.25 2.5zM8 14.25l-.345.666-.002-.001-.006-.003-.018-.01a7.643 7.643 0 01-.31-.17 22.075 22.075 0 01-3.434-2.414C2.045 10.731 0 8.35 0 5.5 0 2.836 2.086 1 4.25 1 5.797 1 7.153 1.802 8 3.02 8.847 1.802 10.203 1 11.75 1 13.914 1 16 2.836 16 5.5c0 2.85-2.045 5.231-3.885 6.818a22.08 22.08 0 01-3.744 2.584l-.018.01-.006.003h-.002L8 14.25zm0 0l.345.666a.752.752 0 01-.69 0L8 14.25z"></path></svg>
|
||||
<%= plugins.support.stats.hearts %> heart<%= s(plugins.support.stats.hearts) %> received
|
||||
</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="M8 1.5a6.5 6.5 0 100 13 6.5 6.5 0 000-13zM0 8a8 8 0 1116 0A8 8 0 010 8zm9 3a1 1 0 11-2 0 1 1 0 012 0zM6.92 6.085c.081-.16.19-.299.34-.398.145-.097.371-.187.74-.187.28 0 .553.087.738.225A.613.613 0 019 6.25c0 .177-.04.264-.077.318a.956.956 0 01-.277.245c-.076.051-.158.1-.258.161l-.007.004a7.728 7.728 0 00-.313.195 2.416 2.416 0 00-.692.661.75.75 0 001.248.832.956.956 0 01.276-.245 6.3 6.3 0 01.26-.16l.006-.004c.093-.057.204-.123.313-.195.222-.149.487-.355.692-.662.214-.32.329-.702.329-1.15 0-.76-.36-1.348-.863-1.725A2.76 2.76 0 008 4c-.631 0-1.155.16-1.572.438-.413.276-.68.638-.849.977a.75.75 0 101.342.67z"></path></svg>
|
||||
<%= plugins.support.stats.topics %> topic<%= s(plugins.support.stats.topics) %> created
|
||||
</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="M2.75 2.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-7.5a.25.25 0 00-.25-.25H2.75zM1 2.75C1 1.784 1.784 1 2.75 1h10.5c.966 0 1.75.784 1.75 1.75v7.5A1.75 1.75 0 0113.25 12H9.06l-2.573 2.573A1.457 1.457 0 014 13.543V12H2.75A1.75 1.75 0 011 10.25v-7.5z"></path></svg>
|
||||
<%= plugins.support.stats.posts %> post<%= s(plugins.support.stats.posts) %>
|
||||
</div>
|
||||
</section>
|
||||
<section>
|
||||
<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.637 2.291A.75.75 0 014.23 2h7.54a.75.75 0 01.593.291l3.48 4.5a.75.75 0 01-.072.999l-7.25 7a.75.75 0 01-1.042 0l-7.25-7a.75.75 0 01-.072-.999l3.48-4.5zM4.598 3.5L1.754 7.177 8 13.207l6.246-6.03L11.402 3.5H4.598z"></path></svg>
|
||||
<%= plugins.support.badges.count %> badge<%= s(plugins.support.badges.count) %>
|
||||
</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="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.support.stats.solutions %> solution<%= s(plugins.support.stats.solutions) %>
|
||||
</div>
|
||||
</section>
|
||||
</div>
|
||||
<% } %>
|
||||
</section>
|
||||
<% } %>
|
||||
Reference in New Issue
Block a user