Added github forks metric to dashboard

This commit is contained in:
r-freeman 2023-02-21 17:03:38 +00:00
parent 44f6eb39d6
commit ad39e0f4fe
2 changed files with 50 additions and 1 deletions

View File

@ -1,4 +1,4 @@
import {getTotalFollowers, getTotalRepos, getTotalStars} from '@/lib/github'
import {getTotalFollowers, getTotalForks, getTotalRepos, getTotalStars} from '@/lib/github'
import {getAllArticles} from '@/lib/getAllArticles'
import {getTopArtist, getTopGenre} from '@/lib/spotify'
import {getViews} from '@/lib/views'
@ -12,6 +12,7 @@ export async function getDashboardData() {
])
const totalStars = await getTotalStars(totalRepos)
const totalForks = await getTotalForks(totalRepos)
const totalArticles = (await getAllArticles()).length
const totalArticleViews = (await getViews()).views
const topArtist = await getTopArtist()
@ -67,6 +68,12 @@ export async function getDashboardData() {
group: "GitHub",
href: "https://github.com/r-freeman/"
},
{
title: "Forks",
value: +totalForks,
group: "GitHub",
href: "https://github.com/r-freeman/"
},
{
title: "Total articles",
value: +totalArticles,

View File

@ -51,6 +51,22 @@ type TotalStarsResponse = {
}
}
type TotalForksResponse = {
data: {
user: {
repositories: {
nodes: [
{
forks: {
totalCount: number
}
}
]
}
}
}
}
export async function getPinnedRepos() {
const response = await fetcher(GITHUB_GRAPHQL, {
method: 'POST',
@ -150,4 +166,30 @@ export async function getTotalStars(totalRepos: number) {
return response.data.user.repositories.nodes
.reduce((acc, node) => acc + node.stargazers.totalCount, 0)
}
export async function getTotalForks(totalRepos: number) {
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: ${totalRepos}) {
nodes {
forks {
totalCount
}
}
}
}
}`
})
}) as TotalForksResponse
return response.data.user.repositories.nodes
.reduce((acc, node) => acc + node.forks.totalCount, 0)
}