Skip to content

Commit 30414a0

Browse files
authored
Add plugin_people_sponsors_custom option (lowlighter#166)
1 parent 657171a commit 30414a0

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

source/plugins/people/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ Sections will be ordered the same as specified in `plugin_people_types`.
5050
plugin_people_limit: 28 # Limit to 28 entries per section
5151
plugin_people_size: 28 # Size in pixels of displayed avatars
5252
plugin_people_identicons: no # Use avatars (do not use identicons)
53-
plugin_people_thanks: lowlighter, octocat # Users that will be displayed in "thanks" sections
53+
plugin_people_thanks: lowlighter, octocat # Users that will be displayed in "thanks" section
54+
plugin_people_sponsors_custom: octocat # Users that will be displayed additionally in "sponsors" section
5455
plugin_people_shuffle: yes # Shuffle for varied output
5556
```

source/plugins/people/index.mjs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@
2121
}
2222

2323
//Load inputs
24-
let {limit, types, size, identicons, thanks, shuffle} = imports.metadata.plugins.people.inputs({data, account, q}, {types:context.default})
24+
let {limit, types, size, identicons, thanks, shuffle, "sponsors.custom":_sponsors} = imports.metadata.plugins.people.inputs({data, account, q}, {types:context.default})
2525
//Filter types
2626
types = [...new Set([...types].map(type => (context.alias[type] ?? type)).filter(type => context.types.includes(type)) ?? [])]
27+
if ((types.includes("sponsorshipsAsMaintainer"))&&(_sponsors?.length)) {
28+
types.unshift("sponsorshipsCustom")
29+
data.user.sponsorshipsAsMaintainer.totalCount += _sponsors.length
30+
}
2731

2832
//Retrieve followers from graphql api
2933
console.debug(`metrics/compute/${login}/plugins > people > querying api`)
@@ -37,9 +41,10 @@
3741
const {data:nodes} = await rest.repos.listContributors({owner, repo})
3842
result[type].push(...nodes.map(({login, avatar_url}) => ({login, avatarUrl:avatar_url})))
3943
}
40-
else if (type === "thanks") {
41-
const nodes = await Promise.all(thanks.map(async username => (await rest.users.getByUsername({username})).data))
42-
result[type].push(...nodes.map(({login, avatar_url}) => ({login, avatarUrl:avatar_url})))
44+
else if ((type === "thanks")||(type === "sponsorshipsCustom")) {
45+
const users = {thanks, sponsorshipsCustom:_sponsors}[type] ?? []
46+
const nodes = await Promise.all(users.map(async username => (await rest.users.getByUsername({username})).data))
47+
result[{sponsorshipsCustom:"sponsorshipsAsMaintainer"}[type] ?? type].push(...nodes.map(({login, avatar_url}) => ({login, avatarUrl:avatar_url})))
4348
}
4449
//GraphQL
4550
else {
@@ -77,6 +82,10 @@
7782
await Promise.all(result[type].map(async user => user.avatar = await imports.imgb64(user.avatarUrl)))
7883
}
7984

85+
//Special type handling
86+
if (types.includes("sponsorshipsCustom"))
87+
types.splice(types.indexOf("sponsorshipsCustom"), 1)
88+
8089
//Results
8190
return {types, size, ...result}
8291
}

source/plugins/people/metadata.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ inputs:
5757
format: comma-separated
5858
default: ""
5959

60+
# Add specified users to GitHub sponsors ("sponsors" must be specified in "plugin_people_types")
61+
# This is useful to list sponsors from unsupported GitHub sponsors sources
62+
plugin_people_sponsors_custom:
63+
description: Custom GitHub sponsors
64+
type: array
65+
format: comma-separated
66+
default: ""
67+
6068
# Use GitHub identicons instead of users' avatar (for privacy purposes)
6169
plugin_people_identicons:
6270
description: Use identicons instead of avatars

source/plugins/people/tests.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@
3232
plugin_people: yes
3333
plugin_people_types: sponsors
3434

35+
- name: People plugin (custom sponsors)
36+
uses: lowlighter/metrics@latest
37+
with:
38+
token: MOCKED_TOKEN
39+
plugin_people: yes
40+
plugin_people_types: sponsors
41+
plugin_people_sponsors_custom: lowlighter, octocat
42+
3543
- name: People plugin (stargazers)
3644
uses: lowlighter/metrics@latest
3745
with:

0 commit comments

Comments
 (0)