GithubHelp home page GithubHelp logo

isabella232 / jthoober Goto Github PK

View Code? Open in Web Editor NEW

This project forked from npm/jthoober

0.0 0.0 0.0 245 KB

run bash scripts when you get a push event from a github webhook

License: ISC License

JavaScript 99.58% Shell 0.42%

jthoober's Introduction

jthoober

A service to receive github webhook events & run scripts in response. Run custom testing or deploys in response to pushes! Build things!

on npm Tests Coverage Dependencies

Usage

npm install --save jthoober

Set up jthoober somewhere that github has access to. Create a shared secret for github to send to the webhook & make a note of it. Run jthoober like this:

Usage: jthoober --rules path/to/rules.js --secret sooper-sekrit

Options:
  --rules, -r  path to the rules file                         [required]
  --secret     shared secret with github                      [required]
  -p, --port   port to listen on                              [default: 5757]
  -h, --host   host to bind to                                [default: "localhost"]
  --mount      path to mount routes on                        [default: "/webhook"]
  --help       Show help

I like to use nginx to terminate tls then proxy pass through to jthoober. I run it under upstart.

Set up a webhook for a project on github. Point it to your jthoober location & give it the secret string you created earlier. Observe that the test payload makes it through.

Rules

The rules file must export an array of hashes; each hash is passed to the Rule constructor to make an object. Set up rules that match repos to scripts to execute when jthoober receives an event. Here are some examples:

module.exports =
[
    {
      pattern: /jthoober/,
      event: '*',
      script: '/usr/local/bin/fortune'
    },
    {
      pattern: /request/,
      event: 'push',
      script: './example-script.sh',
    },
    {
      pattern: /reponame/,
      branchPattern: /master/,
      event: 'push',
      script: './examples/bash-example.sh'
    },
    {
      pattern: /reponame/,
      event: 'push',
      script: './examples/bash-fullevent.sh',
      fullEvent: true
    },
    {
      pattern: /reponame/,
      event: 'push',
      script: './example-script.js',
      cmd: 'node',
      args: [process.env, '-t 100']
      // will result in `node ./example-script.js <repoName> <branchName> <env> -t 100`
    },
    {
      pattern: /issue/,
      event: 'issues',
      func: function(event, cb) { console.log('hi'); cb(); },
    },
    {
      pattern: /manyissues/,
      event: 'issues',
      args: [process.env, 'cheddar'],
      func: function(event, env, cheese, cb) { console.log('hi'); cb(); }
    }
];

Rules may either invoke a script file or call a javascript function.

A javascript function will be passed the event object & a callback to fire when complete.

If you set the fullEvent boolean option to true, a script rule will be passed the entire JSON webhook event, stringified, in the WEBHOOK_EVENT environment variable.

Otherwise, all script rules receive the repo name as the first script argument & the ref of the commit (aka the branch) as the second. If the event is a push event, the third argument is the after payload field, aka the hash of the head commit. If you are passing the event to a javascript function instead of invoking an external script, you are given have the whole event to play with.

Valid rules options:

  • pattern: required; regexp to match against the repo name
  • branchPattern: regexp to match against the branch name.
  • event: required; github event to match on; * matches all events
  • func: javascript function to invoke on match; mutually exclusive with script
  • script: external executable to invoke on match
  • cmd: the executable to run the script with; unused for functions. e.g. bash
  • args: an array of additional args to pass to the script or function. These args come after the repo and branch names, at the end of args passed. If func is passed, these args will come after the event name.
  • fullEvent: a boolean, considered only for script rules.
  • concurrentOkay: boolean; set to true if a rule should be allowed to be run concurrently with itself

Endpoints

/webhook - route that responds to the webhook. Configurable; pass --mount /foo to the runner to mount the handler on /foo instead.

/ping - responds with 200 "OK". Use this to monitor.

Logging

The server logs events & status in json to stdout. Pipe the output through bistre --time to get pretty logs.

Notes

j'thoob is the official pronunciation of gi-thub, aka the site this code is hosted on.

TODO

Pass more stuff from the hook event to the bash script. Commit hash? Why not allow rules to be arbitrary node code? Or just define a handler API? But bash is so handy.

Logging for js functions?

License

ISC; see the LICENSE file.

jthoober's People

Contributors

ceejbot avatar greenkeeperio-bot avatar joeybaker avatar gedkott avatar bcoe avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.