Add push and PR creation on sync
@@ -6,6 +6,7 @@ from functools import lru_cache
import git
+from onegittorulethemall.services.pagure import PagureService
from sourcegit.transformator import Transformator, get_package_mapping
from sourcegit.utils import commits_to_nice_str
@@ -54,6 +55,10 @@ class Synchronizer:
url=target_url, repo=repo, branch=repo.active_branch, **package_config
) as t:
t.clone_dist_git_repo()
+
+ dist_git_new_branch = t.dist_git_repo.create_head(source_ref)
+ dist_git_new_branch.checkout()
+
t.create_archive()
t.copy_redhat_content_to_dest_dir()
patches = t.create_patches()
@@ -68,7 +73,41 @@ class Synchronizer:
msg = f"{pr_url}\n\n{commits_nice_str}"
t.commit_distgit(title=title, msg=msg)
- # Create pr in dist-git (fork if needed)
+ package_name = package_config["package_name"]
+ pagure = PagureService(token=self.pagure_token, username=self.pagure_user)
+
+ project = pagure.get_project(repo=package_name, namespace="rpms")
+
+ if not project.fork:
+ logger.info("Creating a fork.")
+ project.fork_create()
+
+ is_push_force = source_ref in project.fork.branches
+
+ t.dist_git_repo.create_remote(
+ name="origin-fork", url=project.fork.git_urls["ssh"]
+ )
+ t.dist_git_repo.remote("origin-fork").push(
+ refspec=source_ref, force=is_push_force
+ )
+
+ dist_git_pr_id = project.fork.pr_create(
+ title=f"[source-git] {title}",
+ body=msg,
+ source_branch=source_ref,
+ target_branch="master",
+ )["id"]
+ logger.info(f"PR created: {dist_git_pr_id}")
+
+ @property
+ @lru_cache()
+ def pagure_token(self):
+ return os.environ["PAGURE_API_TOKEN"]
+
+ @property
+ @lru_cache()
+ def pagure_user(self):
+ return os.environ["PAGURE_USER"]
@lru_cache()
def get_repo(self, url, directory=None):
