feat(plugins/notable): add support for plugin_notable_from to display contributions from repositories hosted by user accounts (#560)
This commit is contained in:
@@ -248,16 +248,25 @@ export async function markdown(text, {mode = "inline", codelines = Infinity} = {
|
||||
/**Check GitHub filter against object */
|
||||
export function ghfilter(text, object) {
|
||||
console.debug(`metrics/svg/ghquery > checking ${text} against ${JSON.stringify(object)}`)
|
||||
const result = text.split(" ").map(x => x.trim()).filter(x => x).map(criteria => {
|
||||
const result = text.split(/(?<!NOT) /).map(x => x.trim()).filter(x => x).map(criteria => {
|
||||
const [key, filters] = criteria.split(":")
|
||||
const value = object[key]
|
||||
const value = object[/^NOT /.test(key) ? key.substring(3).trim() : key.trim()]
|
||||
console.debug(`metrics/svg/ghquery > checking ${criteria} against ${value}`)
|
||||
return filters.split(",").map(x => x.trim()).filter(x => x).map(filter => {
|
||||
return filters?.split(",").map(x => x.trim()).filter(x => x).map(filter => {
|
||||
if (!Number.isFinite(Number(value))) {
|
||||
if (/^NOT /.test(filter))
|
||||
return value !== filter.substring(3).trim()
|
||||
return value === filter.trim()
|
||||
}
|
||||
switch (true) {
|
||||
case /^>\d+$/.test(filter):
|
||||
return value > Number(filter.substring(1))
|
||||
case /^>=\d+$/.test(filter):
|
||||
return value >= Number(filter.substring(2))
|
||||
case /^<\d+$/.test(filter):
|
||||
return value < Number(filter.substring(1))
|
||||
case /^<=\d+$/.test(filter):
|
||||
return value <= Number(filter.substring(2))
|
||||
case /^\d+$/.test(filter):
|
||||
return value === Number(filter)
|
||||
case /^\d+..\d+$/.test(filter): {
|
||||
@@ -267,7 +276,7 @@ export function ghfilter(text, object) {
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}).reduce((a, b) => a || b, false)
|
||||
}).reduce((a, b) => a || b, false) ?? false
|
||||
}).reduce((a, b) => a && b, true)
|
||||
console.debug(`metrics/svg/ghquery > ${result ? "matching" : "not matching"}`)
|
||||
return result
|
||||
|
||||
@@ -22,5 +22,6 @@ The *notable* plugin displays badges of organization where you commited at least
|
||||
# ... 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_from: organization # Only display contributions within organization repositories
|
||||
plugin_notable_repositories: yes # Display repositories name instead of only organization name
|
||||
```
|
||||
@@ -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}
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -16,10 +16,10 @@
|
||||
<% } else { %>
|
||||
<% if (plugins.notable.contributions.length) { %>
|
||||
<div class="row organization contributions">
|
||||
<% for (const {name, avatar} of plugins.notable.contributions) { %>
|
||||
<% for (const {name, avatar, organization} of plugins.notable.contributions) { %>
|
||||
<div class="organization contribution">
|
||||
<img class="organization avatar" src="<%= avatar %>" width="16" height="16" />
|
||||
<span class="organization name">@<%= name %></span>
|
||||
<img class="<%= organization ? "organization" : "" %> avatar" src="<%= avatar %>" width="16" height="16" />
|
||||
<span class="name">@<%= name %></span>
|
||||
</div>
|
||||
<% } %>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user