Added top repo metric to dashboard

This commit is contained in:
r-freeman 2023-02-21 21:21:11 +00:00
parent ad39e0f4fe
commit 51717e99a0
2 changed files with 58 additions and 1 deletions

View File

@ -1,4 +1,10 @@
import {getTotalFollowers, getTotalForks, getTotalRepos, getTotalStars} from '@/lib/github' import {
getTopRepo,
getTotalFollowers,
getTotalForks,
getTotalRepos,
getTotalStars
} from '@/lib/github'
import {getAllArticles} from '@/lib/getAllArticles' import {getAllArticles} from '@/lib/getAllArticles'
import {getTopArtist, getTopGenre} from '@/lib/spotify' import {getTopArtist, getTopGenre} from '@/lib/spotify'
import {getViews} from '@/lib/views' import {getViews} from '@/lib/views'
@ -11,6 +17,7 @@ export async function getDashboardData() {
getTotalFollowers() getTotalFollowers()
]) ])
const topRepo = await getTopRepo()
const totalStars = await getTotalStars(totalRepos) const totalStars = await getTotalStars(totalRepos)
const totalForks = await getTotalForks(totalRepos) const totalForks = await getTotalForks(totalRepos)
const totalArticles = (await getAllArticles()).length const totalArticles = (await getAllArticles()).length
@ -56,6 +63,12 @@ export async function getDashboardData() {
group: "GitHub", group: "GitHub",
href: "https://github.com/r-freeman?tab=repositories" href: "https://github.com/r-freeman?tab=repositories"
}, },
{
title: "Top repo",
value: topRepo.name,
group: "GitHub",
href: topRepo.url
},
{ {
title: "Followers", title: "Followers",
value: +totalFollowers, value: +totalFollowers,

View File

@ -67,6 +67,21 @@ type TotalForksResponse = {
} }
} }
type TopRepoResponse = {
data: {
user: {
repositories: {
nodes: [
{
name: string
url: string
}
]
}
}
}
}
export async function getPinnedRepos() { export async function getPinnedRepos() {
const response = await fetcher(GITHUB_GRAPHQL, { const response = await fetcher(GITHUB_GRAPHQL, {
method: 'POST', method: 'POST',
@ -193,3 +208,32 @@ export async function getTotalForks(totalRepos: number) {
return response.data.user.repositories.nodes return response.data.user.repositories.nodes
.reduce((acc, node) => acc + node.forks.totalCount, 0) .reduce((acc, node) => acc + node.forks.totalCount, 0)
} }
export async function getTopRepo() {
const response = await fetcher(GITHUB_GRAPHQL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${GITHUB_ACCESS_TOKEN}`
},
body: JSON.stringify({
query: `{
user(login: "${GITHUB_USERNAME}") {
repositories(first: 1, orderBy: {field: STARGAZERS, direction: DESC}) {
nodes {
name
url
}
}
}
}`
})
}) as TopRepoResponse
const {name, url} = response.data.user.repositories.nodes[0]
return {
name,
url
}
}