receive github webhook, and run os command like cgi
go get github.com/nazoking/hookserver/cmd/hookserver.go
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
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
.
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"
}
}
{
"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"
}
}
}
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
... )
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
/your/home/hookserver/your-username/your-reponame/push/_index
/your/home/hookserver/your-username/your-reponame/push
/your/home/hookserver/your-username/your-reponame/_index
/your/home/hookserver/your-username/your-reponame
/your/home/hookserver/your-username/_index
/your/home/hookserver/your-username
/your/home/hookserver/_index
- return http not found status