Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/lowlighter/metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
lowlighter committed Mar 2, 2021
2 parents dae62fd + 30414a0 commit 442b83e
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 10 deletions.
25 changes: 20 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@

Generate your metrics that you can embed everywhere, including your GitHub profile readme! It works for both user and organization accounts, and even for repositories!


<sup>*鈿狅笍 This is the documentation of **v3.5-beta** (`@master` branch) which includes [unreleased features](https://github.com/lowlighter/metrics/compare/latest...master), see documentation of **v3.4** (`@latest` branch) [here](https://github.com/lowlighter/metrics/blob/latest/README.md).*</sup>


<table>
<tr>
<th align="center">For user accounts</th>
Expand All @@ -21,6 +25,9 @@ Generate your metrics that you can embed everywhere, including your GitHub profi
</tr>
</table>


And you can customize these heavily with plugins, templates and hundreds of options!

<table>
<tr>
<th colspan="2" align="center">
Expand Down Expand Up @@ -222,6 +229,9 @@ Generate your metrics that you can embed everywhere, including your GitHub profi
<tr>
<td align="center">
<img alt="" width="400" src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.posts.svg">
<details><summary>With posts descriptions and cover images version</summary>
<img alt="" width="400" src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.posts.full.svg">
</details>
<img width="900" height="1" alt="">
</td>
<td align="center">
Expand All @@ -236,6 +246,9 @@ Generate your metrics that you can embed everywhere, including your GitHub profi
<tr>
<td align="center">
<img alt="" width="400" src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.tweets.svg">
<details><summary>With tweets attachments version</summary>
<img alt="" width="400" src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.tweets.attachments.svg">
</details>
<img width="900" height="1" alt="">
</td>
<td align="center">
Expand Down Expand Up @@ -319,7 +332,7 @@ Assuming your username is `my-github-user`, you can then embed rendered metrics
```

<details>
<summary>馃挰 How to setup?</summary>
<summary><b>馃挰 How to setup?</b> <i>(click to expand)</i></summary>

### 0. Setup your personal repository

Expand Down Expand Up @@ -432,7 +445,7 @@ For convenience, you can use the shared instance available at [metrics.lecoq.io]
This is mostly intended for previews, to enjoy all features consider using GitHub Action instead.

<details>
<summary>馃挰 Fair use</summary>
<summary><b>馃挰 Fair use</b> <i>(click to expand)</i></summary>

To ensure service availability, shared instance has a few limitations:
* Images are cached for 15 minutes
Expand All @@ -458,7 +471,7 @@ Assuming your username is `my-github-user`, you can then embed rendered metrics
```

<details>
<summary>馃挰 How to setup?</summary>
<summary><b>馃挰 How to setup?</b> <i>(click to expand)</i></summary>

### 0. Prepare your server

Expand Down Expand Up @@ -750,7 +763,7 @@ While metrics targets mainly user accounts, it's possible to render metrics for
![Metrics (organization account)](https://github.com/lowlighter/lowlighter/blob/master/metrics.organization.svg)

<details>
<summary>馃挰 Metrics for organizations</summary>
<summary><b>馃挰 Metrics for organizations</b> <i>(click to expand)</i></summary>

Setup is the same as for user accounts, though you'll need to add `read:org` scope, **whether you're member of target organization or not**.

Expand Down Expand Up @@ -778,7 +791,7 @@ To support private repositories, add full `repo` scope to your personal token.
</details>

<details>
<summary>馃挰 Organizations memberships for user accounts</summary>
<summary><b>馃挰 Organizations memberships for user accounts</b> <i>(click to expand)</i></summary>

Only public memberships can be displayed by metrics by default.
You can manage your membership visibility in the `People` tab of your organization:
Expand Down Expand Up @@ -814,6 +827,8 @@ Copyright (c) 2020 lowlighter

![License details](https://github.com/lowlighter/lowlighter/blob/master/metrics.licenses.svg)

![Sponsors](https://github.com/lowlighter/lowlighter/blob/master/metrics.sponsors.svg)

## 馃摉 Useful references

* [GitHub GraphQL API](https://docs.github.com/en/graphql)
Expand Down
3 changes: 2 additions & 1 deletion source/plugins/people/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```
17 changes: 13 additions & 4 deletions source/plugins/people/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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`)
Expand All @@ -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 {
Expand Down Expand Up @@ -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}
}
Expand Down
8 changes: 8 additions & 0 deletions source/plugins/people/metadata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions source/plugins/people/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 442b83e

Please sign in to comment.