Skip to content
This repository was archived by the owner on Dec 20, 2024. It is now read-only.
/ express-git-hook Public archive

A lightweight module for handling Github webhooks compatible with express and the default http server.

License

Notifications You must be signed in to change notification settings

F1nnM/express-git-hook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

39 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

express-git-hook

A lightweight module for handling Github webhooks compatible with express and the default http server.

Installation

$ npm install express-git-hook
const { hook, multihook } = require('express-git-hook');

API

hook(repo, targetPath, [options, [pat]])

  • repo : URL of the repository to watch
  • targetPath : Path to a directory to clone into. Will be created, if it doesn't exist.
  • options: Optional. Options for git-clone
  • pat: Optional. Personal Authentication Token. Needed for pulling private repos.

multihhook(clonePaths, [options, [pat]])

Works like hook, but accepts multiple repositories.

  • clonePaths : Object like: {'repositoryURL': './path/to/clone/to', ...}
  • options: Optional. Options for git-clone
  • pat: Optional. Personal Authentication Token. Needed for pulling private repos.

Usage

Listen for only one repository

var express = require('express');
var app = express();

const {hook} = require('express-git-hook');
// URL of the repo, directory to clone into, [Optional: options for cloning]
const mw = hook('F1nnM/express-git-hook', "./git-hook");

// for all requests
app.post('/', mw, (req, res) => {
    // res.locals.files contains a list of all files with their full paths
    // if, e.g. you always want to read the file config/main.json, 
    // you can use the following:
    let path = res.locals.files['config']['main.json'];
    fs.readFile(path, 'utf-8', (err, data) => {
        //...
    })
})

Listen for multiple repositories

var express = require('express');
var app = express();

const {multihook} = require('express-git-hook');

// Configuring the allowed repos and their clone paths
const config = {
    'F1nnM/express-git-hook': './repos/git-hook',
    'F1nnM/HyperViz': './repos/hyperviz',
}
// create the middleware
const mw = hook(config);

// for all requests
app.post('/', mw, (req, res) => {
    // res.locals.files contains a list of all files with their full paths
    // if, e.g. you always want to read the file config/main.json, 
    // you can use the following:
    let path = res.locals.files['config']['main.json'];
    fs.readFile(path, 'utf-8', (err, data) => {
        //...
    })
})

About

A lightweight module for handling Github webhooks compatible with express and the default http server.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published