Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion server/utils/contributors.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Contributor, ModuleMaintainer } from '#shared/types'
import type { Contributor, ModuleMaintainer, ModuleContributor } from '#shared/types'
import { Octokit } from 'octokit'

export const fetchContributors = cachedFunction<Contributor[]>(async (event) => {
Expand All @@ -17,6 +17,25 @@ export const fetchModuleMaintainers = cachedFunction<ModuleMaintainer[]>(async (
maxAge: 60 * 10, // 10 minutes
})

export const fetchAllModuleContributors = cachedFunction<ModuleContributor[]>(async () => {
const modules = await $fetch<{ modules: { contributors: ModuleContributor[] }[] }>('https://api.nuxt.com/modules').then(data => data.modules).catch(() => null)
if (modules === null) return []

// Combine contributors across modules
const rawContributors = modules.map(mod => mod.contributors).flat()
const contributors = rawContributors.reduce((map, contributor) => {
let data = map.get(contributor.id)
if (data === undefined) data = contributor
else data.contributions = data.contributions + contributor.contributions
map.set(contributor.id, data)
return map
}, new Map<ModuleContributor['id'], ModuleContributor>())
return Array.from(contributors.values())
}, {
getKey: () => 'module-contributors',
maxAge: 60 * 10, // 10 minutes
})

export const fetchNuxtUIProOutsideCollaborators = cachedFunction<string[]>(async () => {
// Fetch on GitHub the outside collaborators of the Nuxt UI Pro repository
const octokit = new Octokit({
Expand Down
6 changes: 6 additions & 0 deletions shared/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ export interface ModuleMaintainer {
modules: string[]
}

export interface ModuleContributor {
id: number
username: string
contributions: number
}

export interface Score {
type: string
multiplier: number | ''
Expand Down