/**Achievements list for users accounts */
export default async function({list, login, data, computed, imports, graphql, queries, rest, rank, leaderboard}) {
//Initialization
const {organization} = await graphql(queries.achievements.organizations({login}))
const scores = {followers: 0, created: organization.repositories.totalCount, stars: organization.popular.nodes?.[0]?.stargazers?.totalCount ?? 0, forks: Math.max(0, ...data.user.repositories.nodes.map(({forkCount}) => forkCount))}
const ranks = await graphql(queries.achievements.ranking(scores))
const requirements = {stars: 5, followers: 3, forks: 1, created: 1}
//Developers
{
const value = organization.repositories.totalCount
const unlock = organization.repositories.nodes?.shift()
list.push({
title: "Developers",
text: `Published ${value} public repositor${imports.s(value, "y")}`,
icon:
'',
...rank(value, [1, 50, 100, 200, 300]),
value,
unlock: new Date(unlock?.createdAt),
leaderboard: leaderboard({user: ranks.created_rank.userCount, requirement: scores.created >= requirements.created, type: "users"}),
})
}
//Forkers
{
const value = organization.forks.totalCount
const unlock = organization.forks.nodes?.shift()
list.push({
title: "Forkers",
text: `Forked ${value} public repositor${imports.s(value, "y")}`,
icon:
'',
...rank(value, [1, 10, 30, 50, 100]),
value,
unlock: new Date(unlock?.createdAt),
})
}
//Managers
{
const value = organization.projects.totalCount
const unlock = organization.projects.nodes?.shift()
list.push({
title: "Managers",
text: `Created ${value} user project${imports.s(value)}`,
icon:
'',
...rank(value, [1, 2, 4, 8, 10]),
value,
unlock: new Date(unlock?.createdAt),
})
}
//Packagers
{
const value = organization.packages.totalCount + ((await rest.packages.listPackagesForOrganization({package_type: "container", org: login}).catch(() => ({data: []})))?.data?.length || 0)
const unlock = organization.packages.nodes?.shift()
list.push({
title: "Packagers",
text: `Created ${value} package${imports.s(value)}`,
icon:
'',
...rank(value, [1, 20, 50, 100, 250]),
value,
unlock: new Date(unlock?.createdAt),
})
}
//Maintainers
{
const value = organization.popular.nodes?.shift()?.stargazers?.totalCount ?? 0
const unlock = null
list.push({
title: "Maintainers",
text: `Maintaining a repository with ${value} star${imports.s(value)}`,
icon:
'',
...rank(value, [1, 5000, 10000, 30000, 50000]),
value,
unlock: new Date(unlock?.createdAt),
leaderboard: leaderboard({user: ranks.repo_rank.repositoryCount, requirement: scores.stars >= requirements.stars, type: "repositories"}),
})
}
//Inspirers
{
const value = Math.max(0, ...data.user.repositories.nodes.map(({forkCount}) => forkCount))
const unlock = null
list.push({
title: "Inspirers",
text: `Maintaining or created a repository which has been forked ${value} time${imports.s(value)}`,
icon:
'',
...rank(value, [1, 500, 1000, 3000, 5000]),
value,
unlock: new Date(unlock?.createdAt),
leaderboard: leaderboard({user: ranks.forks_rank.repositoryCount, requirement: scores.forks >= requirements.forks, type: "repositories"}),
})
}
//Polyglots
{
const value = new Set(data.user.repositories.nodes.flatMap(repository => repository.languages.edges.map(({node: {name}}) => name))).size
const unlock = null
list.push({
title: "Polyglots",
text: `Using ${value} different programming language${imports.s(value)}`,
icon:
'',
...rank(value, [1, 8, 16, 32, 64]),
value,
unlock: new Date(unlock?.createdAt),
})
}
//Sponsors
{
const value = organization.sponsorshipsAsSponsor.totalCount
const unlock = null
list.push({
title: "Sponsors",
text: `Sponsoring ${value} user${imports.s(value)} or organization${imports.s(value)}`,
icon:
'',
...rank(value, [1, 5, 10, 20, 50]),
value,
unlock: new Date(unlock?.createdAt),
})
}
//Organization
{
const value = organization.membersWithRole.totalCount
const unlock = null
list.push({
title: "Organization",
text: `Has ${value} member${imports.s(value)}`,
icon:
'',
...rank(value, [1, 100, 500, 1000, 2500]),
value,
unlock: new Date(unlock?.createdAt),
})
}
//Member
{
const {years: value} = computed.registered
const unlock = null
list.push({
title: "Member",
text: `Registered ${Math.floor(value)} year${imports.s(Math.floor(value))} ago`,
icon:
'',
...rank(value, [1, 3, 5, 10, 15]),
value,
unlock: new Date(unlock?.createdAt),
})
}
}