Last active
March 31, 2017 15:53
-
-
Save sagepe/b291a86ea7880b17c5be00962ae38744 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import json | |
import pygithub3 | |
def get_repo_names(organisation): | |
repos = gh.repos.list_by_org(organisation,type='all').all() | |
for repo in repos: | |
yield repo.name | |
def get_irc_hooks(repo_name): | |
hooks = gh.repos.hooks.list(repo=repo_name).all() | |
if hooks is not None: | |
for hook in hooks: | |
if hook.name == 'irc': | |
yield hook.id | |
if __name__ == '__main__': | |
# token | |
j = json.load(open('token.json')) | |
mstoken = j['token'] | |
if not mstoken: | |
sys.exit('Failed to find the GitHub API token') | |
# Connection object | |
gh = pygithub3.Github(user='mysociety', token=mstoken) | |
repo_names = get_repo_names("mysociety") | |
for name in repo_names: | |
hooks = get_irc_hooks(name) | |
if hooks is not None: | |
for hook in hooks: | |
print "Deleting IRC hook in repo ", name | |
gh.repos.hooks.delete(hook, repo=name) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment