3 # usage: add-github-webhooks.sh OWNER REPO URL CHANNEL
5 # add-github-webhooks.sh wking dockerfile http://irc.example.net:80 '#dockerfile'
7 # Create a token with https://github.com/settings/tokens/new
9 # The token needs write:repo_hook [1].
11 # [1]: https://developer.github.com/v3/oauth/
14 if test -z "${TOKEN}" || test 'xFIXME' = "x${TOKEN}"
16 echo "edit $0 and set TOKEN to a GitHub authentication token" >&2
25 ENDPOINT="https://api.github.com"
28 # https://developer.github.com/v3/repos/hooks/#create-a-hook
30 --header "Authorization: token ${TOKEN}" \
31 --header "Content-Type: application/json" \
33 "${ENDPOINT}/repos/${OWNER}/${REPO}/hooks" <<EOF
37 "url": "${URL}/hubot/gh-commits?room=${CHANNEL}",
38 "content_type": "json",
47 --header "Authorization: token ${TOKEN}" \
48 --header "Content-Type: application/json" \
50 "${ENDPOINT}/repos/${OWNER}/${REPO}/hooks" <<EOF
54 "url": "${URL}/hubot/gh-pull-requests?room=${CHANNEL}",
55 "content_type": "json",
58 "events": ["pull_request"],