/**Achievements list for users accounts */ export default async function({list, login, data, computed, imports, graphql, queries, rest, rank, leaderboard}) { //Initialization const {user} = await graphql(queries.achievements({login})) const scores = {followers: user.followers.totalCount, created: user.repositories.totalCount, stars: user.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} //Developer { const value = user.repositories.totalCount const unlock = user.repositories.nodes?.shift() list.push({ title: "Developer", text: `Published ${value} public repositor${imports.s(value, "y")}`, icon: '', ...rank(value, [1, 20, 50, 100, 250]), value, unlock: new Date(unlock?.createdAt), leaderboard: leaderboard({user: ranks.created_rank.userCount, requirement: scores.created >= requirements.created, type: "users"}), }) } //Forker { const value = user.forks.totalCount const unlock = user.forks.nodes?.shift() list.push({ title: "Forker", text: `Forked ${value} public repositor${imports.s(value, "y")}`, icon: '', ...rank(value, [1, 5, 10, 20, 50]), value, unlock: new Date(unlock?.createdAt), }) } //Contributor { const value = user.pullRequests.totalCount const unlock = user.pullRequests.nodes?.shift() list.push({ title: "Contributor", text: `Opened ${value} pull request${imports.s(value)}`, icon: '', ...rank(value, [1, 200, 500, 1000, 2500]), value, unlock: new Date(unlock?.createdAt), }) } //Manager { const value = user.projects.totalCount const unlock = user.projects.nodes?.shift() list.push({ title: "Manager", text: `Created ${value} user project${imports.s(value)}`, icon: '', ...rank(value, [1, 2, 3, 4, 5]), value, unlock: new Date(unlock?.createdAt), }) } //Reviewer { const value = user.contributionsCollection.pullRequestReviewContributions.totalCount const unlock = user.contributionsCollection.pullRequestReviewContributions.nodes?.shift() list.push({ title: "Reviewer", text: `Reviewed ${value} pull request${imports.s(value)}`, icon: '', ...rank(value, [1, 200, 500, 1000, 2500]), value, unlock: new Date(unlock?.createdAt), }) } //Packager { const value = user.packages.totalCount + ((await rest.packages.listPackagesForUser({package_type: "container", username: login}).catch(() => ({data: []})))?.data?.length || 0) const unlock = user.packages.nodes?.shift() list.push({ title: "Packager", text: `Created ${value} package${imports.s(value)}`, icon: '', ...rank(value, [1, 5, 10, 20, 30]), value, unlock: new Date(unlock?.createdAt), }) } //Gister { const value = user.gists.totalCount const unlock = user.gists.nodes?.shift() list.push({ title: "Gister", text: `Published ${value} gist${imports.s(value)}`, icon: '', ...rank(value, [1, 20, 50, 100, 250]), value, unlock: new Date(unlock?.createdAt), }) } //Worker { const value = user.organizations.totalCount const unlock = user.organizations.nodes?.shift() list.push({ title: "Worker", text: `Joined ${value} organization${imports.s(value)}`, icon: '', ...rank(value, [1, 2, 4, 8, 10]), value, unlock: new Date(unlock?.createdAt), }) } //Stargazer { const value = user.starredRepositories.totalCount const unlock = user.starredRepositories.nodes?.shift() list.push({ title: "Stargazer", text: `Starred ${value} repositor${imports.s(value, "y")}`, icon: '', ...rank(value, [1, 200, 500, 1000, 2500]), value, unlock: new Date(unlock?.createdAt), }) } //Follower { const value = user.following.totalCount const unlock = user.following.nodes?.shift() list.push({ title: "Follower", text: `Following ${value} user${imports.s(value)}`, icon: '', ...rank(value, [1, 200, 500, 1000, 2500]), value, unlock: new Date(unlock?.createdAt), }) } //Influencer { const value = user.followers.totalCount const unlock = user.followers.nodes?.shift() list.push({ title: "Influencer", text: `Followed by ${value} user${imports.s(value)}`, icon: '', ...rank(value, [1, 200, 500, 1000, 2500]), value, unlock: new Date(unlock?.createdAt), leaderboard: leaderboard({user: ranks.user_rank.userCount, requirement: scores.followers >= requirements.followers, type: "users"}), }) } //Maintainer { const value = user.popular.nodes?.shift()?.stargazers?.totalCount ?? 0 const unlock = null list.push({ title: "Maintainer", text: `Maintaining a repository with ${value} star${imports.s(value)}`, icon: '', ...rank(value, [1, 1000, 5000, 10000, 25000]), value, unlock: new Date(unlock?.createdAt), leaderboard: leaderboard({user: ranks.repo_rank.repositoryCount, requirement: scores.stars >= requirements.stars, type: "repositories"}), }) } //Inspirer { const value = Math.max(0, ...data.user.repositories.nodes.map(({forkCount}) => forkCount)) const unlock = null list.push({ title: "Inspirer", text: `Maintaining or created a repository which has been forked ${value} time${imports.s(value)}`, icon: '', ...rank(value, [1, 100, 500, 1000, 2500]), value, unlock: new Date(unlock?.createdAt), leaderboard: leaderboard({user: ranks.forks_rank.repositoryCount, requirement: scores.forks >= requirements.forks, type: "repositories"}), }) } //Polyglot { const value = new Set(data.user.repositories.nodes.flatMap(repository => repository.languages.edges.map(({node: {name}}) => name))).size const unlock = null list.push({ title: "Polyglot", text: `Using ${value} different programming language${imports.s(value)}`, icon: '', ...rank(value, [1, 4, 8, 16, 32]), 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), }) } //Sponsors { const value = user.sponsorshipsAsSponsor.totalCount const unlock = null list.push({ title: "Sponsor", text: `Sponsoring ${value} user${imports.s(value)} or organization${imports.s(value)}`, icon: '', ...rank(value, [1, 3, 5, 10, 25]), value, unlock: new Date(unlock?.createdAt), }) } //Deployer { const value = computed.repositories?.deployments const unlock = null list.push({ title: "Deployer", text: `Repositories have been deployed ${value} time${imports.s(value)}`, icon: '', ...rank(value, [1, 200, 500, 1000, 2500]), value, unlock: new Date(unlock?.createdAt), }) } //Chatter { const value = user.discussionsStarted.totalCount + user.discussionsComments.totalCount const unlock = null list.push({ title: "Chatter", text: `Participated in discussions ${value} time${imports.s(value)}`, icon: '', ...rank(value, [1, 200, 500, 1000, 2500]), value, unlock: new Date(unlock?.createdAt), }) } //Helper { const value = user.discussionAnswers.totalCount const unlock = null list.push({ title: "Helper", text: `Answered and solved ${value} discussion${imports.s(value)}`, icon: '', ...rank(value, [1, 20, 50, 100, 250]), value, unlock: new Date(unlock?.createdAt), }) } //Verified { const value = !/This user hasn't uploaded any GPG keys/i.test((await imports.axios.get(`https://github.com/${login}.gpg`)).data) const unlock = null list.push({ title: "Verified", text: "Registered a GPG key to sign commits", icon: '', rank: value ? "$" : "X", progress: value ? 1 : 0, value, unlock: new Date(unlock?.createdAt), }) } //Explorer { const value = !/doesn’t have any starred topics yet/i.test((await imports.axios.get(`https://github.com/stars/${login}/topics`)).data) const unlock = null list.push({ title: "Explorer", text: "Starred a topic on GitHub Explore", icon: '', rank: value ? "$" : "X", progress: value ? 1 : 0, value, unlock: new Date(unlock?.createdAt), }) } //Automator { const value = process.env.GITHUB_ACTIONS const unlock = null list.push({ title: "Automator", text: "Use GitHub Actions to automate profile updates", icon: '', rank: value ? "$" : "X", progress: value ? 1 : 0, value, unlock: new Date(unlock?.createdAt), }) } //Infographile { const {repository: {viewerHasStarred: value}, viewer: {login: _login}} = await graphql(queries.achievements.metrics()) const unlock = null list.push({ title: "Infographile", text: "Fervent supporter of metrics", icon: '', rank: (value) && (login === _login) ? "$" : "X", progress: (value) && (login === _login) ? 1 : 0, value, unlock: new Date(unlock?.createdAt), }) } //Octonaut { const {user: {viewerIsFollowing: value}, viewer: {login: _login}} = await graphql(queries.achievements.octocat()) const unlock = null list.push({ title: "Octonaut", text: "Following octocat", icon: '', rank: (value) && (login === _login) ? "$" : "X", progress: (value) && (login === _login) ? 1 : 0, value, unlock: new Date(unlock?.createdAt), }) } }