Add notable contributions plugin (#222)
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
name: "🗃️ Base content"
|
||||
cost: 1 GraphQL request
|
||||
cost: 2 GraphQL requests + 1 GraphQL request per 100 repositories fetched
|
||||
categorie: core
|
||||
supports:
|
||||
- user
|
||||
|
||||
@@ -48,7 +48,7 @@ query BaseUser {
|
||||
}
|
||||
}
|
||||
}
|
||||
repositoriesContributedTo {
|
||||
repositoriesContributedTo(includeUserRepositories: true) {
|
||||
totalCount
|
||||
}
|
||||
followers {
|
||||
|
||||
21
source/plugins/notable/README.md
Normal file
21
source/plugins/notable/README.md
Normal file
@@ -0,0 +1,21 @@
|
||||
### 🎩 Notable contributions
|
||||
|
||||
The *notable* plugin displays badges of organization where you commited at least once on main branch.
|
||||
|
||||
<table>
|
||||
<td align="center">
|
||||
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.notable.svg">
|
||||
<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_notable: yes
|
||||
```
|
||||
48
source/plugins/notable/index.mjs
Normal file
48
source/plugins/notable/index.mjs
Normal file
@@ -0,0 +1,48 @@
|
||||
//Setup
|
||||
export default async function({login, q, imports, graphql, data, account, queries}, {enabled = false} = {}) {
|
||||
//Plugin execution
|
||||
try {
|
||||
//Check if plugin is enabled and requirements are met
|
||||
if ((!enabled)||(!q.notable))
|
||||
return null
|
||||
|
||||
//Load inputs
|
||||
imports.metadata.plugins.notable.inputs({data, account, q})
|
||||
|
||||
//Initialization
|
||||
const organizations = new Map()
|
||||
|
||||
//Load organization memberships
|
||||
try {
|
||||
const {user:{organizations:{nodes}}} = await graphql(queries.notable.organizations({login}))
|
||||
nodes.map(({login, avatarUrl}) => organizations.set(login, avatarUrl))
|
||||
}
|
||||
catch (error) {
|
||||
console.debug(`metrics/compute/${login}/plugins > notable > failed to load organizations memberships: ${error}`)
|
||||
}
|
||||
|
||||
//Iterate through contributed repositories from organizations
|
||||
{
|
||||
let cursor = null
|
||||
let pushed = 0
|
||||
do {
|
||||
console.debug(`metrics/compute/${login}/plugins > notable > retrieving contributed repositories after ${cursor}`)
|
||||
const {user:{repositoriesContributedTo:{edges}}} = await graphql(queries.notable.contributions({login, after:cursor ? `after: "${cursor}"` : "", repositories:100}))
|
||||
cursor = edges?.[edges?.length-1]?.cursor
|
||||
edges.map(({node}) => node.isInOrganization ? organizations.set(node.owner.login, node.owner.avatarUrl) : null)
|
||||
pushed = edges.length
|
||||
} while ((pushed)&&(cursor))
|
||||
}
|
||||
|
||||
//Set contributions
|
||||
const contributions = (await Promise.all([...organizations.entries()].map(async([name, avatarUrl]) => ({name, avatar:await imports.imgb64(avatarUrl)})))).sort((a, b) => a.name.localeCompare(b.name))
|
||||
console.debug(`metrics/compute/${login}/plugins > notable > found contributions to ${organizations.length} organizations`)
|
||||
|
||||
//Results
|
||||
return {contributions}
|
||||
}
|
||||
//Handle errors
|
||||
catch (error) {
|
||||
throw {error:{message:"An error occured", instance:error}}
|
||||
}
|
||||
}
|
||||
13
source/plugins/notable/metadata.yml
Normal file
13
source/plugins/notable/metadata.yml
Normal file
@@ -0,0 +1,13 @@
|
||||
name: "🎩 Notable contributions"
|
||||
cost: 1 GraphQL request per 100 repositories fetched
|
||||
categorie: github
|
||||
index: 18
|
||||
supports:
|
||||
- user
|
||||
inputs:
|
||||
|
||||
# Enable or disable plugin
|
||||
plugin_notable:
|
||||
description: Display notable contributions in organizations
|
||||
type: boolean
|
||||
default: no
|
||||
16
source/plugins/notable/queries/contributions.graphql
Normal file
16
source/plugins/notable/queries/contributions.graphql
Normal file
@@ -0,0 +1,16 @@
|
||||
query NotableContributions {
|
||||
user(login: "$login") {
|
||||
repositoriesContributedTo($after first: $repositories, contributionTypes: COMMIT) {
|
||||
edges {
|
||||
cursor
|
||||
node {
|
||||
isInOrganization
|
||||
owner {
|
||||
login
|
||||
avatarUrl
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
11
source/plugins/notable/queries/organizations.graphql
Normal file
11
source/plugins/notable/queries/organizations.graphql
Normal file
@@ -0,0 +1,11 @@
|
||||
query NotableOrganizations {
|
||||
user(login: "$login") {
|
||||
organizations(first: 100) {
|
||||
nodes {
|
||||
login
|
||||
avatarUrl
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
5
source/plugins/notable/tests.yml
Normal file
5
source/plugins/notable/tests.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
- name: Notable plugin (default)
|
||||
uses: lowlighter/metrics@latest
|
||||
with:
|
||||
token: MOCKED_TOKEN
|
||||
plugin_notable: yes
|
||||
@@ -1,7 +1,7 @@
|
||||
name: "🌇 GitHub Skyline 3D calendar"
|
||||
cost: N/A
|
||||
categorie: github
|
||||
index: 18
|
||||
index: 19
|
||||
supports:
|
||||
- user
|
||||
inputs:
|
||||
|
||||
Reference in New Issue
Block a user