Commit 3c7b79cb authored by ale's avatar ale

Update server code to support the new dependency maps

Improve help messages for the command too.
parent cadc1cf7
import logging
def check_hook(gl, hook_url, webhook_token, project_path):
def check_hook(gl, hook_url, webhook_token, project_path, dry_run):
project = gl.projects.get(project_path)
found = False
for h in project.hooks.list():
......@@ -9,8 +10,10 @@ def check_hook(gl, hook_url, webhook_token, project_path):
break
if found:
return
project.hooks.add(
url=hook_url,
pipeline_events=True,
token=webhook_token,
)
logging.info('adding pipeline_events hook to %s', project_path)
if not dry_run:
project.hooks.add(
url=hook_url,
pipeline_events=True,
token=webhook_token,
)
This diff is collapsed.
......@@ -2,13 +2,14 @@ import logging
import time
def rebuild(gl, project_path, wait=False):
def rebuild(gl, project_path, branch_name, wait=False):
"""Trigger a rebuild of a project."""
project = gl.projects.get(project_path)
if not project:
return None
pipeline = project.pipelines.create({'ref': 'master'})
pipeline = project.pipelines.create({'ref': branch_name})
logging.info('started pipeline %s', pipeline.web_url)
if wait:
while pipeline.finished_at is None:
pipeline.refresh()
......@@ -20,9 +21,9 @@ def rebuild_deps(gl, project_deps, project_path, branch_name, dry_run,
wait_and_recurse):
stack = project_deps.get((project_path, branch_name), [])
while stack:
path = stack.pop(0)
logging.info('rebuilding %s', path)
path, branch = stack.pop(0)
logging.info('rebuilding %s:%s', path, branch)
if not dry_run:
rebuild(gl, path, wait_and_recurse)
rebuild(gl, path, branch, wait_and_recurse)
if wait_and_recurse:
stack.extend(project_deps.get(path, []))
stack.extend(project_deps.get((path, branch), []))
......@@ -16,25 +16,25 @@ queue = Queue.Queue()
def _process_request(gl, project_deps, data):
pipeline_status = data['object_attributes']['status']
branch = data['object_attributes']['ref']
path_with_namespace = data['project']['path_with_namespace']
branch_name = data['object_attributes']['ref']
project_path = data['project']['path_with_namespace']
action = 'none'
if pipeline_status == 'success':
deps = project_deps.get_contents().get(path_with_namespace, [])
deps = project_deps.get((project_path, branch_name), [])
built_projects = []
for dep_path in deps:
for dep_path, dep_branch in deps:
try:
p = rebuild(gl, dep_path)
logging.info('started pipeline %s', p)
rebuild(gl, dep_path, dep_branch)
built_projects.append(f'{dep_path}:{dep_branch}')
except Exception as e:
logging.error('error rebuilding project %s: %s' % (
path_with_namespace, str(e)))
logging.error('error rebuilding project %s:%s: %s' % (
dep_path, dep_branch, str(e)))
action = 'rebuilt %s' % (', '.join(built_projects),)
logging.info('pipeline for %s@%s: %s, action=%s',
path_with_namespace, branch, pipeline_status, action)
project_path, branch_name, pipeline_status, action)
def worker_thread(gl, project_deps):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment