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 */
|
/**Check GitHub filter against object */
|
||||||
export function ghfilter(text, object) {
|
export function ghfilter(text, object) {
|
||||||
console.debug(`metrics/svg/ghquery > checking ${text} against ${JSON.stringify(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 [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}`)
|
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) {
|
switch (true) {
|
||||||
case /^>\d+$/.test(filter):
|
case /^>\d+$/.test(filter):
|
||||||
return value > Number(filter.substring(1))
|
return value > Number(filter.substring(1))
|
||||||
|
case /^>=\d+$/.test(filter):
|
||||||
|
return value >= Number(filter.substring(2))
|
||||||
case /^<\d+$/.test(filter):
|
case /^<\d+$/.test(filter):
|
||||||
return value < Number(filter.substring(1))
|
return value < Number(filter.substring(1))
|
||||||
|
case /^<=\d+$/.test(filter):
|
||||||
|
return value <= Number(filter.substring(2))
|
||||||
case /^\d+$/.test(filter):
|
case /^\d+$/.test(filter):
|
||||||
return value === Number(filter)
|
return value === Number(filter)
|
||||||
case /^\d+..\d+$/.test(filter): {
|
case /^\d+..\d+$/.test(filter): {
|
||||||
@@ -267,7 +276,7 @@ export function ghfilter(text, object) {
|
|||||||
default:
|
default:
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}).reduce((a, b) => a || b, false)
|
}).reduce((a, b) => a || b, false) ?? false
|
||||||
}).reduce((a, b) => a && b, true)
|
}).reduce((a, b) => a && b, true)
|
||||||
console.debug(`metrics/svg/ghquery > ${result ? "matching" : "not matching"}`)
|
console.debug(`metrics/svg/ghquery > ${result ? "matching" : "not matching"}`)
|
||||||
return result
|
return result
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ The *notable* plugin displays badges of organization where you commited at least
|
|||||||
with:
|
with:
|
||||||
# ... other options
|
# ... other options
|
||||||
plugin_notable: yes
|
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
|
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
|
return null
|
||||||
|
|
||||||
//Load inputs
|
//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
|
//Iterate through contributed repositories
|
||||||
const organizations = new Map()
|
const notable = new Map()
|
||||||
|
|
||||||
//Iterate through contributed repositories from organizations
|
|
||||||
{
|
{
|
||||||
let cursor = null
|
let cursor = null
|
||||||
let pushed = 0
|
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}))
|
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
|
cursor = edges?.[edges?.length - 1]?.cursor
|
||||||
edges
|
edges
|
||||||
.filter(({node}) => node.isInOrganization)
|
.filter(({node}) => ({all:true, organization:node.isInOrganization, user:!node.isInOrganization}[from]))
|
||||||
.filter(({node}) => imports.ghfilter(filter, {name:node.nameWithOwner, stars:node.stargazers.totalCount, watchers:node.watchers.totalCount, forks:node.forks.totalCount}))
|
.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}) => organizations.set(repositories ? node.nameWithOwner : node.owner.login, node.owner.avatarUrl))
|
.map(({node}) => notable.set((repositories || !node.isInOrganization) ? node.nameWithOwner : node.owner.login, {organization:node.isInOrganization, avatarUrl:node.owner.avatarUrl}))
|
||||||
pushed = edges.length
|
pushed = edges.length
|
||||||
} while ((pushed) && (cursor))
|
} while ((pushed) && (cursor))
|
||||||
}
|
}
|
||||||
|
|
||||||
//Set contributions
|
//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))
|
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 to ${organizations.length} organizations`)
|
console.debug(`metrics/compute/${login}/plugins > notable > found ${contributions.length} notable contributions`)
|
||||||
|
|
||||||
//Results
|
//Results
|
||||||
return {contributions}
|
return {contributions}
|
||||||
|
|||||||
@@ -21,7 +21,18 @@ inputs:
|
|||||||
default: ""
|
default: ""
|
||||||
example: stars:>500 forks:>100
|
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
|
# Also display repository name along with organization name
|
||||||
|
# Note that repositories hosted by user account will always be displayed fully
|
||||||
plugin_notable_repositories:
|
plugin_notable_repositories:
|
||||||
description: Also display repository name
|
description: Also display repository name
|
||||||
type: boolean
|
type: boolean
|
||||||
|
|||||||
@@ -16,10 +16,10 @@
|
|||||||
<% } else { %>
|
<% } else { %>
|
||||||
<% if (plugins.notable.contributions.length) { %>
|
<% if (plugins.notable.contributions.length) { %>
|
||||||
<div class="row organization contributions">
|
<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">
|
<div class="organization contribution">
|
||||||
<img class="organization avatar" src="<%= avatar %>" width="16" height="16" />
|
<img class="<%= organization ? "organization" : "" %> avatar" src="<%= avatar %>" width="16" height="16" />
|
||||||
<span class="organization name">@<%= name %></span>
|
<span class="name">@<%= name %></span>
|
||||||
</div>
|
</div>
|
||||||
<% } %>
|
<% } %>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user