From 9f6c8f62e78a0dd3bd42af9fa746261577a0edf7 Mon Sep 17 00:00:00 2001 From: Stephan Kulow Date: Tue, 8 Nov 2022 09:22:32 +0100 Subject: [PATCH] Push to the remote when the repo changed --- lib/git.py | 11 +++++++++++ lib/git_exporter.py | 2 ++ 2 files changed, 13 insertions(+) diff --git a/lib/git.py b/lib/git.py index ce5e238..b5684d1 100644 --- a/lib/git.py +++ b/lib/git.py @@ -214,3 +214,14 @@ class Git: print(response.data) url = f"gitea@gitea.opensuse.org:{org_name}/{repo_name}.git" self.repo.remotes.create("origin", url) + + def push(self): + remo = self.repo.remotes["origin"] + + keypair = pygit2.KeypairFromAgent("gitea") + callbacks = pygit2.RemoteCallbacks(credentials=keypair) + + refspecs = ["refs/heads/factory"] + if "refs/heads/devel" in self.repo.references: + refspecs.append("refs/heads/devel") + remo.push(refspecs, callbacks=callbacks) diff --git a/lib/git_exporter.py b/lib/git_exporter.py index 80333d2..330bd1a 100644 --- a/lib/git_exporter.py +++ b/lib/git_exporter.py @@ -84,6 +84,8 @@ class GitExporter: logging.debug(f"Committing {flat}") self.commit_flat(flat, branch_state) + self.git.push() + def run_gc(self): self.gc_cnt = self.gc_interval self.git.gc()