From 30414a02417740ff2517193ab04c4cb0ce5b6ec7 Mon Sep 17 00:00:00 2001 From: Simon Lecoq <22963968+lowlighter@users.noreply.github.com> Date: Tue, 2 Mar 2021 11:35:09 +0100 Subject: [PATCH] Add plugin_people_sponsors_custom option (#166) --- source/plugins/people/README.md | 3 ++- source/plugins/people/index.mjs | 17 +++++++++++++---- source/plugins/people/metadata.yml | 8 ++++++++ source/plugins/people/tests.yml | 8 ++++++++ 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/source/plugins/people/README.md b/source/plugins/people/README.md index 19b37832..a93c415e 100644 --- a/source/plugins/people/README.md +++ b/source/plugins/people/README.md @@ -50,6 +50,7 @@ Sections will be ordered the same as specified in `plugin_people_types`. 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 + plugin_people_thanks: lowlighter, octocat # Users that will be displayed in "thanks" section + plugin_people_sponsors_custom: octocat # Users that will be displayed additionally in "sponsors" section plugin_people_shuffle: yes # Shuffle for varied output ``` diff --git a/source/plugins/people/index.mjs b/source/plugins/people/index.mjs index 79b537fa..6b2a1f91 100644 --- a/source/plugins/people/index.mjs +++ b/source/plugins/people/index.mjs @@ -21,9 +21,13 @@ } //Load inputs - let {limit, types, size, identicons, thanks, shuffle} = imports.metadata.plugins.people.inputs({data, account, q}, {types:context.default}) + let {limit, types, size, identicons, thanks, shuffle, "sponsors.custom":_sponsors} = 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)) ?? [])] + if ((types.includes("sponsorshipsAsMaintainer"))&&(_sponsors?.length)) { + types.unshift("sponsorshipsCustom") + data.user.sponsorshipsAsMaintainer.totalCount += _sponsors.length + } //Retrieve followers from graphql api console.debug(`metrics/compute/${login}/plugins > people > querying api`) @@ -37,9 +41,10 @@ const {data:nodes} = await rest.repos.listContributors({owner, repo}) result[type].push(...nodes.map(({login, avatar_url}) => ({login, avatarUrl:avatar_url}))) } - else if (type === "thanks") { - const nodes = await Promise.all(thanks.map(async username => (await rest.users.getByUsername({username})).data)) - result[type].push(...nodes.map(({login, avatar_url}) => ({login, avatarUrl:avatar_url}))) + else if ((type === "thanks")||(type === "sponsorshipsCustom")) { + const users = {thanks, sponsorshipsCustom:_sponsors}[type] ?? [] + const nodes = await Promise.all(users.map(async username => (await rest.users.getByUsername({username})).data)) + result[{sponsorshipsCustom:"sponsorshipsAsMaintainer"}[type] ?? type].push(...nodes.map(({login, avatar_url}) => ({login, avatarUrl:avatar_url}))) } //GraphQL else { @@ -77,6 +82,10 @@ await Promise.all(result[type].map(async user => user.avatar = await imports.imgb64(user.avatarUrl))) } + //Special type handling + if (types.includes("sponsorshipsCustom")) + types.splice(types.indexOf("sponsorshipsCustom"), 1) + //Results return {types, size, ...result} } diff --git a/source/plugins/people/metadata.yml b/source/plugins/people/metadata.yml index 1dda0795..cbc3be3c 100644 --- a/source/plugins/people/metadata.yml +++ b/source/plugins/people/metadata.yml @@ -57,6 +57,14 @@ inputs: format: comma-separated default: "" + # Add specified users to GitHub sponsors ("sponsors" must be specified in "plugin_people_types") + # This is useful to list sponsors from unsupported GitHub sponsors sources + plugin_people_sponsors_custom: + description: Custom GitHub sponsors + 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 diff --git a/source/plugins/people/tests.yml b/source/plugins/people/tests.yml index a39053f6..cf8197a6 100644 --- a/source/plugins/people/tests.yml +++ b/source/plugins/people/tests.yml @@ -32,6 +32,14 @@ plugin_people: yes plugin_people_types: sponsors +- name: People plugin (custom sponsors) + uses: lowlighter/metrics@latest + with: + token: MOCKED_TOKEN + plugin_people: yes + plugin_people_types: sponsors + plugin_people_sponsors_custom: lowlighter, octocat + - name: People plugin (stargazers) uses: lowlighter/metrics@latest with: