mirror of
				https://github.com/r-freeman/portfolio.git
				synced 2025-11-03 23:31:11 +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 {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'
 | 
				
			||||||
@ -12,6 +12,7 @@ export async function getDashboardData() {
 | 
				
			|||||||
    ])
 | 
					    ])
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    const totalStars = await getTotalStars(totalRepos)
 | 
					    const totalStars = await getTotalStars(totalRepos)
 | 
				
			||||||
 | 
					    const totalForks = await getTotalForks(totalRepos)
 | 
				
			||||||
    const totalArticles = (await getAllArticles()).length
 | 
					    const totalArticles = (await getAllArticles()).length
 | 
				
			||||||
    const totalArticleViews = (await getViews()).views
 | 
					    const totalArticleViews = (await getViews()).views
 | 
				
			||||||
    const topArtist = await getTopArtist()
 | 
					    const topArtist = await getTopArtist()
 | 
				
			||||||
@ -67,6 +68,12 @@ export async function getDashboardData() {
 | 
				
			|||||||
            group: "GitHub",
 | 
					            group: "GitHub",
 | 
				
			||||||
            href: "https://github.com/r-freeman/"
 | 
					            href: "https://github.com/r-freeman/"
 | 
				
			||||||
        },
 | 
					        },
 | 
				
			||||||
 | 
					        {
 | 
				
			||||||
 | 
					            title: "Forks",
 | 
				
			||||||
 | 
					            value: +totalForks,
 | 
				
			||||||
 | 
					            group: "GitHub",
 | 
				
			||||||
 | 
					            href: "https://github.com/r-freeman/"
 | 
				
			||||||
 | 
					        },
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            title: "Total articles",
 | 
					            title: "Total articles",
 | 
				
			||||||
            value: +totalArticles,
 | 
					            value: +totalArticles,
 | 
				
			||||||
 | 
				
			|||||||
@ -51,6 +51,22 @@ type TotalStarsResponse = {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					type TotalForksResponse = {
 | 
				
			||||||
 | 
					    data: {
 | 
				
			||||||
 | 
					        user: {
 | 
				
			||||||
 | 
					            repositories: {
 | 
				
			||||||
 | 
					                nodes: [
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
 | 
					                        forks: {
 | 
				
			||||||
 | 
					                            totalCount: number
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                ]
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
export async function getPinnedRepos() {
 | 
					export async function getPinnedRepos() {
 | 
				
			||||||
    const response = await fetcher(GITHUB_GRAPHQL, {
 | 
					    const response = await fetcher(GITHUB_GRAPHQL, {
 | 
				
			||||||
        method: 'POST',
 | 
					        method: 'POST',
 | 
				
			||||||
@ -151,3 +167,29 @@ export async function getTotalStars(totalRepos: number) {
 | 
				
			|||||||
    return response.data.user.repositories.nodes
 | 
					    return response.data.user.repositories.nodes
 | 
				
			||||||
        .reduce((acc, node) => acc + node.stargazers.totalCount, 0)
 | 
					        .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…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user