https://github.com/arlac77/koa-github-hook-handler
handle github/gitea Webhook requests
https://github.com/arlac77/koa-github-hook-handler
gitea github koa webhook
Last synced: about 1 month ago
JSON representation
handle github/gitea Webhook requests
- Host: GitHub
- URL: https://github.com/arlac77/koa-github-hook-handler
- Owner: arlac77
- License: 0bsd
- Created: 2019-04-18T08:08:22.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2025-04-06T00:05:53.000Z (about 1 month ago)
- Last Synced: 2025-04-06T00:24:21.612Z (about 1 month ago)
- Topics: gitea, github, koa, webhook
- Language: JavaScript
- Homepage:
- Size: 1.62 MB
- Stars: 3
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://www.npmjs.com/package/koa-github-hook-handler)
[](https://spdx.org/licenses/0BSD.html)
[](https://typescriptlang.org)
[](https://bundlejs.com/?q=koa-github-hook-handler)
[](https://npmjs.org/package/koa-github-hook-handler)
[](https://github.com/arlac77/koa-github-hook-handler/issues)
[](https://actions-badge.atrox.dev/arlac77/koa-github-hook-handler/goto)
[](https://github.com/prettier/prettier)
[](http://commitizen.github.io/cz-cli/)
[](https://snyk.io/test/github/arlac77/koa-github-hook-handler)
[](https://coveralls.io/github/arlac77/koa-github-hook-handler)## koa-github-hook-handler
handle github/gitea/bitbucket requests
```js
import Koa from "koa";
import Router from "koa-better-router";
import { createGithubHookHandler } from "koa-github-hook-handler";...
const router = Router();
const secret = "...";router.addRoute(
"POST",
"/hook",
createGithubHookHandler(
{
push: async request => {
console.log("PUSH",request);
return { ok: true };
}
},
{ secret }
)
);
```# API
### Table of Contents
* [Context](#context)
* [KoaHandler](#koahandler)
* [Parameters](#parameters)
* [WebhookHandler](#webhookhandler)
* [Parameters](#parameters-1)
* [createGithubHookHandler](#creategithubhookhandler)
* [Parameters](#parameters-2)
* [createGiteaHookHandler](#creategiteahookhandler)
* [Parameters](#parameters-3)
* [createBitbucketHookHandler](#createbitbuckethookhandler)
* [Parameters](#parameters-4)## Context
Type: [Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)
## KoaHandler
Type: [Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)
### Parameters
* `ctx` **[Context](#context)**
* `next` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)**## WebhookHandler
Type: [Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)
### Parameters
* `request` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** decoded request body
* `event` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** from 'x-github-event' header
* `ctx` **[Context](#context)** from koa## createGithubHookHandler
Create a koa middleware suitable to bridge github webhook requests to KoaHandlers
### Parameters
* `actions` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** holding all the handles for the events (event is the key)
* `actions.default` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** default action
* `actions.event` **[WebhookHandler](#webhookhandler)** (event is the key)
* `config` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)*** `config.secret` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** to decode signature
Returns **[KoaHandler](#koahandler)** suitable as koa middleware
## createGiteaHookHandler
Create a koa middleware suitable to bridge gitea webhook requests to KoaHandlers
### Parameters
* `actions` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** holding all the handles for the events (event is the key)
* `actions.default` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** default action
* `actions.event` **[WebhookHandler](#webhookhandler)** (event is the key)
* `config` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)*** `config.secret` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** to decode signature
Returns **[KoaHandler](#koahandler)** suitable as koa middleware
## createBitbucketHookHandler
Create a koa middleware suitable to bridge gitea webhook requests to KoaHandlers
### Parameters
* `actions` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)** holding all the handles for the events (event is the key)
* `actions.default` **[Function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Statements/function)** default action
* `actions.event` **[WebhookHandler](#webhookhandler)** (event is the key)
* `config` **[Object](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object)*** `config.secret` **[string](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String)** to decode signature
Returns **[KoaHandler](#koahandler)** suitable as koa middleware
# install
With [npm](http://npmjs.org) do:
```shell
npm install koa-github-hook-handler
```# license
BSD-2-Clause