Skip to content
Snippets Groups Projects
Commit 669266ef authored by ale's avatar ale
Browse files

Add a "clear-hooks" command

Useful in emergencies to undo mistakes done by set-hooks.
parent 9ce7a22c
Branches
No related tags found
No related merge requests found
Pipeline #45666 passed
......@@ -18,3 +18,12 @@ def check_hook(gl, hook_url, webhook_token, project_path, dry_run):
'pipeline_events': True,
'token': webhook_token,
})
def clear_hooks(gl, project_path, dry_run):
project = gl.projects.get(project_path)
for h in project.hooks.list():
logging.info('%s: removing hook %s', project_path, h.url)
if not dry_run:
h.delete()
......@@ -7,7 +7,7 @@ from urllib.parse import urlsplit
from .deps import get_branches, list_projects, list_deps, \
split_project_branch, read_deps
from .hooks import check_hook
from .hooks import check_hook, clear_hooks
from .rebuild import rebuild_deps
from .server import run_app
......@@ -105,6 +105,14 @@ from standard input if a filename is omitted or specified as '-'.
type=argparse.FileType('r'),
nargs='?', default=sys.stdin)
clear_hooks_parser = subparsers.add_parser(
'clear-hooks',
parents=[common_parser])
clear_hooks_parser.add_argument(
'projects_list',
type=argparse.FileType('r'),
nargs='?', default=sys.stdin)
# Setup pipeline hooks on the specified projects.
set_hooks_parser = subparsers.add_parser(
'set-hooks',
......@@ -264,6 +272,16 @@ specified as '-'.
logging.error('error checking project %s: %s',
project_path, e)
elif cmd == 'clear-hooks':
projects = set(y[0] for y in (
split_project_branch(x.strip()) for x in args.projects_list))
for project_path in projects:
try:
clear_hooks(gl, project_path, args.dry_run)
except Exception as e:
logging.error('error clearing hooks for project %s: %s',
project_path, e)
elif cmd == 'server':
deps = read_deps(args.dependencies_list)
run_app(gl, deps, args.bind_host, args.bind_port,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment