Skip to content

Instantly share code, notes, and snippets.

@tolleiv
Created March 10, 2014 18:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tolleiv/9470916 to your computer and use it in GitHub Desktop.
Save tolleiv/9470916 to your computer and use it in GitHub Desktop.
Autoregistering a hook through a shell script.
#!/bin/bash
### ALL SPOTS marked with XXX have to be changed before this runs
token="XXX"; # get that from your user settings
name="AOEpeople" # the github login name
type="orgs" # or "users"
list=`curl -s -H "Authorization: token ${token}" "https://api.github.com/${type}/${name}/repos" | grep '"url"' | grep 'repos' | sed -E 's~.*https(.*)",~https\1~'`
for repo in $list; do
hooks=`curl -s -H "Authorization: token ${token}" "${repo}/hooks" | grep "aoepeople"`
echo -n "${repo} "
if [ -z "${hooks}" ]; then
echo "registering"
curl -s -X POST -H "Content-Type: application/json" -H "Authorization: token ${token}" -d '{ "name": "repoactivity", "active": true, "events": [ "*" ], "config": { "url": "XXXX", "content_type": "form" } }' "${repo}/hooks"
else
echo "ok"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment