Skip to content

Commit 32b61f0

Browse files
authoredApr 18, 2021
Feat notable options (#240)
1 parent cbd1192 commit 32b61f0

File tree

8 files changed

+67
-36
lines changed

8 files changed

+67
-36
lines changed
 

‎source/app/metrics/utils.mjs

+28
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,34 @@
180180
return rendered
181181
}
182182

183+
/**Check GitHub filter against object */
184+
export function ghfilter(text, object) {
185+
console.debug(`metrics/svg/ghquery > checking ${text} against ${JSON.stringify(object)}`)
186+
const result = text.split(" ").map(x => x.trim()).filter(x => x).map(criteria => {
187+
const [key, filters] = criteria.split(":")
188+
const value = object[key]
189+
console.debug(`metrics/svg/ghquery > checking ${criteria} against ${value}`)
190+
return filters.split(",").map(x => x.trim()).filter(x => x).map(filter => {
191+
switch (true) {
192+
case /^>\d+$/.test(filter):
193+
return value > Number(filter.substring(1))
194+
case /^<\d+$/.test(filter):
195+
return value < Number(filter.substring(1))
196+
case /^\d+$/.test(filter):
197+
return value === Number(filter)
198+
case /^\d+..\d+$/.test(filter):{
199+
const [a, b] = filter.split("..").map(Number)
200+
return (value >= a)&&(value <= b)
201+
}
202+
default:
203+
return false
204+
}
205+
}).reduce((a, b) => a||b, false)
206+
}).reduce((a, b) => a&&b, true)
207+
console.debug(`metrics/svg/ghquery > ${result ? "matching" : "not matching"}`)
208+
return result
209+
}
210+
183211
/**Image to base64 */
184212
export async function imgb64(image, {width, height, fallback = true} = {}) {
185213
//Undefined image

‎source/app/mocks/api/github/graphql/notable.contributions.mjs

+4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
login:faker.internet.userName(),
2020
avatarUrl:null,
2121
},
22+
nameWithOwner:`${faker.internet.userName()}/${faker.lorem.slug()}`,
23+
stargazers:{totalCount:faker.datatype.number(1000)},
24+
watchers:{totalCount:faker.datatype.number(1000)},
25+
forks:{totalCount:faker.datatype.number(1000)},
2226
},
2327
},
2428
],

‎source/app/mocks/api/github/graphql/notable.organizations.mjs

-14
This file was deleted.

‎source/plugins/notable/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ The *notable* plugin displays badges of organization where you commited at least
55
<table>
66
<td align="center">
77
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.notable.svg">
8+
<details open><summary>With repository name</summary>
9+
<img src="https://github.com/lowlighter/lowlighter/blob/master/metrics.plugin.notable.repositories.svg">
10+
</details>
811
<img width="900" height="1" alt="">
912
</td>
1013
</table>
@@ -18,4 +21,6 @@ The *notable* plugin displays badges of organization where you commited at least
1821
with:
1922
# ... other options
2023
plugin_notable: yes
24+
plugin_notable_filter: stars:>500 # Only display repositories with 500 stars or more (syntax based on GitHub search query)
25+
plugin_notable_repositories: yes # Display repositories name instead of only organization name
2126
```

‎source/plugins/notable/index.mjs

+5-11
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,11 @@
77
return null
88

99
//Load inputs
10-
imports.metadata.plugins.notable.inputs({data, account, q})
10+
let {filter, repositories} = imports.metadata.plugins.notable.inputs({data, account, q})
1111

1212
//Initialization
1313
const organizations = new Map()
1414

15-
//Load organization memberships
16-
try {
17-
const {user:{organizations:{nodes}}} = await graphql(queries.notable.organizations({login}))
18-
nodes.map(({login, avatarUrl}) => organizations.set(login, avatarUrl))
19-
}
20-
catch (error) {
21-
console.debug(`metrics/compute/${login}/plugins > notable > failed to load organizations memberships: ${error}`)
22-
}
23-
2415
//Iterate through contributed repositories from organizations
2516
{
2617
let cursor = null
@@ -29,7 +20,10 @@
2920
console.debug(`metrics/compute/${login}/plugins > notable > retrieving contributed repositories after ${cursor}`)
3021
const {user:{repositoriesContributedTo:{edges}}} = await graphql(queries.notable.contributions({login, after:cursor ? `after: "${cursor}"` : "", repositories:100}))
3122
cursor = edges?.[edges?.length-1]?.cursor
32-
edges.map(({node}) => node.isInOrganization ? organizations.set(node.owner.login, node.owner.avatarUrl) : null)
23+
edges
24+
.filter(({node}) => node.isInOrganization)
25+
.filter(({node}) => imports.ghfilter(filter, {name:node.nameWithOwner, stars:node.stargazers.totalCount, watchers:node.watchers.totalCount, forks:node.forks.totalCount}))
26+
.map(({node}) => organizations.set(repositories ? node.nameWithOwner : node.owner.login, node.owner.avatarUrl))
3327
pushed = edges.length
3428
} while ((pushed)&&(cursor))
3529
}

‎source/plugins/notable/metadata.yml

+15
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,19 @@ inputs:
1010
plugin_notable:
1111
description: Display notable contributions in organizations
1212
type: boolean
13+
default: no
14+
15+
# Query filter
16+
# Based on GitHub search notation
17+
# Supported fields are "stars", "forks" and "watchers"
18+
plugin_notable_filter:
19+
description: Query filter
20+
type: string
21+
default: ""
22+
example: stars:>500 forks:>100
23+
24+
# Also display repository name along with organization name
25+
plugin_notable_repositories:
26+
description: Also display repository name
27+
type: boolean
1328
default: no

‎source/plugins/notable/queries/contributions.graphql

+10
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,16 @@ query NotableContributions {
99
login
1010
avatarUrl
1111
}
12+
nameWithOwner
13+
watchers {
14+
totalCount
15+
}
16+
forks {
17+
totalCount
18+
}
19+
stargazers {
20+
totalCount
21+
}
1222
}
1323
}
1424
}

‎source/plugins/notable/queries/organizations.graphql

-11
This file was deleted.

0 commit comments

Comments
 (0)
Failed to load comments.