mirror of
https://github.com/documenso/documenso.git
synced 2025-11-23 05:01:54 +10:00
fix: fetch the correct number of open issues using the github search api (#495)
This commit is contained in:
committed by
GitHub
parent
e3b589516b
commit
34527c1842
@ -18,6 +18,14 @@ export const revalidate = 3600;
|
|||||||
|
|
||||||
export const dynamic = 'force-dynamic';
|
export const dynamic = 'force-dynamic';
|
||||||
|
|
||||||
|
const GITHUB_HEADERS: Record<string, string> = {
|
||||||
|
accept: 'application/vnd.github.v3+json',
|
||||||
|
};
|
||||||
|
|
||||||
|
if (process.env.NEXT_PRIVATE_GITHUB_TOKEN) {
|
||||||
|
GITHUB_HEADERS.authorization = `Bearer ${process.env.NEXT_PRIVATE_GITHUB_TOKEN}`;
|
||||||
|
}
|
||||||
|
|
||||||
const ZGithubStatsResponse = z.object({
|
const ZGithubStatsResponse = z.object({
|
||||||
stargazers_count: z.number(),
|
stargazers_count: z.number(),
|
||||||
forks_count: z.number(),
|
forks_count: z.number(),
|
||||||
@ -28,6 +36,10 @@ const ZMergedPullRequestsResponse = z.object({
|
|||||||
total_count: z.number(),
|
total_count: z.number(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const ZOpenIssuesResponse = z.object({
|
||||||
|
total_count: z.number(),
|
||||||
|
});
|
||||||
|
|
||||||
const ZStargazersLiveResponse = z.record(
|
const ZStargazersLiveResponse = z.record(
|
||||||
z.object({
|
z.object({
|
||||||
stars: z.number(),
|
stars: z.number(),
|
||||||
@ -48,49 +60,76 @@ const ZEarlyAdoptersResponse = z.record(
|
|||||||
export type StargazersType = z.infer<typeof ZStargazersLiveResponse>;
|
export type StargazersType = z.infer<typeof ZStargazersLiveResponse>;
|
||||||
export type EarlyAdoptersType = z.infer<typeof ZEarlyAdoptersResponse>;
|
export type EarlyAdoptersType = z.infer<typeof ZEarlyAdoptersResponse>;
|
||||||
|
|
||||||
export default async function OpenPage() {
|
const fetchGithubStats = async () => {
|
||||||
const GITHUB_HEADERS: Record<string, string> = {
|
return await fetch('https://api.github.com/repos/documenso/documenso', {
|
||||||
accept: 'application/vnd.github.v3+json',
|
headers: {
|
||||||
};
|
...GITHUB_HEADERS,
|
||||||
|
},
|
||||||
if (process.env.NEXT_PRIVATE_GITHUB_TOKEN) {
|
|
||||||
GITHUB_HEADERS.authorization = `Bearer ${process.env.NEXT_PRIVATE_GITHUB_TOKEN}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
const {
|
|
||||||
forks_count: forksCount,
|
|
||||||
open_issues: openIssues,
|
|
||||||
stargazers_count: stargazersCount,
|
|
||||||
} = await fetch('https://api.github.com/repos/documenso/documenso', {
|
|
||||||
headers: GITHUB_HEADERS,
|
|
||||||
})
|
})
|
||||||
.then(async (res) => res.json())
|
.then(async (res) => res.json())
|
||||||
.then((res) => ZGithubStatsResponse.parse(res));
|
.then((res) => ZGithubStatsResponse.parse(res));
|
||||||
|
};
|
||||||
|
|
||||||
const { total_count: mergedPullRequests } = await fetch(
|
const fetchOpenIssues = async () => {
|
||||||
|
return await fetch(
|
||||||
|
'https://api.github.com/search/issues?q=repo:documenso/documenso+type:issue+state:open&page=0&per_page=1',
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
...GITHUB_HEADERS,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
)
|
||||||
|
.then(async (res) => res.json())
|
||||||
|
.then((res) => ZOpenIssuesResponse.parse(res));
|
||||||
|
};
|
||||||
|
|
||||||
|
const fetchMergedPullRequests = async () => {
|
||||||
|
return await fetch(
|
||||||
'https://api.github.com/search/issues?q=repo:documenso/documenso/+is:pr+merged:>=2010-01-01&page=0&per_page=1',
|
'https://api.github.com/search/issues?q=repo:documenso/documenso/+is:pr+merged:>=2010-01-01&page=0&per_page=1',
|
||||||
{
|
{
|
||||||
headers: GITHUB_HEADERS,
|
headers: {
|
||||||
|
...GITHUB_HEADERS,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
.then(async (res) => res.json())
|
.then(async (res) => res.json())
|
||||||
.then((res) => ZMergedPullRequestsResponse.parse(res));
|
.then((res) => ZMergedPullRequestsResponse.parse(res));
|
||||||
|
};
|
||||||
|
|
||||||
const STARGAZERS_DATA = await fetch('https://stargrazer-live.onrender.com/api/stats', {
|
const fetchStargazers = async () => {
|
||||||
|
return await fetch('https://stargrazer-live.onrender.com/api/stats', {
|
||||||
headers: {
|
headers: {
|
||||||
accept: 'application/json',
|
accept: 'application/json',
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then(async (res) => res.json())
|
.then(async (res) => res.json())
|
||||||
.then((res) => ZStargazersLiveResponse.parse(res));
|
.then((res) => ZStargazersLiveResponse.parse(res));
|
||||||
|
};
|
||||||
|
|
||||||
const EARLY_ADOPTERS_DATA = await fetch('https://stargrazer-live.onrender.com/api/stats/stripe', {
|
const fetchEarlyAdopters = async () => {
|
||||||
|
return await fetch('https://stargrazer-live.onrender.com/api/stats/stripe', {
|
||||||
headers: {
|
headers: {
|
||||||
accept: 'application/json',
|
accept: 'application/json',
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
.then(async (res) => res.json())
|
.then(async (res) => res.json())
|
||||||
.then((res) => ZEarlyAdoptersResponse.parse(res));
|
.then((res) => ZEarlyAdoptersResponse.parse(res));
|
||||||
|
};
|
||||||
|
|
||||||
|
export default async function OpenPage() {
|
||||||
|
const [
|
||||||
|
{ forks_count: forksCount, stargazers_count: stargazersCount },
|
||||||
|
{ total_count: openIssues },
|
||||||
|
{ total_count: mergedPullRequests },
|
||||||
|
STARGAZERS_DATA,
|
||||||
|
EARLY_ADOPTERS_DATA,
|
||||||
|
] = await Promise.all([
|
||||||
|
fetchGithubStats(),
|
||||||
|
fetchOpenIssues(),
|
||||||
|
fetchMergedPullRequests(),
|
||||||
|
fetchStargazers(),
|
||||||
|
fetchEarlyAdopters(),
|
||||||
|
]);
|
||||||
|
|
||||||
const MONTHLY_USERS = await getUserMonthlyGrowth();
|
const MONTHLY_USERS = await getUserMonthlyGrowth();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user