hookah

package module
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 7, 2018 License: MIT Imports: 18 Imported by: 1

README

Hookah

Go Report Card GoDoc Build Status

Hookah is a simple server for GitHub Webhooks that forwards the hooks messsage to any manner of script, be they PHP, Ruby, Python or even straight up shell.

It simply passes the message on to the STDIN of any script.

Installation

From Source:
go get -u -v github.com/donatj/hookah/cmd/hookah

Usage

When receiving a webhook request from GitHub, Hookah checks {server-root}/{vendor}/{product}/{X-Github-Event}/* for any executable scripts, and executes them sequentially passing the JSON payload to it's standard in.

This allows actual hook scripts to be written in any language you prefer.

For example, a script server/donatj/hookah/push/log.rb would be executed every time a "push" event webhook was received from Github on the donatj/hookah repo.

Example Hook Scripts

bash + jq
#!/bin/bash

set -e

json=`cat`
ref=$(<<< "$json" jq -r .ref)

echo "$ref"
if [ "$ref" == "refs/heads/master" ]
then
        echo "Ref was Master"
else
        echo "Ref was not Master"
fi
PHP
#!/usr/bin/php
<?php

$input = file_get_contents("php://stdin");

$data = json_decode($input, true);
print_r($data);

Note:

Don't forget to make your scripts executable (chmod +x <script filename>), and add a shebang poiting to your desired interpreter (i.e. #!/bin/bash) as the first line.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type HookExec

type HookExec struct {
	RootDir string

	Owner string
	Repo  string

	Event string
	Data  io.ReadSeeker

	HookServer *HookServer
}

HookExec represents a call to a hook

func (*HookExec) Exec

func (h *HookExec) Exec(timeout time.Duration) error

Exec triggers the execution of all scripts associated with the given Hook

func (*HookExec) GetPathExecs

func (h *HookExec) GetPathExecs() ([]string, error)

GetPathExecs fetches the executable filenames for the given path

type HookJSON

type HookJSON struct {
	Repository struct {
		Name  string       `json:"name"`
		Owner HookUserJSON `json:"owner"`
	} `json:"repository"`
	Sender HookUserJSON `json:"sender"`
}

HookJSON represents the minimum body we need to parse

type HookServer

type HookServer struct {
	RootDir string
	Timeout time.Duration

	sync.Mutex
	// contains filtered or unexported fields
}

HookServer implements net/http.Handler

func NewHookServer

func NewHookServer(rootdir, secret string, timeout time.Duration) (*HookServer, error)

NewHookServer instantiates a new HookServer with some basic validation on the root directory

func (*HookServer) ServeHTTP

func (h *HookServer) ServeHTTP(w http.ResponseWriter, r *http.Request)

type HookUserJSON

type HookUserJSON struct {
	Login string `json:"login"`
	Name  string `json:"name"`
}

HookUserJSON exists because some hooks use Login, some use Name - it's horribly inconsistent

func (*HookUserJSON) GetLogin

func (h *HookUserJSON) GetLogin() string

GetLogin is used to get the login from the data github decided to pass today

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL