# express-git-hook

> express-git-hook =========

Latest version **0.3.12** (published 2021-11-10) · GPL-3.0-or-later license · 0 weekly downloads

## Install

```sh
npm install express-git-hook
pnpm add express-git-hook
yarn add express-git-hook
bun add express-git-hook
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.12 |
| Published | 2021-11-10 |
| First published | 2021-10-19 |
| Weekly downloads | 0 |
| License | GPL-3.0-or-later |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 39.1 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Finn Melzer |
| Maintainers | f1nnm |
| Keywords | express, git, webhook, github |

## Links

- npm: https://www.npmjs.com/package/express-git-hook
- Repository: https://github.com/F1nnM/express-git-hook
- Homepage: https://github.com/F1nnM/express-git-hook#readme
- Issues: https://github.com/F1nnM/express-git-hook/issues
- npm.io page: https://npm.io/package/express-git-hook

## Dependencies (2)

- [del](https://npm.io/package/del.md) ^6.0.0
- [git-clone](https://npm.io/package/git-clone.md) ^0.2.0

## Recent versions

- 0.3.12 (latest) — 2021-11-10
- 0.3.11 — 2021-11-10
- 0.3.10 — 2021-11-10
- 0.3.9 — 2021-11-10
- 0.3.8 — 2021-11-10
- 0.3.7 — 2021-11-08
- 0.3.6 — 2021-10-24
- 0.3.5 — 2021-10-24
- 0.3.4 — 2021-10-24
- 0.3.3 — 2021-10-20
- 0.3.2 — 2021-10-20
- 0.3.1 — 2021-10-20
- 0.3.0 — 2021-10-20
- 0.2.1 — 2021-10-20
- 0.2.0 — 2021-10-20
- … 1 more at https://npm.io/package/express-git-hook/versions

## README

express-git-hook
=========

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

## Installation
```
$ npm install express-git-hook
```

```JavaScript
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](https://www.npmjs.com/package/git-clone#common-options)
 * `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](https://www.npmjs.com/package/git-clone#common-options)
 * `pat`: Optional. Personal Authentication Token. Needed for pulling private repos.
# Usage
## Listen for only one repository
```JavaScript
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
```JavaScript
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) => {
        //...
    })
})
```

---
_Source: https://npm.io/package/express-git-hook · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
