Skip to content
Snippets Groups Projects
Commit 3ed99637 authored by ale's avatar ale
Browse files

Add a "set-hooks" command to set pipeline hooks on projects

parent ec4523cd
No related branches found
No related tags found
1 merge request!1Modular
def check_hook(gl, hook_url, webhook_token, project_path):
project = gl.projects.get(project_path)
found = False
for h in project.hooks.list():
if h.url == hook_url and h.pipeline_events:
found = True
break
if found:
return
project.hooks.add(
url=hook_url,
pipeline_events=True,
token=webhook_token,
)
......@@ -7,6 +7,7 @@ import urllib.parse as urlparse
from .deps import get_branches, list_projects, list_deps, \
split_project_branch, read_deps
from .hooks import check_hook
from .rebuild import rebuild_deps
from .server import run_app
......@@ -63,6 +64,20 @@ def main():
'--docker', action='store_true',
help='Output dependencies between Docker images, not Gitlab projects')
# Setup pipeline hooks on the specified projects.
set_hooks_parser = subparsers.add_parser(
'set-hooks',
parents=[common_parser],
help='set pipeline hooks on projects',
description='Set the pipeline hooks on the specified projects '
'(usually points at our own server)')
set_hooks_parser.add_argument(
'--hook-url', metavar='URL',
help='URL for the pipeline HTTP hook')
set_hooks_parser.add_argument(
'--webhook-auth-token', metavar='TOKEN',
help='Secret X-Gitlab-Token for request authentication')
# Trigger rebuilds of reverse deps.
rebuild_image_parser = subparsers.add_parser(
'rebuild',
......@@ -140,9 +155,17 @@ def main():
project_path, branch_name = split_project_branch(args.project_path)
rebuild_deps(gl, deps, project_path, branch_name, args.dry_run,
args.recurse)
elif cmd == 'set-hooks':
if not args.hook_url:
parser.error('Must specify --hook-url')
# Need a project list on input, ignore branches.
projects = set(y[0] for y in (
split_project_branch(x.strip()) for x in sys.stdin))
for project_path in projects:
check_hook(gl, args.hook_url, args.webhook_auth_token,
project_path)
elif cmd == 'server':
deps = read_deps(sys.stdin)
# TODO
run_app(gl, deps, args.bind_host, args.bind_port,
args.webhook_auth_token)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment