0.3.12 • Published 2 years ago

express-git-hook v0.3.12

Weekly downloads
-
License
GPL-3.0-or-later
Repository
github
Last release
2 years ago

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) => {
        //...
    })
})
0.3.9

2 years ago

0.3.12

2 years ago

0.3.11

2 years ago

0.3.10

2 years ago

0.3.8

2 years ago

0.3.7

3 years ago

0.3.6

3 years ago

0.3.5

3 years ago

0.3.4

3 years ago

0.3.3

3 years ago

0.3.2

3 years ago

0.3.1

3 years ago

0.3.0

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.1.0

3 years ago