Esempio n. 1
0
File: core.py Progetto: sclorg/betka
    def _run_sync(self):
        self.refresh_betka_yaml()
        for self.image in self.get_synced_images():
            self.pagure_api.set_image(self.image)
            # Checks if pagure already contains a fork for the image self.image
            # The image name is defined in the betka.yaml configuration file
            # variable dist_git_repos
            if not self.pagure_api.get_pagure_fork():
                UMBSender.send_umb_message_skip(self.msg_artifact,
                                                "not-applicable",
                                                "pagure fork not found")
                continue

            self.info("Trying to sync image %r.", self.image)
            os.chdir(self.betka_tmp_dir.name)

            self.clone_url = self.pagure_api.get_clone_url()
            # after downstream is cloned then
            # new cwd is self.downstream_dir
            if not self.prepare_downstream_git():
                UMBSender.send_umb_message_skip(
                    self.msg_artifact,
                    "not-applicable",
                    "Failed cloning downstream repository",
                )
                continue
            # This function updates fork based on the upstream
            Git.get_changes_from_distgit(
                url=self.pagure_api.full_downstream_url)
            # Branches are taken from upstream repository like
            # https://src.fedoraproject.org/container/nginx not from fork
            all_branches = self.pagure_api.get_branches()
            # Filter our branches before checking bot-cfg.yml files
            branch_list_to_sync = Git.branches_to_synchronize(
                self.betka_config, all_branches=all_branches)
            self.debug(f"Branches to sync {branch_list_to_sync}")
            Git.sync_fork_with_upstream(branch_list_to_sync)
            valid_branches = self.pagure_api.get_valid_branches(
                self.downstream_dir, branch_list_to_sync)

            if not valid_branches:
                msg = "There are no valid branches with bot-cfg.yaml file"
                self.info(msg)
                UMBSender.send_umb_message_skip(self.msg_artifact,
                                                "not-applicable", msg)
                if self.downstream_dir.is_dir():
                    shutil.rmtree(str(self.downstream_dir))
                continue

            try:
                self._sync_valid_branches(valid_branches)
            finally:
                self.delete_cloned_directories()

            self.send_umb_message_complete()

        # Deletes temporary directory.
        # It is created during each upstream2downstream task.
        if Path(self.betka_tmp_dir.name).is_dir():
            self.betka_tmp_dir.cleanup()
Esempio n. 2
0
File: core.py Progetto: sclorg/betka
    def sync_to_downstream_branches(self, branch) -> bool:
        """
        Sync upstream repository into relevant downstream dist-git branch
        based on the configuration file.
        :param branch: downstream branch to check and to sync
        """
        if not self.config.get("master_checker"):
            self.info(
                "Syncing upstream repo to downstream repo is not allowed.")
            return False
        self.info("Syncing upstream %r to downstream %r",
                  self.msg_upstream_url, self.image)
        description_msg = COMMIT_MASTER_MSG.format(hash=self.upstream_hash,
                                                   repo=self.repo)
        pr_id = self.pagure_api.check_downstream_pull_requests(branch=branch)
        if not pr_id:
            Git.get_changes_from_distgit(
                url=self.pagure_api.full_downstream_url)
            Git.push_changes_to_fork(branch=branch)

        if not self.sync_upstream_to_downstream_directory():
            return False

        # git {add,commit,push} all files in local dist-git repo
        Git.git_add_all(
            upstream_msg=self.upstream_message,
            related_msg=Git.get_msg_from_jira_ticket(self.config),
        )

        # Prepare betka_schema used for sending mail and Pagure Pull Request
        # The function also checks if downstream does not already contain pull request
        betka_schema = self.pagure_api.file_pull_request(
            pr_msg=description_msg,
            upstream_hash=self.upstream_hash,
            branch=branch,
            pr_id=pr_id,
        )
        self.send_result_email(betka_schema=betka_schema)
        return True