https://github.com/jasterv/api--github-webhooks
An API Rest built with Deno to catch github webhook events
https://github.com/jasterv/api--github-webhooks
Last synced: about 1 year ago
JSON representation
An API Rest built with Deno to catch github webhook events
- Host: GitHub
- URL: https://github.com/jasterv/api--github-webhooks
- Owner: JasterV
- Created: 2021-11-08T23:55:02.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-11-14T20:06:48.000Z (over 4 years ago)
- Last Synced: 2025-03-07T21:32:55.494Z (over 1 year ago)
- Language: TypeScript
- Size: 44.9 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Deno github webhook server
An API Rest built with Deno to catch github events
## Run
```sh
make start
```
## Github webhook secret
When creating a github webhook from the repository webhooks UI, we need to
provide a secret token.
Github is going to hash this token using a Hmac algorithm and send it to us
using the 'X-Hub-Signature-256' header.
In order to secure our endpoint, we must set a middleware that signs our secret
using the same Hmac algorithm and checks if it matches with the received hash.
Example:
```typescript
const hash = request.headers.get("X-Hub-Signature-256");
const signature = "sha256=" +
hmac("sha256", secret, JSON.stringify(req.body)).hex();
if (hash !== signature) {
// Return an unauthorized error
}
next();
```
## Get the github event
We can get the github event from the `x-github-event` header. Then, to get more
data about this event we can look at the payload received in the body of the
request.
## Actions file
The actions file defines which commands to execute when a certain event is
received.
Example:
```yaml
actions:
- on: push
command: "echo 'Hello World'"
- on: pull_request
command:
- "mkdir ./patata"
- "rmdir ./patata"
- "touch patata/mypatata.txt"
- "tree patata"
```
Right now it only supports push, pull requests and issues, and does not support
specifying a branch. But it will be implemented on demand (For sure I want to be
able to trigger the push event only when it happens on a certain branch).