Giter VIP home page Giter VIP logo

hookserver's Introduction

hookserver

receive github webhook, and run os command like cgi

install

go get github.com/nazoking/hookserver/cmd/hookserver.go

Usage

Usage of hookserver:
  -addr=":8999":   address and port of hook server
  -default="_all": default script name
  -parser:         json file of payload parse configuration
  -scripts:        script root path
  -secret="":      secret of webhook Signature

Quick start

mkdir -p /your/home/hookserver/your-username/your-reponame/
cat <<SCRIPT > /your/home/hookserver/your-username/your-reponame/push
#do mirror
cd /your/home/git/your-reponame
git fetch origin
git push mirror
SCRIPT
chmod u+x /your/home/hookserver/your-username/your-reponame/push

hookserver -scripts=/your/home/hookserver

and you go to https://github.com/your-username/your-reponame, set webhook send payload to http://your-host:8999/ . When repository pushed, and github send hook, hookserver run /your/home/hookserver/your-username/your-reponame/push .

Parser json

You can customize script path by parser json. it schema is below.

{
  "Event Name( X-Github-Event )" : {
    "Path": "template string it direct to script path",
    "Values": {
      "Value name": "value path of webhook json payload"
    }
}

Default parser json

{
  "pull_request":{
    "Path": "{{.BASE_OWNER}}/{{.BASE_REPO}}/pull_request/{{.ACTION}}",
    "Values":{
      "HEAD_OWNER"  :"/pull_request/head/repo/owner/login",
      "HEAD_REPO"   :"/pull_request/head/repo/name",
      "HEAD_BRANCH" :"/pull_request/head/ref",
      "HEAD_SHA"    :"/pull_request/head/sha",
      "BASE_OWNER"  :"/pull_request/base/repo/owner/login",
      "BASE_REPO"   :"/pull_request/base/repo/name",
      "BASE_BRANCH" :"/pull_request/head/ref",
      "BASE_SHA"    :"/pull_request/head/sha",
      "ACTION"      :"/action"
    }
  },
  "push":{
    "Path": "{{.OWNER}}/{{.REPO}}/push/{{.BRANCH}}",
    "Values":{
      "OWNER"  :"/repository/owner/name",
      "REPO"   :"/repository/name",
      "BRANCH" :"/ref"
    }
  }
}

Environment variable and payload

Your hook scripts can use Environment Variables like cgi. QUERY_STRING, HTTP_METHOD, HTTP_X_GITHUB_EVENT ...

Your hook scripts can use palyoad value by reading std-in.

Values set by parser is export to script. Your hook scripts can use Environment Variables like ACTION set by parser.json.

( Path templete can use header variables like cgi. for example, QUERY_STRING, HTTP_METHOD, HTTP_X_GITHUB_EVENT ... )

default script

hookserver find script by parser's path. if not found path, script search default script.

if you set option hookscript -scripts=/your/home/hookserver/ -default="_index" and, path value is your-username/your-reponame/push then, script find

  1. /your/home/hookserver/your-username/your-reponame/push/_index
  2. /your/home/hookserver/your-username/your-reponame/push
  3. /your/home/hookserver/your-username/your-reponame/_index
  4. /your/home/hookserver/your-username/your-reponame
  5. /your/home/hookserver/your-username/_index
  6. /your/home/hookserver/your-username
  7. /your/home/hookserver/_index
  8. return http not found status

hookserver's People

Contributors

nazoking avatar

Watchers

 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.