feat(plugins/notable): add support for plugin_notable_from to display contributions from repositories hosted by user accounts (#560)

This commit is contained in:
Simon Lecoq
2021-10-08 17:12:42 -04:00
committed by GitHub
parent 67da0b8c0f
commit 75be173cc1
5 changed files with 37 additions and 18 deletions

View File

@@ -21,6 +21,7 @@ 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_filter: stars:>500 # Only display repositories with 500 stars or more (syntax based on GitHub search query)
plugin_notable_from: organization # Only display contributions within organization repositories
plugin_notable_repositories: yes # Display repositories name instead of only organization name
```

View File

@@ -7,12 +7,10 @@ export default async function({login, q, imports, graphql, data, account, querie
return null
//Load inputs
let {filter, repositories} = imports.metadata.plugins.notable.inputs({data, account, q})
let {filter, repositories, from} = imports.metadata.plugins.notable.inputs({data, account, q})
//Initialization
const organizations = new Map()
//Iterate through contributed repositories from organizations
//Iterate through contributed repositories
const notable = new Map()
{
let cursor = null
let pushed = 0
@@ -21,16 +19,16 @@ export default async function({login, q, imports, graphql, data, account, querie
const {user:{repositoriesContributedTo:{edges}}} = await graphql(queries.notable.contributions({login, after:cursor ? `after: "${cursor}"` : "", repositories:data.shared["repositories.batch"] || 100}))
cursor = edges?.[edges?.length - 1]?.cursor
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))
.filter(({node}) => ({all:true, organization:node.isInOrganization, user:!node.isInOrganization}[from]))
.filter(({node}) => imports.ghfilter(filter, {name:node.nameWithOwner, user:node.owner.login, stars:node.stargazers.totalCount, watchers:node.watchers.totalCount, forks:node.forks.totalCount}))
.map(({node}) => notable.set((repositories || !node.isInOrganization) ? node.nameWithOwner : node.owner.login, {organization:node.isInOrganization, avatarUrl:node.owner.avatarUrl}))
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`)
const contributions = (await Promise.all([...notable.entries()].map(async ([name, {avatarUrl, organization}]) => ({name, avatar:await imports.imgb64(avatarUrl), organization})))).sort((a, b) => a.name.localeCompare(b.name))
console.debug(`metrics/compute/${login}/plugins > notable > found ${contributions.length} notable contributions`)
//Results
return {contributions}

View File

@@ -21,7 +21,18 @@ inputs:
default: ""
example: stars:>500 forks:>100
# Filter repositories depending on which type of account it is hosted
plugin_notable_from:
description: Filter by repository host account type
type: string
default: organization
values:
- all #
- organization # Only hosted by organization accounts
- user # Only hosted by user accounts
# Also display repository name along with organization name
# Note that repositories hosted by user account will always be displayed fully
plugin_notable_repositories:
description: Also display repository name
type: boolean