Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@octokit/webhooks

Package Overview
Dependencies
Maintainers
0
Versions
259
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@octokit/webhooks

GitHub webhook events toolset for Node.js

  • 13.4.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created

What is @octokit/webhooks?

@octokit/webhooks is a Node.js library for handling GitHub webhooks. It provides a simple and efficient way to listen for and respond to GitHub webhook events, making it easier to integrate GitHub with your applications.

What are @octokit/webhooks's main functionalities?

Webhook Event Handling

This feature allows you to handle specific GitHub webhook events, such as 'push'. The code sample demonstrates setting up a webhook listener for 'push' events and starting an HTTP server to listen for incoming webhook requests.

const { Webhooks } = require('@octokit/webhooks');
const webhooks = new Webhooks({ secret: 'mysecret' });

webhooks.on('push', ({ id, name, payload }) => {
  console.log(name, 'event received');
  console.log('Payload:', payload);
});

require('http').createServer(webhooks.middleware).listen(3000);

Webhook Signature Verification

This feature allows you to verify the signature of incoming webhook requests to ensure they are from GitHub. The code sample demonstrates how to verify a webhook signature using a secret.

const { verify } = require('@octokit/webhooks');

const payload = JSON.stringify({ foo: 'bar' });
const signature = 'sha256=abcdef1234567890';
const secret = 'mysecret';

const isValid = verify(secret, payload, signature);
console.log('Signature is valid:', isValid);

Webhook Event Routing

This feature allows you to route different webhook events to specific handlers. The code sample demonstrates setting up a general event handler for all events and a specific handler for 'issues.opened' events.

const { Webhooks } = require('@octokit/webhooks');
const webhooks = new Webhooks({ secret: 'mysecret' });

webhooks.on('*', ({ id, name, payload }) => {
  console.log(`Received event: ${name}`);
});

webhooks.on('issues.opened', ({ id, name, payload }) => {
  console.log('Issue opened:', payload.issue.title);
});

require('http').createServer(webhooks.middleware).listen(3000);

Other packages similar to @octokit/webhooks

FAQs

Package last updated on 20 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc