portfolio/lib/github.ts

49 lines
1.3 KiB
TypeScript
Raw Normal View History

import type {Repo} from '@/types'
2023-02-20 20:46:28 +00:00
import fetcher from '@/lib/fetcher'
const GITHUB_ACCESS_TOKEN = process.env.GITHUB_ACCESS_TOKEN
2023-01-28 22:12:58 +00:00
const GITHUB_USERNAME = process.env.GITHUB_USERNAME
const GITHUB_GRAPHQL = "https://api.github.com/graphql"
2023-01-27 23:33:49 +00:00
type PinnedReposResponse = {
data: {
user: {
pinnedItems: {
nodes: Repo[]
}
}
}
}
export async function getPinnedRepos() {
2023-01-28 21:24:05 +00:00
const response = await fetcher(GITHUB_GRAPHQL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${GITHUB_ACCESS_TOKEN}`
},
body: JSON.stringify({
query: `{
2023-01-28 22:12:58 +00:00
user(login: "${GITHUB_USERNAME}") {
pinnedItems(first: 6, types: REPOSITORY) {
nodes {
... on Repository {
name
description
url
stargazerCount
2023-01-26 22:21:15 +00:00
forkCount
primaryLanguage {
name
color
}
}
}
}
}
}`
})
2023-01-28 21:24:05 +00:00
}) as PinnedReposResponse
return response.data.user.pinnedItems.nodes
}