thumbor: Update to post v6.0
[dockerfile.git] / hubot / add-github-webhooks.sh
1 #!/bin/sh
2 #
3 # usage: add-github-webhooks.sh OWNER REPO URL CHANNEL
4 # for example:
5 #   add-github-webhooks.sh wking dockerfile http://irc.example.net:80 '#dockerfile'
6
7 # Create a token with https://github.com/settings/tokens/new
8 #
9 # The token needs write:repo_hook [1].
10 #
11 # [1]: https://developer.github.com/v3/oauth/
12 TOKEN="FIXME"
13
14 if test -z "${TOKEN}" || test 'xFIXME' = "x${TOKEN}"
15 then
16         echo "edit $0 and set TOKEN to a GitHub authentication token" >&2
17         exit 1
18 fi
19
20 OWNER="$1"
21 REPO="$2"
22 URL="$3"
23 CHANNEL="$4"
24
25 ENDPOINT="https://api.github.com"
26
27
28 # https://developer.github.com/v3/repos/hooks/#create-a-hook
29 curl --request POST \
30         --header "Authorization: token ${TOKEN}" \
31         --header "Content-Type: application/json" \
32         --data @- \
33         "${ENDPOINT}/repos/${OWNER}/${REPO}/hooks" <<EOF
34 {
35         "name": "web",
36         "config": {
37                 "url": "${URL}/hubot/gh-commits?room=${CHANNEL}",
38                 "content_type": "json",
39                 "insecure_ssl": false
40                 },
41         "events": ["push"],
42         "active": true
43 }
44 EOF
45
46 curl --request POST \
47         --header "Authorization: token ${TOKEN}" \
48         --header "Content-Type: application/json" \
49         --data @- \
50         "${ENDPOINT}/repos/${OWNER}/${REPO}/hooks" <<EOF
51 {
52         "name": "web",
53         "config": {
54                 "url": "${URL}/hubot/gh-pull-requests?room=${CHANNEL}",
55                 "content_type": "json",
56                 "insecure_ssl": false
57                 },
58         "events": ["pull_request"],
59         "active": true
60 }
61 EOF