site/pages/api/stars.js
2023-03-01 23:57:35 +00:00

41 lines
1.1 KiB
JavaScript

import { graphql } from '@octokit/graphql'
export async function fetchStars() {
if (!process.env.GITHUB_TOKEN) {
console.warn("Note - GITHUB_TOKEN not defined, stars will not be fetched from github")
return { sprig:"?", sinerider:"?", sprigHardware:"?", hackclub:"?", hackathons:"?"};
}
const { organization } = await graphql(
`
{
organization(login: "hackclub") {
sinerider: repository(name: "sinerider") {
stargazerCount
}
sprig: repository(name: "sprig") {
stargazerCount
}
hackclub: repository(name: "hackclub") {
stargazerCount
}
hackathons: repository(name: "hackathons") {
stargazerCount
}
sprigHardware: repository(name: "sprig-hardware") {
stargazerCount
}
}
}
`,
{
headers: {
authorization: `token ${process.env.GITHUB_TOKEN}`
}
}
)
return organization
}
export default async function Stars(req, res) {
res.status(200).json(await fetchStars())
}