Skip to content

Instantly share code, notes, and snippets.

@ekohl
Last active October 4, 2023 09:53
Show Gist options
  • Save ekohl/cb6a252b34c7093fb0ef1b439a95e54f to your computer and use it in GitHub Desktop.
Save ekohl/cb6a252b34c7093fb0ef1b439a95e54f to your computer and use it in GitHub Desktop.

Revisions

  1. ekohl revised this gist Oct 4, 2023. 1 changed file with 8 additions and 3 deletions.
    11 changes: 8 additions & 3 deletions remove_webhooks.py
    Original file line number Diff line number Diff line change
    @@ -9,6 +9,9 @@
    'https://notify.travis-ci.org',
    'https://ossistant-inecas.rhcloud.com',
    )
    TO_KEEP = (
    'https://ci.theforeman.org',
    )
    GITHUB_ORG = 'theforeman'
    GITHUB_TOKEN = os.environ['GITHUB_TOKEN']

    @@ -21,7 +24,9 @@
    for hook in repo.get_hooks():
    url = hook.config['url']
    if url.startswith(TO_CLEAN):
    print(f'{repo.name}: Would remove {url}')
    #hook.delete()
    print(f'{repo.name}: Removing {url}')
    hook.delete()
    elif url.startswith(TO_KEEP):
    pass
    else:
    print(f'{repo.name}: Would keep {url}')
    print(f'{repo.name}: Keeping {url}')
  2. ekohl created this gist Oct 4, 2023.
    27 changes: 27 additions & 0 deletions remove_webhooks.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    #!/usr/bin/env python3

    import os

    from github import Github

    TO_CLEAN = (
    'https://prprocessor.theforeman.org',
    'https://notify.travis-ci.org',
    'https://ossistant-inecas.rhcloud.com',
    )
    GITHUB_ORG = 'theforeman'
    GITHUB_TOKEN = os.environ['GITHUB_TOKEN']

    g = Github(GITHUB_TOKEN)

    org = g.get_organization(GITHUB_ORG)

    for repo in org.get_repos():
    if not repo.archived:
    for hook in repo.get_hooks():
    url = hook.config['url']
    if url.startswith(TO_CLEAN):
    print(f'{repo.name}: Would remove {url}')
    #hook.delete()
    else:
    print(f'{repo.name}: Would keep {url}')