prodeclabs / perlify

0 stars 0 forks source link

feat: add feature to let users connect their repositories with perlify #3

Open sourabhrathourr opened 1 month ago

sourabhrathourr commented 1 month ago

GitHub App Installation & Webhook Integration Documentation

Overview

This documentation covers the setup and handling of GitHub App installations and webhooks in a Next.js application using Drizzle ORM and Neon Database.

Database Schema


export const installations = pgTable('installation', {

  id: text('id').primaryKey(),

  userId: text('userId')

    .notNull()

    .references(() => users.id, { onDelete: 'cascade' }),

  installationId: text('installationId').notNull(),

  accountName: text('accountName').notNull(),

  repositoryIds: text('repositoryIds').array(),

  createdAt: timestamp('createdAt').defaultNow(),

  updatedAt: timestamp('updatedAt').defaultNow(),

})

Required Environment Variables


DATABASE_URL=your_neon_db_url

GITHUB_WEBHOOK_SECRET=your_webhook_secret

NEXT_PUBLIC_GITHUB_APP_NAME=your_github_app_name

GITHUB_APP_ID=your_app_id

GITHUB_APP_PRIVATE_KEY="your_private_key"

Installation Steps

  1. GitHub App Configuration
  1. Development Setup

# Start development server

yarn dev

# Start ngrok tunnel (for local development)

yarn tunnel

Webhook Handler Implementation

The webhook handler (app/api/github/webhook/route.ts) processes GitHub App installation events and manages repository connections:

  1. Verifies webhook signature
  2. Handles installation events:
    • created: Creates new installation record
    • added/removed: Updates repository list
  3. Links installations to authenticated users via GitHub accounts

Technical Notes

Error Handling

The webhook handler includes comprehensive error handling for:

API Response Codes

References

linear[bot] commented 1 month ago

PER-38 feat: add feature to let users connect their repositories with perlify