The great refactor (#82)
This commit is contained in:
52
source/plugins/people/README.md
Normal file
52
source/plugins/people/README.md
Normal file
@@ -0,0 +1,52 @@
|
||||
### 🧑🤝🧑 People plugin <sup>🚧 <code>plugin_people_thanks</code>, repository version and "sponsors" on <code>@master</code></sup>
|
||||
|
||||
The *people* plugin can display people you're following or sponsoring, and also users who're following or sponsoring you.
|
||||
In repository mode, it's possible to display sponsors, stargazers, watchers.
|
||||
|
||||
<table>
|
||||
<td align="center">
|
||||
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.people.followers.svg">
|
||||
<details><summary>Followed people version</summary>
|
||||
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.people.following.svg">
|
||||
</details>
|
||||
<details><summary>Special thanks version</summary>
|
||||
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.people.thanks.svg">
|
||||
</details>
|
||||
<details><summary>Repository template version</summary>
|
||||
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.people.repository.svg">
|
||||
</details>
|
||||
<img width="900" height="1" alt="">
|
||||
</td>
|
||||
</table>
|
||||
|
||||
The following types are supported:
|
||||
|
||||
| Type | Alias | User metrics | Repository metrics |
|
||||
| --------------- | ------------------------------------ | :----------------: | :----------------: |
|
||||
| `followers` | | ✔️ | ❌ |
|
||||
| `following` | `followed` | ✔️ | ❌ |
|
||||
| `sponsoring` | `sponsored`, `sponsorshipsAsSponsor` | ✔️ | ❌ |
|
||||
| `sponsors` | `sponsorshipsAsMaintainer` | ✔️ | ✔️ |
|
||||
| `contributors` | | ❌ | ✔️ |
|
||||
| `stargazers` | | ❌ | ✔️ |
|
||||
| `watchers` | | ❌ | ✔️ |
|
||||
| `thanks` | | ✔️ | ✔️ |
|
||||
|
||||
Sections will be ordered the same as specified in `plugin_people_types`.
|
||||
`sponsors` for repositories will output the same as the owner's sponsors.
|
||||
|
||||
#### ℹ️ Examples workflows
|
||||
|
||||
[➡️ Available options for this plugin](metadata.yml)
|
||||
|
||||
```yaml
|
||||
- uses: lowlighter/metrics@latest
|
||||
with:
|
||||
# ... other options
|
||||
plugin_people: yes
|
||||
plugin_people_types: followers, thanks # Display followers and "thanks" sections
|
||||
plugin_people_limit: 28 # Limit to 28 entries per section
|
||||
plugin_people_size: 28 # Size in pixels of displayed avatars
|
||||
plugin_people_identicons: no # Use avatars (do not use identicons)
|
||||
plugin_people_thanks: lowlighter, octocat # Users that will be displayed in "thanks" sections
|
||||
```
|
||||
@@ -20,14 +20,10 @@
|
||||
context = {...context, mode:"repository", types:["contributors", "stargazers", "watchers", "sponsorshipsAsMaintainer", "thanks"], default:"stargazers, watchers", owner, repo}
|
||||
}
|
||||
|
||||
//Parameters override
|
||||
let {"people.limit":limit = 28, "people.types":types = context.default, "people.size":size = 28, "people.identicons":identicons = false, "people.thanks":thanks = []} = q
|
||||
//Limit
|
||||
limit = Math.max(1, limit)
|
||||
//Repositories projects
|
||||
types = [...new Set(decodeURIComponent(types ?? "").split(",").map(type => type.trim()).map(type => (context.alias[type] ?? type)).filter(type => context.types.includes(type)) ?? [])]
|
||||
//Special thanks
|
||||
thanks = decodeURIComponent(thanks ?? "").split(",").map(user => user.trim()).filter(user => user)
|
||||
//Load inputs
|
||||
let {limit, types, size, identicons, thanks} = imports.metadata.plugins.people.inputs({data, account, q}, {types:context.default})
|
||||
//Filter types
|
||||
types = [...new Set([...types].map(type => (context.alias[type] ?? type)).filter(type => context.types.includes(type)) ?? [])]
|
||||
|
||||
//Retrieve followers from graphql api
|
||||
console.debug(`metrics/compute/${login}/plugins > people > querying api`)
|
||||
@@ -52,8 +48,8 @@
|
||||
do {
|
||||
console.debug(`metrics/compute/${login}/plugins > people > retrieving ${type} after ${cursor}`)
|
||||
const {[type]:{edges}} = (
|
||||
type in context.sponsorships ? (await graphql(queries["people.sponsors"]({login:context.owner ?? login, type, size, after:cursor ? `after: "${cursor}"` : "", target:context.sponsorships[type], account})))[account] :
|
||||
context.mode === "repository" ? (await graphql(queries["people.repository"]({login:context.owner, repository:context.repo, type, size, after:cursor ? `after: "${cursor}"` : "", account})))[account].repository :
|
||||
type in context.sponsorships ? (await graphql(queries.people.sponsors({login:context.owner ?? login, type, size, after:cursor ? `after: "${cursor}"` : "", target:context.sponsorships[type], account})))[account] :
|
||||
context.mode === "repository" ? (await graphql(queries.people.repository({login:context.owner, repository:context.repo, type, size, after:cursor ? `after: "${cursor}"` : "", account})))[account].repository :
|
||||
(await graphql(queries.people({login, type, size, after:cursor ? `after: "${cursor}"` : ""}))).user
|
||||
)
|
||||
cursor = edges?.[edges?.length-1]?.cursor
|
||||
|
||||
61
source/plugins/people/metadata.yml
Normal file
61
source/plugins/people/metadata.yml
Normal file
@@ -0,0 +1,61 @@
|
||||
name: "🧑🤝🧑 People plugin"
|
||||
cost: 1 GraphQL request per 100 users + 1 REST request per user in "plugin_people_thanks"
|
||||
supports:
|
||||
- user
|
||||
- organization
|
||||
- repository
|
||||
inputs:
|
||||
|
||||
# Enable or disable plugin
|
||||
plugin_people:
|
||||
description: Display GitHub users from various affiliations
|
||||
type: boolean
|
||||
default: no
|
||||
|
||||
# Number of users to display per section
|
||||
plugin_people_limit:
|
||||
description: Maximum number of user to display
|
||||
type: number
|
||||
default: 28
|
||||
min: 0
|
||||
|
||||
# Size of displayed user's avatar
|
||||
plugin_people_size:
|
||||
description: Size of displayed GitHub users' avatars
|
||||
type: number
|
||||
default: 28
|
||||
min: 8
|
||||
max: 64
|
||||
|
||||
# List of section to display
|
||||
# Ordering will be kept
|
||||
plugin_people_types:
|
||||
description: Affiliations to display
|
||||
type: array
|
||||
format: comma-separated
|
||||
default: followers, following
|
||||
values:
|
||||
- followers # For user metrics
|
||||
- following # For user metrics
|
||||
- followed # For user metrics, alias for "following"
|
||||
- sponsoring # For user metrics
|
||||
- sponsored # Alias for "sponsored"
|
||||
- sponsors # For both user and repository metrics
|
||||
- contributors # For repository metrics
|
||||
- stargazers # For repository metrics
|
||||
- watchers # For repository metrics
|
||||
- thanks # For both user and repository metrics, see "plugin_people_thanks" below
|
||||
|
||||
# When displaying "thanks" section, specified users list will be displayed
|
||||
# This is useful to craft "Special thanks" badges
|
||||
plugin_people_thanks:
|
||||
description: GitHub users to personally thanks
|
||||
type: array
|
||||
format: comma-separated
|
||||
default: ""
|
||||
|
||||
# Use GitHub identicons instead of users' avatar (for privacy purposes)
|
||||
plugin_people_identicons:
|
||||
description: Use identicons instead of avatars
|
||||
type: boolean
|
||||
default: no
|
||||
14
source/plugins/people/queries/people.graphql
Normal file
14
source/plugins/people/queries/people.graphql
Normal file
@@ -0,0 +1,14 @@
|
||||
query PeopleDefault {
|
||||
user(login: "$login") {
|
||||
login
|
||||
$type($after first: 100) {
|
||||
edges {
|
||||
cursor
|
||||
node {
|
||||
login
|
||||
avatarUrl(size: $size)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
15
source/plugins/people/queries/repository.graphql
Normal file
15
source/plugins/people/queries/repository.graphql
Normal file
@@ -0,0 +1,15 @@
|
||||
query PeopleRepository {
|
||||
$account(login: "$login") {
|
||||
repository(name: "$repository") {
|
||||
$type($after first: 100) {
|
||||
edges {
|
||||
cursor
|
||||
node {
|
||||
login
|
||||
avatarUrl(size: $size)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
18
source/plugins/people/queries/sponsors.graphql
Normal file
18
source/plugins/people/queries/sponsors.graphql
Normal file
@@ -0,0 +1,18 @@
|
||||
query PeopleSponsors {
|
||||
$account(login: "$login") {
|
||||
login
|
||||
$type($after first: 100) {
|
||||
edges {
|
||||
cursor
|
||||
node {
|
||||
$target {
|
||||
... on User {
|
||||
login
|
||||
avatarUrl(size: $size)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user