feat(plugins/sponsors): add new sponsors plugin (#548)
This commit is contained in:
25
source/plugins/sponsors/README.md
Normal file
25
source/plugins/sponsors/README.md
Normal file
@@ -0,0 +1,25 @@
|
||||
### 💕 GitHub Sponsors
|
||||
|
||||
The *sponsors* plugin lets you display your sponsors and introduction text from [GitHub sponsors](https://github.com/sponsors/).
|
||||
|
||||
<table>
|
||||
<td align="center">
|
||||
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.sponsors.svg">
|
||||
<details><summary>With GitHub sponsors introduction</summary>
|
||||
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.sponsors.full.svg">
|
||||
</details>
|
||||
<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_sponsors: yes
|
||||
plugin_sponsors_sections: goal, about # Display goal and about sections
|
||||
```
|
||||
26
source/plugins/sponsors/index.mjs
Normal file
26
source/plugins/sponsors/index.mjs
Normal file
@@ -0,0 +1,26 @@
|
||||
//Setup
|
||||
export default async function({login, q, imports, data, graphql, queries, account}, {enabled = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled)||(!q.sponsors))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
const {sections} = await imports.metadata.plugins.sponsors.inputs({data, account, q})
|
||||
|
||||
//Query sponsors and goal
|
||||
const {[account]:{sponsorsListing:{fullDescription, activeGoal}, sponsorshipsAsMaintainer:{nodes, totalCount:count}}} = await graphql(queries.sponsors({login, account}))
|
||||
const about = await imports.markdown(fullDescription, {mode:"multiline"})
|
||||
const goal = activeGoal ? {progress:activeGoal.percentComplete, title:activeGoal.title, description:await imports.markdown(activeGoal.description)} : null
|
||||
const list = nodes.map(({sponsorEntity:{login, avatarUrl}, tier:{monthlyPriceInDollars:amount}}) => ({login, avatarUrl, amount}))
|
||||
await Promise.all(list.map(async user => user.avatar = await imports.imgb64(user.avatarUrl)))
|
||||
|
||||
//Results
|
||||
return {sections, about, list, count, goal}
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
throw {error:{message:"An error occured", instance:error}}
|
||||
}
|
||||
}
|
||||
25
source/plugins/sponsors/metadata.yml
Normal file
25
source/plugins/sponsors/metadata.yml
Normal file
@@ -0,0 +1,25 @@
|
||||
name: "💕 GitHub Sponsors"
|
||||
cost: 1 GraphQL request
|
||||
category: github
|
||||
index: 23
|
||||
supports:
|
||||
- user
|
||||
- organization
|
||||
inputs:
|
||||
|
||||
# Enable or disable plugin
|
||||
plugin_sponsors:
|
||||
description: Display GitHub sponsors
|
||||
type: boolean
|
||||
default: no
|
||||
|
||||
# Sections to display
|
||||
plugin_sponsors_sections:
|
||||
description: Sections to display
|
||||
type: array
|
||||
format: comma-separated
|
||||
default: goal, about
|
||||
example: goal, about
|
||||
values:
|
||||
- goal # Display your GitHub active goal
|
||||
- about # Display your GitHub sponsors introduction
|
||||
26
source/plugins/sponsors/queries/sponsors.graphql
Normal file
26
source/plugins/sponsors/queries/sponsors.graphql
Normal file
@@ -0,0 +1,26 @@
|
||||
query SponsorsDefault {
|
||||
$account(login: "$login") {
|
||||
sponsorsListing {
|
||||
fullDescription
|
||||
activeGoal {
|
||||
percentComplete
|
||||
title
|
||||
description
|
||||
}
|
||||
}
|
||||
sponsorshipsAsMaintainer(first: 100) {
|
||||
totalCount
|
||||
nodes {
|
||||
sponsorEntity {
|
||||
... on User {
|
||||
login
|
||||
avatarUrl(size: 36)
|
||||
}
|
||||
}
|
||||
tier {
|
||||
monthlyPriceInDollars
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
5
source/plugins/sponsors/tests.yml
Normal file
5
source/plugins/sponsors/tests.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
- name: Sponsors plugin (default)
|
||||
uses: lowlighter/metrics@latest
|
||||
with:
|
||||
token: MOCKED_TOKEN
|
||||
plugin_sponsors: yes
|
||||
Reference in New Issue
Block a user