Skip to content

Commit

Permalink
Merge pull request #45 from interactivethings/feat/team-communication
Browse files Browse the repository at this point in the history
Feat/team communication
  • Loading branch information
noahonyejese authored Jan 6, 2025
2 parents ca51d53 + e12db3f commit 47d7b37
Show file tree
Hide file tree
Showing 5 changed files with 473 additions and 475 deletions.
124 changes: 124 additions & 0 deletions app/api/github/events/projects/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
import { verifyGitHubRequest } from '@/server/security';
import { createError } from '@/utils/error-handling';
import { NextRequest, NextResponse } from 'next/server';

export const POST = async (req: NextRequest) => {
try {
const rawBody = await req.text();

if (!verifyGitHubRequest(rawBody, req)) {
throw createError({
title: 'Invalid GitHub signature',
message: 'The request signature is invalid',
});
}

const body = JSON.parse(rawBody);
const event = req.headers.get('x-github-event');

switch (event) {
case 'ping':
return NextResponse.json({
status: 'success',
message: 'Pong!',
});

case 'create':
console.log('Create event:', {
ref_type: body.ref_type,
ref: body.ref,
repository: body.repository.full_name,
});
break;

case 'delete':
console.log('Delete event:', {
ref_type: body.ref_type,
ref: body.ref,
repository: body.repository.full_name,
});
break;

case 'check_run':
console.log('Check run event:', {
action: body.action, // created, completed, rerequested
status: body.check_run.status,
conclusion: body.check_run.conclusion,
name: body.check_run.name,
});
break;

case 'deployment_status':
// Deployment status updates
console.log('Deployment status event:', {
action: body.action,
state: body.deployment_status.state,
environment: body.deployment.environment,
});
break;

case 'pull_request_review':
// PR review events
console.log('PR review event:', {
action: body.action,
state: body.review.state,
pr_number: body.pull_request.number,
});
break;

case 'pull_request':
console.log('Pull request event:', {
action: body.action,
number: body.pull_request.number,
state: body.pull_request.state,
merged: body.pull_request.merged,
});
break;

case 'push':
console.log('Push event:', {
ref: body.ref,
commits: body.commits.length,
repository: body.repository.full_name,
});
break;

case 'repository':
console.log('Repository event:', {
action: body.action,
repository: body.repository.full_name,
});
break;

default:
console.log(`Unhandled event type: ${event}`);
}

return NextResponse.json({
success: true,
event: event,
});
} catch (error) {
if (error instanceof Error) {
console.error('Webhook error:', error.message);

return NextResponse.json(
{
success: false,
error: {
message: error.message,
},
},
{ status: 400 }
);
}

return NextResponse.json(
{
success: false,
error: 'Unknown error occurred',
},
{ status: 500 }
);
}
};
Loading

0 comments on commit 47d7b37

Please sign in to comment.