From: W. Trevor King Date: Wed, 21 May 2014 20:10:13 +0000 (-0700) Subject: hubot/add-github-webhooks.sh: Add an script for creating GitHub webhooks X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=c53ecee8b5f5ed5e3963159334619d45f86e9f96;p=dockerfile.git hubot/add-github-webhooks.sh: Add an script for creating GitHub webhooks For notifying the github-commits and github-pull-request-notifier scripts. Adding these hooks to a number of repositories by hand is tedious, and it's so easy to automate ;). --- diff --git a/hubot/add-github-webhooks.sh b/hubot/add-github-webhooks.sh new file mode 100755 index 0000000..27bb24b --- /dev/null +++ b/hubot/add-github-webhooks.sh @@ -0,0 +1,61 @@ +#!/bin/sh +# +# usage: add-github-webhooks.sh OWNER REPO URL CHANNEL +# for example: +# add-github-webhooks.sh wking dockerfile http://irc.example.net:80 '#dockerfile' + +# Create a token with https://github.com/settings/tokens/new +# +# The token needs write:repo_hook [1]. +# +# [1]: https://developer.github.com/v3/oauth/ +TOKEN="FIXME" + +if test -z "${TOKEN}" || test 'xFIXME' = "x${TOKEN}" +then + echo "edit $0 and set TOKEN to a GitHub authentication token" >&2 + exit 1 +fi + +OWNER="$1" +REPO="$2" +URL="$3" +CHANNEL="$4" + +ENDPOINT="https://api.github.com" + + +# https://developer.github.com/v3/repos/hooks/#create-a-hook +curl --request POST \ + --header "Authorization: token ${TOKEN}" \ + --header "Content-Type: application/json" \ + --data @- \ + "${ENDPOINT}/repos/${OWNER}/${REPO}/hooks" <