mirror of
https://github.com/r-freeman/portfolio.git
synced 2024-11-22 14:05:42 +00:00
Added top repo metric to dashboard
This commit is contained in:
parent
ad39e0f4fe
commit
51717e99a0
@ -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 {getTopArtist, getTopGenre} from '@/lib/spotify'
|
||||
import {getViews} from '@/lib/views'
|
||||
@ -11,6 +17,7 @@ export async function getDashboardData() {
|
||||
getTotalFollowers()
|
||||
])
|
||||
|
||||
const topRepo = await getTopRepo()
|
||||
const totalStars = await getTotalStars(totalRepos)
|
||||
const totalForks = await getTotalForks(totalRepos)
|
||||
const totalArticles = (await getAllArticles()).length
|
||||
@ -56,6 +63,12 @@ export async function getDashboardData() {
|
||||
group: "GitHub",
|
||||
href: "https://github.com/r-freeman?tab=repositories"
|
||||
},
|
||||
{
|
||||
title: "Top repo",
|
||||
value: topRepo.name,
|
||||
group: "GitHub",
|
||||
href: topRepo.url
|
||||
},
|
||||
{
|
||||
title: "Followers",
|
||||
value: +totalFollowers,
|
||||
|
@ -67,6 +67,21 @@ type TotalForksResponse = {
|
||||
}
|
||||
}
|
||||
|
||||
type TopRepoResponse = {
|
||||
data: {
|
||||
user: {
|
||||
repositories: {
|
||||
nodes: [
|
||||
{
|
||||
name: string
|
||||
url: string
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export async function getPinnedRepos() {
|
||||
const response = await fetcher(GITHUB_GRAPHQL, {
|
||||
method: 'POST',
|
||||
@ -192,4 +207,33 @@ export async function getTotalForks(totalRepos: number) {
|
||||
|
||||
return response.data.user.repositories.nodes
|
||||
.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
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user