2023-01-24 22:27:59 +00:00
|
|
|
import type {Repo} from '@/types'
|
2023-02-20 20:46:28 +00:00
|
|
|
import fetcher from '@/lib/fetcher'
|
2023-01-24 22:27:59 +00:00
|
|
|
|
|
|
|
const GITHUB_ACCESS_TOKEN = process.env.GITHUB_ACCESS_TOKEN
|
2023-01-28 22:12:58 +00:00
|
|
|
const GITHUB_USERNAME = process.env.GITHUB_USERNAME
|
2023-01-24 22:27:59 +00:00
|
|
|
const GITHUB_GRAPHQL = "https://api.github.com/graphql"
|
|
|
|
|
2023-01-27 23:33:49 +00:00
|
|
|
type PinnedReposResponse = {
|
2023-01-24 22:27:59 +00:00
|
|
|
data: {
|
|
|
|
user: {
|
|
|
|
pinnedItems: {
|
|
|
|
nodes: Repo[]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getPinnedRepos() {
|
2023-01-28 21:24:05 +00:00
|
|
|
const response = await fetcher(GITHUB_GRAPHQL, {
|
2023-01-24 22:27:59 +00:00
|
|
|
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}") {
|
2023-01-24 22:27:59 +00:00
|
|
|
pinnedItems(first: 6, types: REPOSITORY) {
|
|
|
|
nodes {
|
|
|
|
... on Repository {
|
|
|
|
name
|
|
|
|
description
|
|
|
|
url
|
|
|
|
stargazerCount
|
2023-01-26 22:21:15 +00:00
|
|
|
forkCount
|
2023-01-24 22:27:59 +00:00
|
|
|
primaryLanguage {
|
|
|
|
name
|
|
|
|
color
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}`
|
|
|
|
})
|
2023-01-28 21:24:05 +00:00
|
|
|
}) as PinnedReposResponse
|
2023-01-24 22:27:59 +00:00
|
|
|
|
|
|
|
return response.data.user.pinnedItems.nodes
|
|
|
|
}
|