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 <pingou@pingoured.fr>
This commit is contained in:
Pierre-Yves Chibon 2020-05-03 21:39:30 +02:00
parent 22e7508160
commit fdb6943cc4

View file

@ -12,7 +12,7 @@ import subprocess
import sys import sys
import time import time
from fedora_messaging import api, config from fedora_messaging import api, config, message
_log = logging.getLogger("mirror_from_pagure_bus") _log = logging.getLogger("mirror_from_pagure_bus")
@ -72,6 +72,11 @@ class MirrorFromPagure(object):
_log.info("Ready to consume and trigger on %s", self.trigger_names) _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): def __call__(self, message, cnt=0):
""" """
Invoked when a message is received by the consumer. Invoked when a message is received by the consumer.
@ -107,6 +112,18 @@ class MirrorFromPagure(object):
cmd = ["git", "-c", "transfer.fsckObjects=1", "fetch"] cmd = ["git", "-c", "transfer.fsckObjects=1", "fetch"]
run_command(cmd, cwd=dest_folder) 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: except Exception:
_log.exception("Something happened while calling git") _log.exception("Something happened while calling git")
if cnt >= 3: if cnt >= 3: