Skip to content

Instantly share code, notes, and snippets.

@iainlane
Last active June 2, 2021 10:46
Show Gist options
  • Save iainlane/982c267ae4354ed75aed5069b5f31617 to your computer and use it in GitHub Desktop.
Save iainlane/982c267ae4354ed75aed5069b5f31617 to your computer and use it in GitHub Desktop.
#!/usr/bin/python3
# Copyright 2021 Canonical Ltd
""" Update all gnome-team repositories to use the given webhooks.
This program is free software: you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free Software
Foundation, either version 3 of the License, or (at your option) any later
version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with
this program. If not, see <http://www.gnu.org/licenses/>.
"""
import gitlab
def fix_hooks(project):
hooks = project.hooks.list(all=True)
hook_params_debian = {
"url": "http://kgb.debian.net:9418/webhook/?channel=debian-gnome&use_color=1&use_irc_notices=0&squash_threshold=5&always_squash_branch=upstream/*&only_branch=debian/*&only_branch=pristine-tar&only_branch=upstream/*&only_tag=upstream/*&only_tag=debian/*",
"push_events": True,
"tag_push_events": True,
"merge_requests_events": False,
"repository_update_events": False,
"enable_ssl_verification": True,
"issues_events": True,
"confidential_issues_events": False,
"note_events": True,
"confidential_note_events": False,
"pipeline_events": True,
"wiki_page_events": False,
"deployment_events": False,
"job_events": True,
"releases_events": False,
"push_events_branch_filter": "",
}
hook_params_ubuntu = hook_params_debian.copy()
hook_params_ubuntu["url"] = "http://kgb.debian.net:9418/webhook/?channel=ubuntu-desktop&network=libera&use_color=1&use_irc_notices=0&squash_threshold=5&always_squash_branch=upstream/*&only_branch=ubuntu/*&only_branch=pristine-tar&only_branch=upstream/*&only_tag=upstream/*&only_tag=debian/*"
for hook in hooks:
if "kgb" in hook.url:
print(f"delete {hook.url}")
hook.delete()
print("creating debian hook")
project.hooks.create(hook_params_debian)
print("creating ubuntu hook")
project.hooks.create(hook_params_ubuntu)
# private token or personal token authentication
gl = gitlab.Gitlab("https://salsa.debian.org/", private_token="YOUR_TOKEN_HERE")
# make an API request to create the gl.user object. This is mandatory if you
# use the username/password authentication.
gl.auth()
gnome_groups = gl.groups.list(search="gnome-team")
for group in gnome_groups:
projects = group.projects.list(all=True)
for group_project in projects:
print(f"==== {group_project.name} ====")
project = gl.projects.get(group_project.id)
fix_hooks(project)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment