diff --git a/source/app/metrics/utils.mjs b/source/app/metrics/utils.mjs
index 88e3e425..a4d0eed7 100644
--- a/source/app/metrics/utils.mjs
+++ b/source/app/metrics/utils.mjs
@@ -180,6 +180,34 @@
return rendered
}
+/**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 [key, filters] = criteria.split(":")
+ const value = object[key]
+ console.debug(`metrics/svg/ghquery > checking ${criteria} against ${value}`)
+ return filters.split(",").map(x => x.trim()).filter(x => x).map(filter => {
+ switch (true) {
+ case /^>\d+$/.test(filter):
+ return value > Number(filter.substring(1))
+ case /^<\d+$/.test(filter):
+ return value < Number(filter.substring(1))
+ case /^\d+$/.test(filter):
+ return value === Number(filter)
+ case /^\d+..\d+$/.test(filter):{
+ const [a, b] = filter.split("..").map(Number)
+ return (value >= a)&&(value <= b)
+ }
+ default:
+ return false
+ }
+ }).reduce((a, b) => a||b, false)
+ }).reduce((a, b) => a&&b, true)
+ console.debug(`metrics/svg/ghquery > ${result ? "matching" : "not matching"}`)
+ return result
+ }
+
/**Image to base64 */
export async function imgb64(image, {width, height, fallback = true} = {}) {
//Undefined image
diff --git a/source/app/mocks/api/github/graphql/notable.contributions.mjs b/source/app/mocks/api/github/graphql/notable.contributions.mjs
index a27e7639..9c19d86c 100644
--- a/source/app/mocks/api/github/graphql/notable.contributions.mjs
+++ b/source/app/mocks/api/github/graphql/notable.contributions.mjs
@@ -19,6 +19,10 @@
login:faker.internet.userName(),
avatarUrl:null,
},
+ nameWithOwner:`${faker.internet.userName()}/${faker.lorem.slug()}`,
+ stargazers:{totalCount:faker.datatype.number(1000)},
+ watchers:{totalCount:faker.datatype.number(1000)},
+ forks:{totalCount:faker.datatype.number(1000)},
},
},
],
diff --git a/source/app/mocks/api/github/graphql/notable.organizations.mjs b/source/app/mocks/api/github/graphql/notable.organizations.mjs
deleted file mode 100644
index 9d47a2a5..00000000
--- a/source/app/mocks/api/github/graphql/notable.organizations.mjs
+++ /dev/null
@@ -1,14 +0,0 @@
-/**Mocked data */
- export default function({faker, query, login = faker.internet.userName()}) {
- console.debug("metrics/compute/mocks > mocking graphql api result > notable/organizations")
- return ({
- user:{
- organizations:{
- nodes:[{
- login:faker.internet.userName(),
- avatarUrl:null,
- }],
- },
- },
- })
- }
diff --git a/source/plugins/notable/README.md b/source/plugins/notable/README.md
index c67c3279..9cb3fe71 100644
--- a/source/plugins/notable/README.md
+++ b/source/plugins/notable/README.md
@@ -5,6 +5,9 @@ The *notable* plugin displays badges of organization where you commited at least
+ With repository name
+
+
|
@@ -18,4 +21,6 @@ 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_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 43c06408..e200cc0d 100644
--- a/source/plugins/notable/index.mjs
+++ b/source/plugins/notable/index.mjs
@@ -7,20 +7,11 @@
return null
//Load inputs
- imports.metadata.plugins.notable.inputs({data, account, q})
+ let {filter, repositories} = imports.metadata.plugins.notable.inputs({data, account, q})
//Initialization
const organizations = new Map()
- //Load organization memberships
- try {
- const {user:{organizations:{nodes}}} = await graphql(queries.notable.organizations({login}))
- nodes.map(({login, avatarUrl}) => organizations.set(login, avatarUrl))
- }
- catch (error) {
- console.debug(`metrics/compute/${login}/plugins > notable > failed to load organizations memberships: ${error}`)
- }
-
//Iterate through contributed repositories from organizations
{
let cursor = null
@@ -29,7 +20,10 @@
console.debug(`metrics/compute/${login}/plugins > notable > retrieving contributed repositories after ${cursor}`)
const {user:{repositoriesContributedTo:{edges}}} = await graphql(queries.notable.contributions({login, after:cursor ? `after: "${cursor}"` : "", repositories:100}))
cursor = edges?.[edges?.length-1]?.cursor
- edges.map(({node}) => node.isInOrganization ? organizations.set(node.owner.login, node.owner.avatarUrl) : null)
+ 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))
pushed = edges.length
} while ((pushed)&&(cursor))
}
diff --git a/source/plugins/notable/metadata.yml b/source/plugins/notable/metadata.yml
index dd901cc7..7f7f9668 100644
--- a/source/plugins/notable/metadata.yml
+++ b/source/plugins/notable/metadata.yml
@@ -10,4 +10,19 @@ inputs:
plugin_notable:
description: Display notable contributions in organizations
type: boolean
+ default: no
+
+ # Query filter
+ # Based on GitHub search notation
+ # Supported fields are "stars", "forks" and "watchers"
+ plugin_notable_filter:
+ description: Query filter
+ type: string
+ default: ""
+ example: stars:>500 forks:>100
+
+ # Also display repository name along with organization name
+ plugin_notable_repositories:
+ description: Also display repository name
+ type: boolean
default: no
\ No newline at end of file
diff --git a/source/plugins/notable/queries/contributions.graphql b/source/plugins/notable/queries/contributions.graphql
index acc10c15..041b2808 100644
--- a/source/plugins/notable/queries/contributions.graphql
+++ b/source/plugins/notable/queries/contributions.graphql
@@ -9,6 +9,16 @@ query NotableContributions {
login
avatarUrl
}
+ nameWithOwner
+ watchers {
+ totalCount
+ }
+ forks {
+ totalCount
+ }
+ stargazers {
+ totalCount
+ }
}
}
}
diff --git a/source/plugins/notable/queries/organizations.graphql b/source/plugins/notable/queries/organizations.graphql
deleted file mode 100644
index c1e5b3fa..00000000
--- a/source/plugins/notable/queries/organizations.graphql
+++ /dev/null
@@ -1,11 +0,0 @@
-query NotableOrganizations {
- user(login: "$login") {
- organizations(first: 100) {
- nodes {
- login
- avatarUrl
- }
- }
- }
-}
-