mirror of
https://github.com/r-freeman/portfolio.git
synced 2024-11-11 18:45:41 +00:00
Added github forks metric to dashboard
This commit is contained in:
parent
44f6eb39d6
commit
ad39e0f4fe
@ -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,
|
||||
|
@ -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',
|
||||
@ -151,3 +167,29 @@ 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)
|
||||
}
|
Loading…
Reference in New Issue
Block a user