Feat notable options (#240)

This commit is contained in:
Simon Lecoq
2021-04-18 20:19:39 +02:00
committed by GitHub
parent cbd119215e
commit 32b61f0b70
8 changed files with 67 additions and 36 deletions

View File

@@ -5,6 +5,9 @@ The *notable* plugin displays badges of organization where you commited at least
<table>
<td align="center">
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.notable.svg">
<details open><summary>With repository name</summary>
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.notable.repositories.svg">
</details>
<img width="900" height="1" alt="">
</td>
</table>
@@ -18,4 +21,6 @@ The *notable* plugin displays badges of organization where you commited at least
with:
# ... other options
plugin_notable: yes
plugin_notable_filter: stars:>500 # Only display repositories with 500 stars or more (syntax based on GitHub search query)
plugin_notable_repositories: yes # Display repositories name instead of only organization name
```

View File

@@ -7,20 +7,11 @@
return null
//Load inputs
imports.metadata.plugins.notable.inputs({data, account, q})
let {filter, repositories} = 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
@@ -29,7 +20,10 @@
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)
edges
.filter(({node}) => node.isInOrganization)
.filter(({node}) => imports.ghfilter(filter, {name:node.nameWithOwner, stars:node.stargazers.totalCount, watchers:node.watchers.totalCount, forks:node.forks.totalCount}))
.map(({node}) => organizations.set(repositories ? node.nameWithOwner : node.owner.login, node.owner.avatarUrl))
pushed = edges.length
} while ((pushed)&&(cursor))
}

View File

@@ -10,4 +10,19 @@ inputs:
plugin_notable:
description: Display notable contributions in organizations
type: boolean
default: no
# Query filter
# Based on GitHub search notation
# Supported fields are "stars", "forks" and "watchers"
plugin_notable_filter:
description: Query filter
type: string
default: ""
example: stars:>500 forks:>100
# Also display repository name along with organization name
plugin_notable_repositories:
description: Also display repository name
type: boolean
default: no

View File

@@ -9,6 +9,16 @@ query NotableContributions {
login
avatarUrl
}
nameWithOwner
watchers {
totalCount
}
forks {
totalCount
}
stargazers {
totalCount
}
}
}
}

View File

@@ -1,11 +0,0 @@
query NotableOrganizations {
user(login: "$login") {
organizations(first: 100) {
nodes {
login
avatarUrl
}
}
}
}