Skip to content

Commit 8659a72

Browse files
committed
feat(plugins/notable): add plugin_notable_organizations_skipped parameter
1 parent 366f8b9 commit 8659a72

File tree

5 files changed

+80
-1
lines changed

5 files changed

+80
-1
lines changed

action.yml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

source/app/metrics/utils.mjs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -417,6 +417,43 @@ export const filters = {
417417
console.debug(`metrics/filters/repo > filter ${repo} (${include ? "included" : "excluded"})`)
418418
return include
419419
},
420+
/**Organization filter (exclusion list, same semantics as repo) */
421+
organization(organizationLogin, patterns, {debug = true} = {}) {
422+
if (!patterns.length)
423+
return true
424+
425+
const org = `${organizationLogin}`.toLocaleLowerCase()
426+
427+
let include = true
428+
if (patterns[0] === "@use.patterns") {
429+
if (debug)
430+
console.debug(`metrics/filters/organization > ${org} > using advanced pattern matching`)
431+
const options = {nocase: true}
432+
for (let pattern of patterns) {
433+
if (pattern.startsWith("#"))
434+
continue
435+
let action = false
436+
if ((pattern.startsWith("+")) || (pattern.startsWith("-"))) {
437+
action = pattern.charAt(0) === "+"
438+
pattern = pattern.substring(1)
439+
}
440+
if (minimatch(org, pattern, options)) {
441+
if (debug)
442+
console.debug(`metrics/filters/organization > ${org} matches ${action ? "including" : "excluding"} pattern ${pattern}`)
443+
include = action
444+
}
445+
}
446+
}
447+
else {
448+
if (debug)
449+
console.debug(`metrics/filters/organization > ${org} > using basic pattern matching`)
450+
include = !patterns.includes(org)
451+
}
452+
453+
if (debug)
454+
console.debug(`metrics/filters/organization > filter ${org} (${include ? "included" : "excluded"})`)
455+
return include
456+
},
420457
/**Text filter*/
421458
text(text, patterns, {debug = true} = {}) {
422459
//Disable filtering when no pattern is provided

source/plugins/notable/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,17 @@ Some repositories may not be able to reported advanced stats and in the case the
6767
<b>type:</b> <code>array</code>
6868
<i>(newline-separated)</i>
6969
<br></td>
70+
</tr>
71+
<tr>
72+
<td nowrap="nowrap"><h4><code>plugin_notable_organizations_skipped</code></h4></td>
73+
<td rowspan="2"><p>Skipped organizations. Exclude contributions from these organizations in both badges and repository lists. Supports the same pattern syntax as <code>plugin_notable_skipped</code> (basic and <code>@use.patterns</code> with minimatch for wildcards, e.g. <code>org-*</code>).</p>
74+
<img width="900" height="1" alt=""></td>
75+
</tr>
76+
<tr>
77+
<td nowrap="nowrap"><b>type:</b> <code>array</code>
78+
<i>(newline-separated)</i>
79+
<br>
80+
<b>default:</b> ""<br></td>
7081
</tr>
7182
<tr>
7283
<td nowrap="nowrap"><h4><code>plugin_notable_from</code></h4></td>
@@ -159,6 +170,19 @@ with:
159170
base: ""
160171
plugin_notable: yes
161172

173+
```
174+
```yaml
175+
name: Contributions (excluding organizations)
176+
uses: lowlighter/metrics@latest
177+
with:
178+
filename: metrics.plugin.notable.svg
179+
token: ${{ secrets.METRICS_TOKEN }}
180+
base: ""
181+
plugin_notable: yes
182+
plugin_notable_organizations_skipped: |
183+
my-org
184+
other-org
185+
162186
```
163187
```yaml
164188
name: Indepth analysis

source/plugins/notable/index.mjs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export default async function({login, q, imports, rest, graphql, data, account,
77
return null
88

99
//Load inputs
10-
let {filter, skipped, repositories, types, from, indepth, self} = imports.metadata.plugins.notable.inputs({data, account, q})
10+
let {filter, skipped, "organizations.skipped": organizationsSkipped = [], repositories, types, from, indepth, self} = imports.metadata.plugins.notable.inputs({data, account, q})
1111
skipped.push(...data.shared["repositories.skipped"])
1212

1313
//Iterate through contributed repositories
@@ -21,6 +21,7 @@ export default async function({login, q, imports, rest, graphql, data, account,
2121
cursor = edges?.[edges?.length - 1]?.cursor
2222
edges
2323
.filter(({node}) => imports.filters.repo(node, skipped))
24+
.filter(({node}) => !node.isInOrganization || imports.filters.organization(node.owner.login, organizationsSkipped))
2425
.filter(({node}) => ({all: true, organization: node.isInOrganization, user: !node.isInOrganization}[from]))
2526
.filter(({node}) => imports.filters.github(filter, {name: node.nameWithOwner, user: node.owner.login, stars: node.stargazers.totalCount, watchers: node.watchers.totalCount, forks: node.forks.totalCount}))
2627
.map(({node}) => contributions.push({handle: node.nameWithOwner, stars: node.stargazers.totalCount, issues: node.issues.totalCount, pulls: node.pullRequests.totalCount, organization: node.isInOrganization, avatarUrl: node.owner.avatarUrl}))

source/plugins/notable/metadata.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@ inputs:
4242
example: my-repo-1, my-repo-2, owner/repo-3, ...
4343
inherits: repositories_skipped
4444

45+
plugin_notable_organizations_skipped:
46+
description: |
47+
Skipped organizations
48+
49+
Exclude contributions from these organizations in both badges and repository lists.
50+
Supports the same pattern syntax as [`plugin_notable_skipped`](/source/plugins/notable/README.md#plugin_notable_skipped) (basic and `@use.patterns` with minimatch for wildcards, e.g. `org-*`).
51+
type: array
52+
format:
53+
- newline-separated
54+
- comma-separated
55+
default: ""
56+
example: my-org, other-org, ...
57+
4558
plugin_notable_from:
4659
description: |
4760
Repository owner account type filter

0 commit comments

Comments
 (0)