Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions app/(hacktoberfest)/oss-issues/page.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import { getAllOssGgIssuesOfRepos } from "@/lib/github/service";
import { getOssIssuesForRepo } from "@/lib/github/service";
import { getAllRepositories } from "@/lib/repository/service";
import { TPullRequest } from "@/types/pullRequest";
import Link from "next/link";

export default async function IssuesPage() {
const ossGgRepositories = await getAllRepositories();
const pullRequests: TPullRequest[] = await getAllOssGgIssuesOfRepos(
ossGgRepositories.map((repo) => ({ id: repo.githubId, fullName: `${repo.owner}/${repo.name}` }))

const issuesPromises = ossGgRepositories.map((repo) =>
getOssIssuesForRepo(repo.githubId, `${repo.owner}/${repo.name}`)
);

const issuesArrays = await Promise.all(issuesPromises);
const issues: TPullRequest[] = issuesArrays.flat();

return (
<div className="space-y-2 font-mono text-xs">
<h1 className="pb-2 font-bold">available issues ({pullRequests.length})</h1>
<h1 className="pb-2 font-bold">available issues ({issues.length})</h1>
<ul className="list-none space-y-2">
{pullRequests.map((pullRequest) => (
{issues.map((pullRequest) => (
<li key={pullRequest.href}>
<Link href={pullRequest.href} className="underline-offset-4 hover:underline">
{pullRequest.repositoryFullName && <span>{pullRequest.repositoryFullName}</span>}
Expand Down
41 changes: 41 additions & 0 deletions app/api/github-webhook/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { registerHooks } from "@/lib/github";
import { EmitterWebhookEvent, EmitterWebhookEventName } from "@octokit/webhooks";
import { headers } from "next/headers";
import { NextResponse } from "next/server";

// Set to store processed event IDs
const processedEvents = new Set<string>();

export async function POST(req: Request) {
const headersList = headers();
const eventId = headersList.get("x-github-delivery") as string;
const githubEvent = headersList.get("x-github-event") as string;

let body: EmitterWebhookEvent<"issue_comment" | "pull_request" | "installation">["payload"];

try {
body = await req.json();
} catch (error) {
return NextResponse.json({ error: "Invalid JSON payload" }, { status: 400 });
}

if (!eventId) {
return NextResponse.json({ error: "Missing X-GitHub-Delivery header" }, { status: 400 });
}

if (processedEvents.has(eventId)) {
return NextResponse.json({ message: `Event ${eventId} already processed, skipping` }, { status: 200 });
}

await registerHooks(githubEvent as EmitterWebhookEventName, body);

processedEvents.add(eventId);
setTimeout(
() => {
processedEvents.delete(eventId);
},
24 * 60 * 60 * 1000
); // 24 hours

return NextResponse.json({ message: `Event ${eventId} processed` }, { status: 200 });
}
Loading