feat(plugins/starlists): add new starlists plugin (#765)
This commit is contained in:
25
source/plugins/starlists/README.md
Normal file
25
source/plugins/starlists/README.md
Normal file
@@ -0,0 +1,25 @@
|
||||
### 💫 Starlists
|
||||
|
||||
The *starlists* plugin displays your recently star lists.
|
||||
|
||||
<table>
|
||||
<td align="center">
|
||||
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.starlist.svg">
|
||||
<img width="900" height="1" alt="">
|
||||
</td>
|
||||
</table>
|
||||
|
||||
#### ℹ️ Examples workflows
|
||||
|
||||
[➡️ Available options for this plugin](metadata.yml)
|
||||
|
||||
```yaml
|
||||
- uses: lowlighter/metrics@latest
|
||||
with:
|
||||
# ... other options
|
||||
plugin_starlists: yes
|
||||
plugin_starlists_limit: 16 # Limit to 16 entries
|
||||
plugin_starlists_limit_repositories: 2 # Limit to 2 repositories per entries
|
||||
plugin_starlists_ignored: list1, list2 # Ignored lists
|
||||
plugin_starlists_only: list3 # Only display this list
|
||||
```
|
||||
55
source/plugins/starlists/index.mjs
Normal file
55
source/plugins/starlists/index.mjs
Normal file
@@ -0,0 +1,55 @@
|
||||
//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.starlists))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
let {limit, ignored, only, "limit.repositories":_limit} = imports.metadata.plugins.starlists.inputs({data, account, q})
|
||||
|
||||
//Start puppeteer and navigate to star lists
|
||||
console.debug(`metrics/compute/${login}/plugins > starlists > starting browser`)
|
||||
const browser = await imports.puppeteer.launch()
|
||||
console.debug(`metrics/compute/${login}/plugins > starlists > started ${await browser.version()}`)
|
||||
const page = await browser.newPage()
|
||||
|
||||
//Fetch star lists
|
||||
console.debug(`metrics/compute/${login}/plugins > starlists > fetching lists`)
|
||||
await page.goto(`https://github.com/${login}?tab=stars`)
|
||||
let lists = (await page.evaluate(() => [...document.querySelectorAll("[href^='/stars/lowlighter/lists']")].map(element => ({
|
||||
link:element.href,
|
||||
name:element.querySelector("h3")?.innerText ?? "",
|
||||
description:element.querySelector("span")?.innerText ?? "",
|
||||
count:Number(element.querySelector("div")?.innerText.match(/(?<count>\d+)/)?.groups.count),
|
||||
repositories:[]
|
||||
}))))
|
||||
const count = lists.length
|
||||
lists = lists.slice(0, limit).filter(({name}) => (only.includes(name.toLocaleLowerCase())) || ((!only.length)&&((!name)||(!ignored.includes(name.toLocaleLowerCase())))))
|
||||
console.debug(`metrics/compute/${login}/plugins > starlists > extracted ${lists.length} lists`)
|
||||
|
||||
//Fetch star list content
|
||||
for (const list of lists) {
|
||||
console.debug(`metrics/compute/${login}/plugins > starlists > fetching ${list.name}`)
|
||||
await page.goto(list.link)
|
||||
const repositories = await page.evaluate(() => [...document.querySelectorAll("#user-list-repositories > div")].map(element => ({
|
||||
name:element.querySelector("div:first-child")?.innerText.replace(" / ", "/") ?? "",
|
||||
description:element.querySelector(".py-1")?.innerText ?? ""
|
||||
})))
|
||||
list.repositories.push(...repositories)
|
||||
list.repositories = list.repositories.slice(0, _limit)
|
||||
}
|
||||
|
||||
//Close browser
|
||||
console.debug(`metrics/compute/${login}/plugins > starlists > closing browser`)
|
||||
await browser.close()
|
||||
|
||||
//Results
|
||||
return {lists, count}
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
throw {error:{message:"An error occured", instance:error}}
|
||||
}
|
||||
}
|
||||
46
source/plugins/starlists/metadata.yml
Normal file
46
source/plugins/starlists/metadata.yml
Normal file
@@ -0,0 +1,46 @@
|
||||
name: "💫 Starlists"
|
||||
category: github
|
||||
index: ~
|
||||
supports:
|
||||
- user
|
||||
scopes: []
|
||||
inputs:
|
||||
|
||||
# Enable or disable plugin
|
||||
plugin_starlists:
|
||||
description: Display star lists
|
||||
type: boolean
|
||||
default: no
|
||||
|
||||
# Number of star lists to display
|
||||
plugin_starlists_limit:
|
||||
description: Number of star lists to display
|
||||
type: number
|
||||
default: 2
|
||||
min: 1
|
||||
max: 100
|
||||
|
||||
# Number of repositories to display per star lists
|
||||
plugin_starlists_limit_repositories:
|
||||
description: Number of repositories to display per star lists
|
||||
type: number
|
||||
default: 2
|
||||
min: 0
|
||||
max: 100
|
||||
|
||||
# List of star lists that will be ignored
|
||||
plugin_starlists_ignored:
|
||||
description: Star lists to skip
|
||||
type: array
|
||||
format: comma-separated
|
||||
default: ""
|
||||
example: 😎 list1, 🥳 list2, ...
|
||||
|
||||
# List of star lists to display
|
||||
# Using this option is equivalent of using "plugin_starlists_ignored" with all star lists but the ones listed
|
||||
plugin_starlists_only:
|
||||
description: Start lists to display
|
||||
type: array
|
||||
format: comma-separated
|
||||
default: ""
|
||||
example: 😎 list1, 🥳 list2, ...
|
||||
5
source/plugins/starlists/tests.yml
Normal file
5
source/plugins/starlists/tests.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
- name: Starlists plugin (default)
|
||||
uses: lowlighter/metrics@latest
|
||||
with:
|
||||
token: MOCKED_TOKEN
|
||||
plugin_starlists: yes
|
||||
Reference in New Issue
Block a user