npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

git-emit-node7

v0.0.1

Published

expose git hooks through an event emitter

Downloads

1

Readme

git-emit

Expose git hooks through an EventEmitter.

This module is super handy when used in conjunction with pushover.

example

reject.js

// randomly reject 50% of commits
var em = require('git-emit')(__dirname + '/repo.git');

em.on('update', function (update) {
    if (Math.random() > 0.5) update.reject()
    else update.accept()
});

Now we can create a new bare repo and run reject.js to listen for commits:

$ git init --bare repo.git
Initialized empty Git repository in /home/substack/projects/node-git-emit/example/repo.git/
$ node reject.js

The first time, our commit is rejected:

$ git push ~/projects/node-git-emit/example/repo.git master
Counting objects: 43, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (36/36), done.
Writing objects: 100% (43/43), 6.15 KiB, done.
Total 43 (delta 18), reused 0 (delta 0)
Unpacking objects: 100% (43/43), done.
remote: error: hook declined to update refs/heads/master
To example/repo.git
 ! [remote rejected] master -> master (hook declined)
error: failed to push some refs to 'example/repo.git'

but the second time, the commit goes through!

$ git push ~/projects/node-git-emit/example/repo.git master
Counting objects: 43, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (36/36), done.
Writing objects: 100% (43/43), 6.15 KiB, done.
Total 43 (delta 18), reused 0 (delta 0)
Unpacking objects: 100% (43/43), done.
To example/repo.git
 * [new branch]      master -> master

It works as expected hooray!

methods

var gitEmit = require('git-emit')

var emitter = gitEmit(repoDir, cb)

Install hooks into repoDir. repoDir should be either a .git directory from an existing or new project or just a bare git directory created with git init --bare.

repoDir should not have any existing hooks unless they were created with git-emit.

Optionally pass in cb(err, emitter) to be notified when the hooks have been installed into repoDir or an error has occured.

emitter.close()

Shut down the dnode listener used internally by git-emit.

events

You can listen for events corresponding to github hooks.

All events receive an update object.

Passive events fire and cannot influence the acceptance any actions.

Abortable events MUST respond to the update object with either an update.accept() or an update.reject().

passive events

  • post-applypatch
  • post-commit
  • post-checkout
  • post-merge
  • post-receive
  • post-update
  • post-rewrite

abortable events

  • applypatch-msg
  • pre-applypatch
  • pre-commit
  • prepare-commit-msg
  • commit-msg
  • pre-rebase
  • pre-receive
  • update
  • pre-auto-gc

update object

All events are passed an update object as the first argument.

Abortable updates MUST call update.accept() or update.reject().

Since there may be multiple listeners for any update, all listeners must accept() an update for it to be ultimately accepted.

update.accept()

Accept an update.

update.reject()

Reject an update.

update.arguments

The raw arguments provided to the git hook on the command line.

update.lines

An array of lines from process.stdin.

This attribute is only defined for pre-recieve, post-receieve, and post-rewrite hooks.

update.canAbort

Whether the update is abortable.

install

With npm do:

npm install git-emit

license

MIT/X11