Feat notable options (#240)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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)},
|
||||
},
|
||||
},
|
||||
],
|
||||
|
||||
@@ -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,
|
||||
}],
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
@@ -5,6 +5,9 @@ The *notable* plugin displays badges of organization where you commited at least
|
||||
<table>
|
||||
<td align="center">
|
||||
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.notable.svg">
|
||||
<details open><summary>With repository name</summary>
|
||||
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.notable.repositories.svg">
|
||||
</details>
|
||||
<img width="900" height="1" alt="">
|
||||
</td>
|
||||
</table>
|
||||
@@ -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
|
||||
```
|
||||
@@ -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))
|
||||
}
|
||||
|
||||
@@ -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
|
||||
@@ -9,6 +9,16 @@ query NotableContributions {
|
||||
login
|
||||
avatarUrl
|
||||
}
|
||||
nameWithOwner
|
||||
watchers {
|
||||
totalCount
|
||||
}
|
||||
forks {
|
||||
totalCount
|
||||
}
|
||||
stargazers {
|
||||
totalCount
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
query NotableOrganizations {
|
||||
user(login: "$login") {
|
||||
organizations(first: 100) {
|
||||
nodes {
|
||||
login
|
||||
avatarUrl
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user