Skip to content

Instantly share code, notes, and snippets.

@kamens
Created January 23, 2013 21:15
Show Gist options
  • Save kamens/4613457 to your computer and use it in GitHub Desktop.
Save kamens/4613457 to your computer and use it in GitHub Desktop.
How to limit the events that trigger a Github hook message
>>> import requests
>>> import json
>>> r = requests.get('https://api.github.com/repos/kamens/gae_mini_profiler/hooks', auth=('kamens', 'dontyouwish'))
>>> r.text
u'[{"config":{"restrict_to_branch":"","auth_token":"monkeysmonkeysmonkeys","room":"1s and 0s"},"url":"https://api.github.com/repos/kamens/gae_mini_profiler/hooks/629092","active":true,"test_url":"https://api.github.com/repos/kamens/gae_mini_profiler/hooks/629092/test","updated_at":"2013-01-23T18:59:08Z","last_response":{"status":"ok","message":"OK","code":200},"events":["commit_comment","download","fork","fork_apply","gollum","issues","issue_comment","member","public","pull_request","push","watch"],"name":"hipchat","id":629092,"created_at":"2013-01-04T19:53:44Z"}]'
# Note the id from the hook that you're interested in. In this case, it's 629092
id = 629092
# Grab that hook's data
>>> r = requests.get('https://api.github.com/repos/kamens/gae_mini_profiler/hooks/%s' % id, auth=('kamens', 'dontyouwish'))
>>> data = r.json
# Modify events
>>> data["events"] = ["push", "fork"] # see list of events @ http://developer.github.com/v3/repos/hooks/#get-single-hook
# Patch up hook
>>> r = requests.patch('https://api.github.com/repos/kamens/gae_mini_profiler/hooks/%s' % id, data=json.dumps(data), auth=('kamens', 'dontyouwish'))
# r.response_code should be 200, hook should be updated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment