diff --git a/source/app/metrics/utils.mjs b/source/app/metrics/utils.mjs index f4d41e15..363c242a 100644 --- a/source/app/metrics/utils.mjs +++ b/source/app/metrics/utils.mjs @@ -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(/(? 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 diff --git a/source/plugins/notable/README.md b/source/plugins/notable/README.md index 9cb3fe71..9ebf4011 100644 --- a/source/plugins/notable/README.md +++ b/source/plugins/notable/README.md @@ -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 ``` \ No newline at end of file diff --git a/source/plugins/notable/index.mjs b/source/plugins/notable/index.mjs index 98a84861..19119246 100644 --- a/source/plugins/notable/index.mjs +++ b/source/plugins/notable/index.mjs @@ -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} diff --git a/source/plugins/notable/metadata.yml b/source/plugins/notable/metadata.yml index d97a0d80..0139c924 100644 --- a/source/plugins/notable/metadata.yml +++ b/source/plugins/notable/metadata.yml @@ -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 diff --git a/source/templates/classic/partials/notable.ejs b/source/templates/classic/partials/notable.ejs index 78e8e2fe..0d9b5743 100644 --- a/source/templates/classic/partials/notable.ejs +++ b/source/templates/classic/partials/notable.ejs @@ -16,10 +16,10 @@ <% } else { %> <% if (plugins.notable.contributions.length) { %>