Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: GitHub Webhooks middleware #883

Open
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

oscarvz
Copy link

@oscarvz oscarvz commented Dec 12, 2024

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

Copy link

changeset-bot bot commented Dec 12, 2024

🦋 Changeset detected

Latest commit: 5a7ec29

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant