Commit c509661
Changed files (10)
src
all-badges
collect
src/all-badges/public-keys/public-keys-1.png
Binary file
src/all-badges/public-keys/public-keys-2.png
Binary file
src/all-badges/public-keys/public-keys-3.png
Binary file
src/all-badges/public-keys/public-keys-4.png
Binary file
src/all-badges/public-keys/public-keys-5.png
Binary file
src/all-badges/public-keys/public-keys.ts
@@ -0,0 +1,30 @@
+import { BadgePresenter, Present } from '../../badges.js'
+
+export default new (class implements BadgePresenter {
+ url = new URL(import.meta.url)
+ tiers = true
+ badges = [
+ 'public-keys-1',
+ 'public-keys-2',
+ 'public-keys-3',
+ 'public-keys-4',
+ 'public-keys-5',
+ ] as const
+ present: Present = (data, grant) => {
+ if (data.user.publicKeys.totalCount == 1) {
+ grant('public-keys-1', 'I have one public key').tier(1)
+ }
+ if (data.user.publicKeys.totalCount == 2) {
+ grant('public-keys-2', 'I have two public keys').tier(2)
+ }
+ if (data.user.publicKeys.totalCount == 3) {
+ grant('public-keys-3', 'I have three public keys').tier(3)
+ }
+ if (data.user.publicKeys.totalCount == 4) {
+ grant('public-keys-4', 'I have four public keys').tier(4)
+ }
+ if (data.user.publicKeys.totalCount >= 5) {
+ grant('public-keys-5', 'I have five or more public keys').tier(5)
+ }
+ }
+})()
src/all-badges/index.ts
@@ -15,4 +15,5 @@ export const allBadges = [
await import('./delorean/delorean.js'),
await import('./covid-19/covid-19.js'),
await import('./pr-collaboration/pr-collaboration.js'),
+ await import('./public-keys/public-keys.js'),
] as const
src/collect/user.graphql
@@ -43,6 +43,12 @@ query UserQuery($login: String!) {
starredRepositories {
totalCount
}
+ publicKeys {
+ totalCount
+ nodes {
+ key
+ }
+ }
}
rateLimit {
limit
src/collect/user.ts
@@ -38,6 +38,12 @@ export type UserQuery = {
starredRepositories: {
totalCount: number
}
+ publicKeys: {
+ totalCount: number
+ nodes: Array<{
+ key: string
+ }>
+ }
}
rateLimit: {
limit: number
test/present-badges.test.ts
@@ -5,7 +5,11 @@ import { presentBadges } from '../src/present-badges.js'
describe('present-badges', () => {
const data: Data = {
- user: {} as Data['user'],
+ user: {
+ publicKeys: {
+ totalCount: 1,
+ },
+ } as Data['user'],
pulls: [] as Data['pulls'],
issues: {} as Data['issues'],
repos: [