middleware icon indicating copy to clipboard operation
middleware copied to clipboard

feat: GitHub Webhooks middleware

Open oscarvz opened this issue 1 year ago • 2 comments

Introduces middleware that allows you to receive and process GitHub Webhooks events in your Hono application. It conveniently validates the incoming requests and provides you with a simple API to handle the events.

Usage

import { Hono } from 'hono'
import { gitHubWebhooksMiddleware } from '@hono/github-webhooks'

type Env = {
  GITHUB_WEBHOOK_SECRET: string
}

const app = new Hono<{ Bindings: Env }>()

app.use('/webhook', gitHubWebhooksMiddleware())

app.post('/webhook', async (c) => {
  const webhooks = c.get('webhooks') /* const webhooks = c.var.webhooks */

  webhooks.on('star.created', async ({ id, name, payload }) => {
    // handle star creation here
  })

  webhooks.on('issues.opened', async ({ id, name, payload }) => {
    // handle opened issue here
  })
})

TODO

  • [ ] update https://github.com/honojs/website/blob/main/docs/middleware/third-party.md

oscarvz avatar Dec 12 '24 16:12 oscarvz

🦋 Changeset detected

Latest commit: 5a7ec2990ce0aca5655931682939aa99f746feb2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@hono/github-webhooks Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

changeset-bot[bot] avatar Dec 12 '24 16:12 changeset-bot[bot]

Hi @oscarvz

Sorry for the late reply. Looks good. I think it will be helpful if you write this as an example on "Examples" in our doc like the "Stripe Webhook": https://hono.dev/examples/stripe-webhook

Maintaining middleware is harder than updating documentation, so I think it's better to make it a document than adding the middleware to this repo.

yusukebe avatar Jan 05 '25 10:01 yusukebe