feat: add github token for portfolio stats

This commit is contained in:
DIYgod
2023-08-10 23:33:04 +01:00
parent 4fd8cb95c3
commit f3a8d92d0e
5 changed files with 28 additions and 3 deletions
+17 -2
View File
@@ -1,5 +1,6 @@
import * as cheerio from "cheerio"
import { PORTFOLIO_GITHUB_TOKEN } from "~/lib/env.server"
import { cacheGet } from "~/lib/redis.server"
import { NextServerResponse, getQuery } from "~/lib/server-helper"
import { PortfolioStats } from "~/lib/types"
@@ -81,6 +82,13 @@ export async function GET(req: Request) {
`https://api.github.com/repos/${url.pathname.split("/")[1]}/${
url.pathname.split("/")[2]
}`,
PORTFOLIO_GITHUB_TOKEN
? {
headers: {
Authorization: `Bearer ${PORTFOLIO_GITHUB_TOKEN}`,
},
}
: undefined,
)
).json()
const issuesData = await (
@@ -88,12 +96,19 @@ export async function GET(req: Request) {
`https://api.github.com/repos/${url.pathname.split("/")[1]}/${
url.pathname.split("/")[2]
}/issues`,
PORTFOLIO_GITHUB_TOKEN
? {
headers: {
Authorization: `Bearer ${PORTFOLIO_GITHUB_TOKEN}`,
},
}
: undefined,
)
).json()
if (repoData?.stargazers_count || issuesData?.[0]?.number) {
result = {
projectStarsCount: repoData.stargazers_count,
commentsCount: issuesData[0].number,
projectStarsCount: repoData?.stargazers_count,
commentsCount: issuesData?.[0]?.number,
}
}
break