From fdb6943cc47aa4abb021a65d434a5664e5fe3f11 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Sun, 3 May 2020 21:39:30 +0200 Subject: [PATCH] mirror_pagure_ansible: Sync the upstream changes These include: - Run a sync upon starting the service - If the repo we fetch in has remotes configured, push to them (if they are not 'origin' since we just fetched from it). Signed-off-by: Pierre-Yves Chibon --- .../templates/mirror_from_pagure_bus.py | 25 ++++++++++++++++--- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/roles/mirror_pagure_ansible/templates/mirror_from_pagure_bus.py b/roles/mirror_pagure_ansible/templates/mirror_from_pagure_bus.py index 322f8ed340..59ef4d3f8c 100644 --- a/roles/mirror_pagure_ansible/templates/mirror_from_pagure_bus.py +++ b/roles/mirror_pagure_ansible/templates/mirror_from_pagure_bus.py @@ -12,7 +12,7 @@ import subprocess import sys import time -from fedora_messaging import api, config +from fedora_messaging import api, config, message _log = logging.getLogger("mirror_from_pagure_bus") @@ -33,9 +33,9 @@ def run_command(command, cwd=None): except subprocess.CalledProcessError as e: _log.error("Command `%s` return code: `%s`", " ".join(command), e.returncode) _log.error("Output:\n------\n%s", e.output) -# To enable when we move to python3 -# _log.error("stdout:\n-------\n%s", e.stdout) -# _log.error("stderr:\n-------\n%s", e.stderr) + # To enable when we move to python3 + # _log.error("stdout:\n-------\n%s", e.stdout) + # _log.error("stderr:\n-------\n%s", e.stderr) raise return output @@ -72,6 +72,11 @@ class MirrorFromPagure(object): _log.info("Ready to consume and trigger on %s", self.trigger_names) + msg = message.Message + msg.topic = "io.pagure.prod.pagure.git.receive" + msg.body = {"repo": {"fullname": self.trigger_names[0]}} + self.__call__(message=msg) + def __call__(self, message, cnt=0): """ Invoked when a message is received by the consumer. @@ -107,6 +112,18 @@ class MirrorFromPagure(object): cmd = ["git", "-c", "transfer.fsckObjects=1", "fetch"] run_command(cmd, cwd=dest_folder) + cmd = ["git", "remote"] + output = run_command(cmd, cwd=dest_folder).decode("utf-8").strip() + if output: + for remote in output.split("\n"): + if remote == "origin": + continue + _log.info(" Running git push --mirror against %s", remote) + cmd = ["git", "push", "--mirror", remote] + run_command(cmd, cwd=dest_folder) + else: + _log.info(" No remotes found") + except Exception: _log.exception("Something happened while calling git") if cnt >= 3: